2 * Unit tests for DCE support
4 * Copyright 2005 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
33 #define DCX_USESTYLE 0x00010000
36 static HWND hwnd_cache
, hwnd_owndc
, hwnd_classdc
, hwnd_classdc2
, hwnd_parent
, hwnd_parentdc
;
38 /* test behavior of DC attributes with various GetDC/ReleaseDC combinations */
39 static void test_dc_attributes(void)
43 INT i
, rop
, def_rop
, caps
;
48 hdc
= GetDC( hwnd_cache
);
49 def_rop
= GetROP2( hdc
);
51 SetROP2( hdc
, R2_WHITE
);
53 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
55 ok( WindowFromDC( hdc
) == hwnd_cache
, "wrong window\n" );
56 ReleaseDC( hwnd_cache
, hdc
);
57 ok( WindowFromDC( hdc
) != hwnd_cache
, "wrong window\n" );
58 hdc
= GetDC( hwnd_cache
);
60 ok( rop
== def_rop
, "wrong ROP2 %d after release\n", rop
);
61 SetROP2( hdc
, R2_WHITE
);
62 ok( WindowFromDC( hdc
) == hwnd_cache
, "wrong window\n" );
63 ReleaseDC( hwnd_cache
, hdc
);
67 for (i
= 0; i
< 20; i
++)
69 hdc
= hdcs
[i
] = GetDCEx( hwnd_cache
, 0, DCX_USESTYLE
| DCX_NORESETATTRS
);
72 ok( rop
== def_rop
, "wrong ROP2 %d after release %p/%p\n", rop
, old_hdc
, hdc
);
76 SetROP2( hdc
, R2_WHITE
);
81 trace( "hdc %p not found in cache using %p\n", old_hdc
, hdcs
[0] );
83 SetROP2( old_hdc
, R2_WHITE
);
85 while (i
> 0) ReleaseDC( hwnd_cache
, hdcs
[--i
] );
87 for (i
= 0; i
< 20; i
++)
89 hdc
= hdcs
[i
] = GetDCEx( hwnd_cache
, 0, DCX_USESTYLE
| DCX_NORESETATTRS
);
93 ok( rop
== R2_WHITE
|| broken( rop
== def_rop
), /* win9x doesn't support DCX_NORESETATTRS */
94 "wrong ROP2 %d after release %p/%p\n", rop
, old_hdc
, hdc
);
96 ok( rop
== def_rop
, "wrong ROP2 %d after release %p/%p\n", rop
, old_hdc
, hdc
);
98 while (i
> 0) ReleaseDC( hwnd_cache
, hdcs
[--i
] );
100 for (i
= 0; i
< 20; i
++)
102 hdc
= hdcs
[i
] = GetDCEx( hwnd_cache
, 0, DCX_USESTYLE
);
104 rop
= GetROP2( hdc
);
107 ok( rop
== R2_WHITE
|| broken( rop
== def_rop
),
108 "wrong ROP2 %d after release %p/%p\n", rop
, old_hdc
, hdc
);
109 SetROP2( old_hdc
, def_rop
);
112 ok( rop
== def_rop
, "wrong ROP2 %d after release %p/%p\n", rop
, old_hdc
, hdc
);
114 while (i
> 0) ReleaseDC( hwnd_cache
, hdcs
[--i
] );
116 /* Released cache DCs are 'disabled' */
117 rop
= SetROP2( old_hdc
, R2_BLACK
);
118 ok( rop
== 0, "got %d\n", rop
);
119 rop
= GetROP2( old_hdc
);
120 ok( rop
== 0, "got %d\n", rop
);
121 caps
= GetDeviceCaps( old_hdc
, HORZRES
);
122 ok( caps
== 0, "got %d\n", caps
);
123 caps
= GetDeviceCaps( old_hdc
, VERTRES
);
124 ok( caps
== 0, "got %d\n", caps
);
125 caps
= GetDeviceCaps( old_hdc
, NUMCOLORS
);
126 ok( caps
== 0, "got %d\n", caps
);
127 ok( WindowFromDC( old_hdc
) != hwnd_cache
, "wrong window\n" );
130 caps
= GetDeviceCaps( hdc
, HORZRES
);
131 ok( caps
!= 0, "got %d\n", caps
);
132 caps
= GetDeviceCaps( hdc
, VERTRES
);
133 ok( caps
!= 0, "got %d\n", caps
);
134 caps
= GetDeviceCaps( hdc
, NUMCOLORS
);
135 ok( caps
!= 0, "got %d\n", caps
);
137 caps
= GetDeviceCaps( hdc
, HORZRES
);
138 ok( caps
== 0, "got %d\n", caps
);
139 caps
= GetDeviceCaps( hdc
, VERTRES
);
140 ok( caps
== 0, "got %d\n", caps
);
141 caps
= GetDeviceCaps( hdc
, NUMCOLORS
);
142 ok( caps
== 0, "got %d\n", caps
);
146 hdc
= GetDC( hwnd_owndc
);
147 SetROP2( hdc
, R2_WHITE
);
148 rop
= GetROP2( hdc
);
149 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
152 ok( WindowFromDC( hdc
) == hwnd_owndc
, "wrong window\n" );
153 ReleaseDC( hwnd_owndc
, hdc
);
154 ok( WindowFromDC( hdc
) == hwnd_owndc
, "wrong window\n" );
155 hdc
= GetDC( hwnd_owndc
);
156 ok( old_hdc
== hdc
, "didn't get same DC %p/%p\n", old_hdc
, hdc
);
157 rop
= GetROP2( hdc
);
158 ok( rop
== R2_WHITE
, "wrong ROP2 %d after release\n", rop
);
159 ok( WindowFromDC( hdc
) == hwnd_owndc
, "wrong window\n" );
160 ReleaseDC( hwnd_owndc
, hdc
);
161 rop
= GetROP2( hdc
);
162 ok( rop
== R2_WHITE
, "wrong ROP2 %d after second release\n", rop
);
166 hdc
= GetDC( hwnd_classdc
);
167 SetROP2( hdc
, R2_WHITE
);
168 rop
= GetROP2( hdc
);
169 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
172 ok( WindowFromDC( hdc
) == hwnd_classdc
, "wrong window\n" );
173 ReleaseDC( hwnd_classdc
, hdc
);
174 ok( WindowFromDC( hdc
) == hwnd_classdc
, "wrong window\n" );
175 hdc
= GetDC( hwnd_classdc
);
176 ok( old_hdc
== hdc
, "didn't get same DC %p/%p\n", old_hdc
, hdc
);
177 rop
= GetROP2( hdc
);
178 ok( rop
== R2_WHITE
, "wrong ROP2 %d after release\n", rop
);
179 ok( WindowFromDC( hdc
) == hwnd_classdc
, "wrong window\n" );
180 ReleaseDC( hwnd_classdc
, hdc
);
181 rop
= GetROP2( hdc
);
182 ok( rop
== R2_WHITE
, "wrong ROP2 %d after second release\n", rop
);
184 /* test class DC with 2 windows */
186 old_hdc
= GetDC( hwnd_classdc
);
187 SetROP2( old_hdc
, R2_BLACK
);
188 ok( WindowFromDC( old_hdc
) == hwnd_classdc
, "wrong window\n" );
189 hdc
= GetDC( hwnd_classdc2
);
190 ok( old_hdc
== hdc
, "didn't get same DC %p/%p\n", old_hdc
, hdc
);
191 rop
= GetROP2( hdc
);
192 ok( rop
== R2_BLACK
, "wrong ROP2 %d for other window\n", rop
);
193 ok( WindowFromDC( hdc
) == hwnd_classdc2
, "wrong window\n" );
194 ReleaseDC( hwnd_classdc
, old_hdc
);
195 ReleaseDC( hwnd_classdc
, hdc
);
196 ok( WindowFromDC( hdc
) == hwnd_classdc2
, "wrong window\n" );
197 rop
= GetROP2( hdc
);
198 ok( rop
== R2_BLACK
, "wrong ROP2 %d after release\n", rop
);
202 /* test behavior with various invalid parameters */
203 static void test_parameters(void)
207 hdc
= GetDC( hwnd_cache
);
208 ok( ReleaseDC( hwnd_owndc
, hdc
), "ReleaseDC with wrong window should succeed\n" );
210 hdc
= GetDC( hwnd_cache
);
211 ok( !ReleaseDC( hwnd_cache
, 0 ), "ReleaseDC with wrong HDC should fail\n" );
212 ok( ReleaseDC( hwnd_cache
, hdc
), "correct ReleaseDC should succeed\n" );
213 ok( !ReleaseDC( hwnd_cache
, hdc
), "second ReleaseDC should fail\n" );
215 hdc
= GetDC( hwnd_owndc
);
216 ok( ReleaseDC( hwnd_cache
, hdc
), "ReleaseDC with wrong window should succeed\n" );
217 hdc
= GetDC( hwnd_owndc
);
218 ok( ReleaseDC( hwnd_owndc
, hdc
), "correct ReleaseDC should succeed\n" );
219 ok( ReleaseDC( hwnd_owndc
, hdc
), "second ReleaseDC should succeed\n" );
221 hdc
= GetDC( hwnd_classdc
);
222 ok( ReleaseDC( hwnd_cache
, hdc
), "ReleaseDC with wrong window should succeed\n" );
223 hdc
= GetDC( hwnd_classdc
);
224 ok( ReleaseDC( hwnd_classdc
, hdc
), "correct ReleaseDC should succeed\n" );
225 ok( ReleaseDC( hwnd_classdc
, hdc
), "second ReleaseDC should succeed\n" );
229 static void test_dc_visrgn(void)
233 RECT rect
, parent_rect
;
237 SetRect( &rect
, 10, 10, 20, 20 );
238 MapWindowPoints( hwnd_cache
, 0, (POINT
*)&rect
, 2 );
239 hrgn
= CreateRectRgnIndirect( &rect
);
240 hdc
= GetDCEx( hwnd_cache
, hrgn
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
241 SetRectEmpty( &rect
);
242 GetClipBox( hdc
, &rect
);
243 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
244 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
245 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
246 ReleaseDC( hwnd_cache
, hdc
);
247 ok( GetRgnBox( hrgn
, &rect
) == ERROR
, "region must no longer be valid\n" );
249 /* cache DC with NORESETATTRS */
251 SetRect( &rect
, 10, 10, 20, 20 );
252 MapWindowPoints( hwnd_cache
, 0, (POINT
*)&rect
, 2 );
253 hrgn
= CreateRectRgnIndirect( &rect
);
254 hdc
= GetDCEx( hwnd_cache
, hrgn
, DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_NORESETATTRS
);
255 SetRectEmpty( &rect
);
256 GetClipBox( hdc
, &rect
);
257 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
258 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
259 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
260 ReleaseDC( hwnd_cache
, hdc
);
261 ok( GetRgnBox( hrgn
, &rect
) == ERROR
, "region must no longer be valid\n" );
262 hdc
= GetDCEx( hwnd_cache
, 0, DCX_USESTYLE
| DCX_NORESETATTRS
);
263 SetRectEmpty( &rect
);
264 GetClipBox( hdc
, &rect
);
265 ok( !(rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20),
266 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect
));
267 ReleaseDC( hwnd_cache
, hdc
);
271 SetRect( &rect
, 10, 10, 20, 20 );
272 MapWindowPoints( hwnd_owndc
, 0, (POINT
*)&rect
, 2 );
273 hrgn
= CreateRectRgnIndirect( &rect
);
274 hdc
= GetDCEx( hwnd_owndc
, hrgn
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
275 SetRectEmpty( &rect
);
276 GetClipBox( hdc
, &rect
);
277 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
278 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
279 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
280 ReleaseDC( hwnd_owndc
, hdc
);
281 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
282 SetRectEmpty( &rect
);
283 GetClipBox( hdc
, &rect
);
284 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
285 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
286 hdc
= GetDCEx( hwnd_owndc
, 0, DCX_USESTYLE
);
287 SetRectEmpty( &rect
);
288 GetClipBox( hdc
, &rect
);
289 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
290 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
291 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
292 ReleaseDC( hwnd_owndc
, hdc
);
293 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
295 SetRect( &rect
, 20, 20, 30, 30 );
296 MapWindowPoints( hwnd_owndc
, 0, (POINT
*)&rect
, 2 );
297 hrgn2
= CreateRectRgnIndirect( &rect
);
298 hdc
= GetDCEx( hwnd_owndc
, hrgn2
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
299 ok( GetRgnBox( hrgn
, &rect
) == ERROR
, "region must no longer be valid\n" );
300 SetRectEmpty( &rect
);
301 GetClipBox( hdc
, &rect
);
302 ok( rect
.left
>= 20 && rect
.top
>= 20 && rect
.right
<= 30 && rect
.bottom
<= 30,
303 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
304 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
305 ReleaseDC( hwnd_owndc
, hdc
);
306 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
307 hdc
= GetDCEx( hwnd_owndc
, 0, DCX_EXCLUDERGN
| DCX_USESTYLE
);
308 ok( GetRgnBox( hrgn2
, &rect
) == ERROR
, "region must no longer be valid\n" );
309 SetRectEmpty( &rect
);
310 GetClipBox( hdc
, &rect
);
311 ok( !(rect
.left
>= 20 && rect
.top
>= 20 && rect
.right
<= 30 && rect
.bottom
<= 30),
312 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect
));
313 ReleaseDC( hwnd_owndc
, hdc
);
317 SetRect( &rect
, 10, 10, 20, 20 );
318 MapWindowPoints( hwnd_classdc
, 0, (POINT
*)&rect
, 2 );
319 hrgn
= CreateRectRgnIndirect( &rect
);
320 hdc
= GetDCEx( hwnd_classdc
, hrgn
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
321 SetRectEmpty( &rect
);
322 GetClipBox( hdc
, &rect
);
323 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
324 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
325 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
326 ReleaseDC( hwnd_classdc
, hdc
);
327 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
328 SetRectEmpty( &rect
);
329 GetClipBox( hdc
, &rect
);
330 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
331 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
333 hdc
= GetDCEx( hwnd_classdc
, 0, DCX_USESTYLE
);
334 SetRectEmpty( &rect
);
335 GetClipBox( hdc
, &rect
);
336 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
337 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
338 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
339 ReleaseDC( hwnd_classdc
, hdc
);
340 ok( GetRgnBox( hrgn
, &rect
) != ERROR
, "region must still be valid\n" );
342 SetRect( &rect
, 20, 20, 30, 30 );
343 MapWindowPoints( hwnd_classdc
, 0, (POINT
*)&rect
, 2 );
344 hrgn2
= CreateRectRgnIndirect( &rect
);
345 hdc
= GetDCEx( hwnd_classdc
, hrgn2
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
346 ok( GetRgnBox( hrgn
, &rect
) == ERROR
, "region must no longer be valid\n" );
347 SetRectEmpty( &rect
);
348 GetClipBox( hdc
, &rect
);
349 ok( rect
.left
>= 20 && rect
.top
>= 20 && rect
.right
<= 30 && rect
.bottom
<= 30,
350 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
351 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
354 hdc
= GetDCEx( hwnd_classdc2
, 0, DCX_USESTYLE
);
355 ok( old_hdc
== hdc
, "did not get the same hdc %p/%p\n", old_hdc
, hdc
);
356 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
357 SetRectEmpty( &rect
);
358 GetClipBox( hdc
, &rect
);
359 ok( !(rect
.left
>= 20 && rect
.top
>= 20 && rect
.right
<= 30 && rect
.bottom
<= 30),
360 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect
));
361 ReleaseDC( hwnd_classdc2
, hdc
);
362 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
363 hdc
= GetDCEx( hwnd_classdc2
, 0, DCX_EXCLUDERGN
| DCX_USESTYLE
);
364 ok( GetRgnBox( hrgn2
, &rect
) != ERROR
, "region2 must still be valid\n" );
365 ok( !(rect
.left
>= 20 && rect
.top
>= 20 && rect
.right
<= 30 && rect
.bottom
<= 30),
366 "clip box must have been reset %s\n", wine_dbgstr_rect( &rect
));
367 ReleaseDC( hwnd_classdc2
, hdc
);
370 hdc
= GetDC( hwnd_parentdc
);
371 GetClipBox( hdc
, &rect
);
372 ReleaseDC( hwnd_parentdc
, hdc
);
374 hdc
= GetDC( hwnd_parent
);
375 GetClipBox( hdc
, &parent_rect
);
376 ReleaseDC( hwnd_parent
, hdc
);
378 ok( EqualRect( &rect
, &parent_rect
), "rect = %s, expected %s\n", wine_dbgstr_rect( &rect
),
379 wine_dbgstr_rect( &parent_rect
));
383 /* test various BeginPaint/EndPaint behaviors */
384 static void test_begin_paint(void)
387 RECT rect
, parent_rect
;
393 /* clear update region */
394 RedrawWindow( hwnd_cache
, NULL
, 0, RDW_VALIDATE
|RDW_NOFRAME
|RDW_NOERASE
);
395 SetRect( &rect
, 10, 10, 20, 20 );
396 RedrawWindow( hwnd_cache
, &rect
, 0, RDW_INVALIDATE
);
397 hdc
= BeginPaint( hwnd_cache
, &ps
);
398 SetRectEmpty( &rect
);
399 GetClipBox( hdc
, &rect
);
400 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
401 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
402 EndPaint( hwnd_cache
, &ps
);
406 RedrawWindow( hwnd_owndc
, NULL
, 0, RDW_VALIDATE
|RDW_NOFRAME
|RDW_NOERASE
);
407 SetRect( &rect
, 10, 10, 20, 20 );
408 RedrawWindow( hwnd_owndc
, &rect
, 0, RDW_INVALIDATE
);
409 hdc
= BeginPaint( hwnd_owndc
, &ps
);
410 SetRectEmpty( &rect
);
411 GetClipBox( hdc
, &rect
);
412 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
413 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
414 ReleaseDC( hwnd_owndc
, hdc
);
415 SetRectEmpty( &rect
);
416 GetClipBox( hdc
, &rect
);
417 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
418 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
419 ok( GetDC( hwnd_owndc
) == hdc
, "got different hdc\n" );
420 SetRectEmpty( &rect
);
421 GetClipBox( hdc
, &rect
);
422 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
423 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
424 EndPaint( hwnd_owndc
, &ps
);
425 SetRectEmpty( &rect
);
426 GetClipBox( hdc
, &rect
);
427 ok( !(rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20),
428 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect
));
429 RedrawWindow( hwnd_owndc
, NULL
, 0, RDW_VALIDATE
|RDW_NOFRAME
|RDW_NOERASE
);
430 SetRect( &rect
, 10, 10, 20, 20 );
431 RedrawWindow( hwnd_owndc
, &rect
, 0, RDW_INVALIDATE
|RDW_ERASE
);
432 ok( GetDC( hwnd_owndc
) == hdc
, "got different hdc\n" );
433 SetRectEmpty( &rect
);
434 GetClipBox( hdc
, &rect
);
435 ok( !(rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20),
436 "clip box should be the whole window %s\n", wine_dbgstr_rect( &rect
));
437 RedrawWindow( hwnd_owndc
, NULL
, 0, RDW_ERASENOW
);
438 SetRectEmpty( &rect
);
439 GetClipBox( hdc
, &rect
);
440 ok( !(rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20),
441 "clip box should still be the whole window %s\n", wine_dbgstr_rect( &rect
));
445 RedrawWindow( hwnd_classdc
, NULL
, 0, RDW_VALIDATE
|RDW_NOFRAME
|RDW_NOERASE
);
446 SetRect( &rect
, 10, 10, 20, 20 );
447 RedrawWindow( hwnd_classdc
, &rect
, 0, RDW_INVALIDATE
);
448 hdc
= BeginPaint( hwnd_classdc
, &ps
);
449 SetRectEmpty( &rect
);
450 GetClipBox( hdc
, &rect
);
451 ok( rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20,
452 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
455 hdc
= GetDC( hwnd_classdc2
);
456 ok( old_hdc
== hdc
, "did not get the same hdc %p/%p\n", old_hdc
, hdc
);
457 SetRectEmpty( &rect
);
458 GetClipBox( hdc
, &rect
);
459 ok( !(rect
.left
>= 10 && rect
.top
>= 10 && rect
.right
<= 20 && rect
.bottom
<= 20),
460 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect
));
461 ReleaseDC( hwnd_classdc2
, hdc
);
462 EndPaint( hwnd_classdc
, &ps
);
465 RedrawWindow( hwnd_parent
, NULL
, 0, RDW_VALIDATE
|RDW_NOFRAME
|RDW_NOERASE
);
466 RedrawWindow( hwnd_parentdc
, NULL
, 0, RDW_INVALIDATE
);
467 hdc
= BeginPaint( hwnd_parentdc
, &ps
);
468 GetClipBox( hdc
, &rect
);
469 cr
= SetPixel( hdc
, 10, 10, RGB(255, 0, 0) );
470 ok( cr
!= -1, "error drawing outside of window client area\n" );
471 EndPaint( hwnd_parentdc
, &ps
);
472 GetClientRect( hwnd_parent
, &parent_rect
);
474 ok( rect
.left
== parent_rect
.left
, "rect.left = %d, expected %d\n", rect
.left
, parent_rect
.left
);
475 ok( rect
.top
== parent_rect
.top
, "rect.top = %d, expected %d\n", rect
.top
, parent_rect
.top
);
476 todo_wine
ok( rect
.right
== parent_rect
.right
, "rect.right = %d, expected %d\n", rect
.right
, parent_rect
.right
);
477 todo_wine
ok( rect
.bottom
== parent_rect
.bottom
, "rect.bottom = %d, expected %d\n", rect
.bottom
, parent_rect
.bottom
);
479 hdc
= GetDC( hwnd_parent
);
480 todo_wine
ok( GetPixel( hdc
, 10, 10 ) == cr
, "error drawing outside of window client area\n" );
481 ReleaseDC( hwnd_parent
, hdc
);
484 /* test ScrollWindow with window DCs */
485 static void test_scroll_window(void)
491 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
493 UpdateWindow( hwnd_owndc
);
494 SetRect( &clip
, 25, 25, 50, 50 );
495 ScrollWindow( hwnd_owndc
, -5, -10, NULL
, &clip
);
496 hdc
= BeginPaint( hwnd_owndc
, &ps
);
497 SetRectEmpty( &rect
);
498 GetClipBox( hdc
, &rect
);
499 ok( rect
.left
>= 25 && rect
.top
>= 25 && rect
.right
<= 50 && rect
.bottom
<= 50,
500 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
501 EndPaint( hwnd_owndc
, &ps
);
503 SetViewportExtEx( hdc
, 2, 3, NULL
);
504 SetViewportOrgEx( hdc
, 30, 20, NULL
);
506 ScrollWindow( hwnd_owndc
, -5, -10, NULL
, &clip
);
507 hdc
= BeginPaint( hwnd_owndc
, &ps
);
508 SetRectEmpty( &rect
);
509 GetClipBox( hdc
, &rect
);
510 ok( rect
.left
>= 25 && rect
.top
>= 25 && rect
.right
<= 50 && rect
.bottom
<= 50,
511 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
512 EndPaint( hwnd_owndc
, &ps
);
514 ScrollWindowEx( hwnd_owndc
, -5, -10, NULL
, &clip
, 0, NULL
, SW_INVALIDATE
| SW_ERASE
);
515 hdc
= BeginPaint( hwnd_owndc
, &ps
);
516 SetRectEmpty( &rect
);
517 GetClipBox( hdc
, &rect
);
518 ok( rect
.left
>= -5 && rect
.top
>= 5 && rect
.right
<= 20 && rect
.bottom
<= 30,
519 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
520 EndPaint( hwnd_owndc
, &ps
);
522 SetViewportExtEx( hdc
, 1, 1, NULL
);
523 SetViewportOrgEx( hdc
, 0, 0, NULL
);
525 ScrollWindowEx( hwnd_owndc
, -5, -10, NULL
, &clip
, 0, NULL
, SW_INVALIDATE
| SW_ERASE
);
526 hdc
= BeginPaint( hwnd_owndc
, &ps
);
527 SetRectEmpty( &rect
);
528 GetClipBox( hdc
, &rect
);
529 ok( rect
.left
>= 25 && rect
.top
>= 25 && rect
.right
<= 50 && rect
.bottom
<= 50,
530 "invalid clip box %s\n", wine_dbgstr_rect( &rect
));
531 EndPaint( hwnd_owndc
, &ps
);
534 static void test_invisible_create(void)
536 HWND hwnd_owndc
= CreateWindowA("owndc_class", NULL
, WS_OVERLAPPED
,
538 0, 0, GetModuleHandleA(0), NULL
);
541 dc1
= GetDC(hwnd_owndc
);
542 dc2
= GetDC(hwnd_owndc
);
544 ok(dc1
== dc2
, "expected owndc dcs to match\n");
546 ReleaseDC(hwnd_owndc
, dc2
);
547 ReleaseDC(hwnd_owndc
, dc1
);
548 DestroyWindow(hwnd_owndc
);
551 static void test_dc_layout(void)
553 HWND hwnd_cache_rtl
, hwnd_owndc_rtl
, hwnd_classdc_rtl
, hwnd_classdc2_rtl
;
557 hdc
= GetDC( hwnd_cache
);
558 SetLayout( hdc
, LAYOUT_RTL
);
559 layout
= GetLayout( hdc
);
560 ReleaseDC( hwnd_cache
, hdc
);
563 win_skip( "SetLayout not supported\n" );
567 hwnd_cache_rtl
= CreateWindowExA(WS_EX_LAYOUTRTL
, "cache_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
568 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL
);
569 hwnd_owndc_rtl
= CreateWindowExA(WS_EX_LAYOUTRTL
, "owndc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
570 0, 200, 100, 100, 0, 0, GetModuleHandleA(0), NULL
);
571 hwnd_classdc_rtl
= CreateWindowExA(WS_EX_LAYOUTRTL
, "classdc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
572 200, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL
);
573 hwnd_classdc2_rtl
= CreateWindowExA(WS_EX_LAYOUTRTL
, "classdc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
574 200, 200, 100, 100, 0, 0, GetModuleHandleA(0), NULL
);
575 hdc
= GetDC( hwnd_cache_rtl
);
576 layout
= GetLayout( hdc
);
578 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
580 ReleaseDC( hwnd_cache_rtl
, hdc
);
581 hdc
= GetDC( hwnd_owndc_rtl
);
582 layout
= GetLayout( hdc
);
583 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
584 ReleaseDC( hwnd_cache_rtl
, hdc
);
586 hdc
= GetDC( hwnd_cache
);
587 layout
= GetLayout( hdc
);
588 ok( layout
== 0, "wrong layout %x\n", layout
);
589 ReleaseDC( hwnd_cache
, hdc
);
591 hdc
= GetDC( hwnd_owndc_rtl
);
592 layout
= GetLayout( hdc
);
593 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
595 ReleaseDC( hwnd_owndc_rtl
, hdc
);
596 hdc
= GetDC( hwnd_owndc_rtl
);
597 layout
= GetLayout( hdc
);
598 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
599 ReleaseDC( hwnd_owndc_rtl
, hdc
);
601 hdc
= GetDC( hwnd_classdc_rtl
);
602 layout
= GetLayout( hdc
);
603 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
605 ReleaseDC( hwnd_classdc_rtl
, hdc
);
606 hdc
= GetDC( hwnd_classdc2_rtl
);
607 layout
= GetLayout( hdc
);
608 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
609 ReleaseDC( hwnd_classdc2_rtl
, hdc
);
610 hdc
= GetDC( hwnd_classdc
);
611 layout
= GetLayout( hdc
);
612 ok( layout
== LAYOUT_RTL
, "wrong layout %x\n", layout
);
613 ReleaseDC( hwnd_classdc_rtl
, hdc
);
615 DestroyWindow(hwnd_classdc2_rtl
);
616 DestroyWindow(hwnd_classdc_rtl
);
617 DestroyWindow(hwnd_owndc_rtl
);
618 DestroyWindow(hwnd_cache_rtl
);
621 static void test_destroyed_window(void)
626 dc
= GetDC( hwnd_cache
);
627 SetROP2( dc
, R2_WHITE
);
629 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
630 ok( WindowFromDC( dc
) == hwnd_cache
, "wrong window\n" );
633 DestroyWindow( hwnd_cache
);
635 ok( rop
== 0, "wrong ROP2 %d\n", rop
);
636 ok( WindowFromDC( dc
) != hwnd_cache
, "wrong window\n" );
637 ok( !ReleaseDC( hwnd_cache
, dc
), "ReleaseDC succeeded\n" );
638 dc
= GetDC( hwnd_cache
);
639 ok( !dc
, "Got a non-NULL DC (%p) for a destroyed window\n", dc
);
641 dc
= GetDC( hwnd_classdc
);
642 SetROP2( dc
, R2_WHITE
);
644 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
645 ok( WindowFromDC( dc
) == hwnd_classdc
, "wrong window\n" );
648 dc
= GetDC( hwnd_classdc2
);
649 ok( old_dc
== dc
, "wrong DC\n" );
651 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
652 ok( WindowFromDC( dc
) == hwnd_classdc2
, "wrong window\n" );
653 DestroyWindow( hwnd_classdc2
);
656 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
657 ok( WindowFromDC( dc
) != hwnd_classdc2
, "wrong window\n" );
658 ok( !ReleaseDC( hwnd_classdc2
, dc
), "ReleaseDC succeeded\n" );
659 dc
= GetDC( hwnd_classdc2
);
660 ok( !dc
, "Got a non-NULL DC (%p) for a destroyed window\n", dc
);
662 dc
= GetDC( hwnd_classdc
);
663 ok( dc
!= 0, "Got NULL DC\n" );
665 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
666 ok( WindowFromDC( dc
) == hwnd_classdc
, "wrong window\n" );
667 DestroyWindow( hwnd_classdc
);
670 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
671 ok( WindowFromDC( dc
) != hwnd_classdc
, "wrong window\n" );
672 ok( !ReleaseDC( hwnd_classdc
, dc
), "ReleaseDC succeeded\n" );
673 dc
= GetDC( hwnd_classdc
);
674 ok( !dc
, "Got a non-NULL DC (%p) for a destroyed window\n", dc
);
676 dc
= GetDC( hwnd_owndc
);
677 ok( dc
!= 0, "Got NULL DC\n" );
679 ok( rop
== R2_WHITE
, "wrong ROP2 %d\n", rop
);
680 ok( WindowFromDC( dc
) == hwnd_owndc
, "wrong window\n" );
681 DestroyWindow( hwnd_owndc
);
684 ok( rop
== 0, "wrong ROP2 %d\n", rop
);
685 ok( WindowFromDC( dc
) != hwnd_owndc
, "wrong window\n" );
686 ok( !ReleaseDC( hwnd_owndc
, dc
), "ReleaseDC succeeded\n" );
687 dc
= GetDC( hwnd_owndc
);
688 ok( !dc
, "Got a non-NULL DC (%p) for a destroyed window\n", dc
);
690 DestroyWindow( hwnd_parent
);
697 cls
.style
= CS_DBLCLKS
;
698 cls
.lpfnWndProc
= DefWindowProcA
;
701 cls
.hInstance
= GetModuleHandleA(0);
703 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
704 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
705 cls
.lpszMenuName
= NULL
;
706 cls
.lpszClassName
= "cache_class";
707 RegisterClassA(&cls
);
708 cls
.style
= CS_DBLCLKS
| CS_OWNDC
;
709 cls
.lpszClassName
= "owndc_class";
710 RegisterClassA(&cls
);
711 cls
.style
= CS_DBLCLKS
| CS_CLASSDC
;
712 cls
.lpszClassName
= "classdc_class";
713 RegisterClassA(&cls
);
714 cls
.style
= CS_PARENTDC
;
715 cls
.lpszClassName
= "parentdc_class";
716 RegisterClassA(&cls
);
718 hwnd_cache
= CreateWindowA("cache_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
720 0, 0, GetModuleHandleA(0), NULL
);
721 hwnd_owndc
= CreateWindowA("owndc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
723 0, 0, GetModuleHandleA(0), NULL
);
724 hwnd_classdc
= CreateWindowA("classdc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
726 0, 0, GetModuleHandleA(0), NULL
);
727 hwnd_classdc2
= CreateWindowA("classdc_class", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
729 0, 0, GetModuleHandleA(0), NULL
);
730 hwnd_parent
= CreateWindowA("static", NULL
, WS_OVERLAPPED
| WS_VISIBLE
,
731 400, 0, 100, 100, 0, 0, 0, NULL
);
732 hwnd_parentdc
= CreateWindowA("parentdc_class", NULL
, WS_CHILD
| WS_VISIBLE
,
733 0, 0, 1, 1, hwnd_parent
, 0, 0, NULL
);
735 test_dc_attributes();
739 test_scroll_window();
740 test_invisible_create();
742 /* this should be last */
743 test_destroyed_window();