2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn
);
47 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
48 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
50 static BOOL test_lbuttondown_flag
;
51 static HWND hwndMessage
;
52 static HWND hwndMain
, hwndMain2
;
55 static const char* szAWRClass
= "Winsize";
59 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
61 /* try to make sure pending X events have been processed before continuing */
62 static void flush_events(void)
66 DWORD time
= GetTickCount() + diff
;
70 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min(10,diff
), QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
71 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
72 diff
= time
- GetTickCount();
76 /* check the values returned by the various parent/owner functions on a given window */
77 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
78 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
84 res
= pGetAncestor( hwnd
, GA_PARENT
);
85 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
87 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
88 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
89 res
= GetParent( hwnd
);
90 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
91 res
= GetWindow( hwnd
, GW_OWNER
);
92 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
95 res
= pGetAncestor( hwnd
, GA_ROOT
);
96 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
97 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
98 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
102 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
105 trace("EnumChildProc on %p\n", hwndChild
);
106 if (*(LPINT
)lParam
> 1) return FALSE
;
110 /* will search for the given window */
111 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
113 trace("EnumChildProc1 on %p\n", hwndChild
);
114 if ((HWND
)lParam
== hwndChild
) return FALSE
;
118 static HWND
create_tool_window( LONG style
, HWND parent
)
120 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
121 0, 0, 100, 100, parent
, 0, 0, NULL
);
122 ok( ret
!= 0, "Creation failed\n" );
126 /* test parent and owner values for various combinations */
127 static void test_parent_owner(void)
130 HWND test
, owner
, ret
;
131 HWND desktop
= GetDesktopWindow();
132 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
135 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
137 /* child without parent, should fail */
138 SetLastError(0xdeadbeef);
139 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
140 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
141 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
142 ok( !test
, "WS_CHILD without parent created\n" );
145 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
146 style
= GetWindowLongA( desktop
, GWL_STYLE
);
147 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
148 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
149 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
151 /* normal child window */
152 test
= create_tool_window( WS_CHILD
, hwndMain
);
153 trace( "created child %p\n", test
);
154 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
155 SetWindowLongA( test
, GWL_STYLE
, 0 );
156 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
157 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
158 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
159 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
160 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
161 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
162 DestroyWindow( test
);
164 /* normal child window with WS_MAXIMIZE */
165 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
166 DestroyWindow( test
);
168 /* normal child window with WS_THICKFRAME */
169 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
170 DestroyWindow( test
);
172 /* popup window with WS_THICKFRAME */
173 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
174 DestroyWindow( test
);
176 /* child of desktop */
177 test
= create_tool_window( WS_CHILD
, desktop
);
178 trace( "created child of desktop %p\n", test
);
179 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
180 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
181 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
182 SetWindowLongA( test
, GWL_STYLE
, 0 );
183 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
184 DestroyWindow( test
);
186 /* child of desktop with WS_MAXIMIZE */
187 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
188 DestroyWindow( test
);
190 /* child of desktop with WS_MINIMIZE */
191 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
192 DestroyWindow( test
);
195 test
= create_tool_window( WS_CHILD
, child
);
196 trace( "created child of child %p\n", test
);
197 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
198 SetWindowLongA( test
, GWL_STYLE
, 0 );
199 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
200 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
201 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
202 DestroyWindow( test
);
204 /* child of child with WS_MAXIMIZE */
205 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
206 DestroyWindow( test
);
208 /* child of child with WS_MINIMIZE */
209 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
210 DestroyWindow( test
);
212 /* not owned top-level window */
213 test
= create_tool_window( 0, 0 );
214 trace( "created top-level %p\n", test
);
215 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
216 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
217 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
218 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
219 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
220 DestroyWindow( test
);
222 /* not owned top-level window with WS_MAXIMIZE */
223 test
= create_tool_window( WS_MAXIMIZE
, 0 );
224 DestroyWindow( test
);
226 /* owned top-level window */
227 test
= create_tool_window( 0, hwndMain
);
228 trace( "created owned top-level %p\n", test
);
229 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
230 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
231 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
232 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
233 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
234 DestroyWindow( test
);
236 /* owned top-level window with WS_MAXIMIZE */
237 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
238 DestroyWindow( test
);
240 /* not owned popup */
241 test
= create_tool_window( WS_POPUP
, 0 );
242 trace( "created popup %p\n", test
);
243 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
244 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
245 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
246 SetWindowLongA( test
, GWL_STYLE
, 0 );
247 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
248 DestroyWindow( test
);
250 /* not owned popup with WS_MAXIMIZE */
251 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
252 DestroyWindow( test
);
255 test
= create_tool_window( WS_POPUP
, hwndMain
);
256 trace( "created owned popup %p\n", test
);
257 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
258 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
259 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
260 SetWindowLongA( test
, GWL_STYLE
, 0 );
261 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
262 DestroyWindow( test
);
264 /* owned popup with WS_MAXIMIZE */
265 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
266 DestroyWindow( test
);
268 /* top-level window owned by child (same as owned by top-level) */
269 test
= create_tool_window( 0, child
);
270 trace( "created top-level owned by child %p\n", test
);
271 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
272 DestroyWindow( test
);
274 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
275 test
= create_tool_window( WS_MAXIMIZE
, child
);
276 DestroyWindow( test
);
278 /* popup owned by desktop (same as not owned) */
279 test
= create_tool_window( WS_POPUP
, desktop
);
280 trace( "created popup owned by desktop %p\n", test
);
281 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
282 DestroyWindow( test
);
284 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
285 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
286 DestroyWindow( test
);
288 /* popup owned by child (same as owned by top-level) */
289 test
= create_tool_window( WS_POPUP
, child
);
290 trace( "created popup owned by child %p\n", test
);
291 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
292 DestroyWindow( test
);
294 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
296 DestroyWindow( test
);
298 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
299 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
300 trace( "created WS_CHILD popup %p\n", test
);
301 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
302 DestroyWindow( test
);
304 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
305 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
306 DestroyWindow( test
);
308 /* owned popup with WS_CHILD (same as WS_POPUP only) */
309 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
310 trace( "created owned WS_CHILD popup %p\n", test
);
311 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
312 DestroyWindow( test
);
314 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
315 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
316 DestroyWindow( test
);
318 /******************** parent changes *************************/
319 trace( "testing parent changes\n" );
322 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
325 /* this test succeeds on NT but crashes on win9x systems */
326 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
327 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
328 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
329 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
330 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
332 /* normal child window */
333 test
= create_tool_window( WS_CHILD
, hwndMain
);
334 trace( "created child %p\n", test
);
336 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
337 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
338 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
340 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
341 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
342 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
344 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
345 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
346 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
348 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
349 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
350 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
351 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
353 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
354 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
355 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
356 DestroyWindow( test
);
358 /* not owned top-level window */
359 test
= create_tool_window( 0, 0 );
360 trace( "created top-level %p\n", test
);
362 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
363 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
364 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
366 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
367 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
368 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
370 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
371 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
372 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
373 DestroyWindow( test
);
375 /* not owned popup */
376 test
= create_tool_window( WS_POPUP
, 0 );
377 trace( "created popup %p\n", test
);
379 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
380 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
381 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
383 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
384 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
385 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
387 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
388 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
389 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
390 DestroyWindow( test
);
392 /* normal child window */
393 test
= create_tool_window( WS_CHILD
, hwndMain
);
394 trace( "created child %p\n", test
);
396 ret
= SetParent( test
, desktop
);
397 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
398 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
400 ret
= SetParent( test
, child
);
401 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
402 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
404 ret
= SetParent( test
, hwndMain2
);
405 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
406 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
407 DestroyWindow( test
);
409 /* not owned top-level window */
410 test
= create_tool_window( 0, 0 );
411 trace( "created top-level %p\n", test
);
413 ret
= SetParent( test
, child
);
414 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
415 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
416 DestroyWindow( test
);
419 test
= create_tool_window( WS_POPUP
, hwndMain2
);
420 trace( "created owned popup %p\n", test
);
422 ret
= SetParent( test
, child
);
423 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
424 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
426 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
427 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
428 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
429 DestroyWindow( test
);
431 /**************** test owner destruction *******************/
433 /* owned child popup */
434 owner
= create_tool_window( 0, 0 );
435 test
= create_tool_window( WS_POPUP
, owner
);
436 trace( "created owner %p and popup %p\n", owner
, test
);
437 ret
= SetParent( test
, child
);
438 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
439 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
440 /* window is now child of 'child' but owned by 'owner' */
441 DestroyWindow( owner
);
442 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
443 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
444 * while Win95, Win2k, WinXP do.
446 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
447 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
450 /* owned top-level popup */
451 owner
= create_tool_window( 0, 0 );
452 test
= create_tool_window( WS_POPUP
, owner
);
453 trace( "created owner %p and popup %p\n", owner
, test
);
454 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
455 DestroyWindow( owner
);
456 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
458 /* top-level popup owned by child */
459 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
460 test
= create_tool_window( WS_POPUP
, 0 );
461 trace( "created owner %p and popup %p\n", owner
, test
);
462 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
463 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
464 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
465 DestroyWindow( owner
);
466 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
467 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
468 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
469 * while Win95, Win2k, WinXP do.
471 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
475 DestroyWindow(child
);
478 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
479 test
= create_tool_window( WS_POPUP
, desktop
);
481 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
483 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
484 "EnumChildWindows should have returned FALSE\n" );
485 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
487 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
488 ret
= SetParent( test
, owner
);
489 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
492 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
493 "EnumChildWindows should have returned TRUE\n" );
494 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
496 child
= create_tool_window( WS_CHILD
, owner
);
498 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
499 "EnumChildWindows should have returned FALSE\n" );
500 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
501 DestroyWindow( child
);
503 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
504 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
506 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
510 ret
= SetParent( child
, owner
);
511 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
512 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
514 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
518 ret
= SetParent( child
, NULL
);
519 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
520 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
522 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
523 "EnumChildWindows should have returned TRUE\n" );
524 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
526 /* even GW_OWNER == owner it's still a desktop's child */
527 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
528 "EnumChildWindows should have found %p and returned FALSE\n", child
);
530 DestroyWindow( child
);
531 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
533 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
534 "EnumChildWindows should have found %p and returned FALSE\n", child
);
536 DestroyWindow( child
);
537 DestroyWindow( test
);
538 DestroyWindow( owner
);
542 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
546 case WM_GETMINMAXINFO
:
548 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
550 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
551 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
552 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
553 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
554 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
555 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
556 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
557 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
558 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
561 case WM_WINDOWPOSCHANGING
:
563 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
564 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
565 trace("main: WM_WINDOWPOSCHANGING\n");
566 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
567 winpos
->hwnd
, winpos
->hwndInsertAfter
,
568 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
569 if (!(winpos
->flags
& SWP_NOMOVE
))
571 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
572 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
574 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
575 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
577 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
578 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
582 case WM_WINDOWPOSCHANGED
:
585 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
586 trace("main: WM_WINDOWPOSCHANGED\n");
587 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
588 winpos
->hwnd
, winpos
->hwndInsertAfter
,
589 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
590 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
591 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
593 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
594 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
596 GetWindowRect(hwnd
, &rc1
);
597 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
598 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
599 /* note: winpos coordinates are relative to parent */
600 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
601 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
604 /* Uncomment this once the test succeeds in all cases */
605 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
608 GetClientRect(hwnd
, &rc2
);
609 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
610 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
611 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
612 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
617 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
618 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
620 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
621 if (got_getminmaxinfo
)
622 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
624 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
625 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
627 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
631 if (test_lbuttondown_flag
)
632 ShowWindow((HWND
)wparam
, SW_SHOW
);
636 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
639 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
643 case WM_GETMINMAXINFO
:
645 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
647 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
648 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
649 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
650 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
651 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
652 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
653 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
654 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
655 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
660 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
661 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
663 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
664 if (got_getminmaxinfo
)
665 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
667 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
668 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
670 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
675 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
678 static BOOL
RegisterWindowClasses(void)
682 cls
.style
= CS_DBLCLKS
;
683 cls
.lpfnWndProc
= main_window_procA
;
686 cls
.hInstance
= GetModuleHandleA(0);
688 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
689 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
690 cls
.lpszMenuName
= NULL
;
691 cls
.lpszClassName
= "MainWindowClass";
693 if(!RegisterClassA(&cls
)) return FALSE
;
696 cls
.lpfnWndProc
= tool_window_procA
;
699 cls
.hInstance
= GetModuleHandleA(0);
701 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
702 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
703 cls
.lpszMenuName
= NULL
;
704 cls
.lpszClassName
= "ToolWindowClass";
706 if(!RegisterClassA(&cls
)) return FALSE
;
711 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
713 RECT rcWindow
, rcClient
;
716 ok(IsWindow(hwnd
), "bad window handle\n");
718 GetWindowRect(hwnd
, &rcWindow
);
719 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
721 GetClientRect(hwnd
, &rcClient
);
722 /* translate to screen coordinates */
723 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
724 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
726 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
727 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
728 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
729 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
731 ok((info
->dwExStyle
& ~0x800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
732 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
733 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
734 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
735 info
->dwWindowStatus
, status
);
737 trace("rcWindow: %d,%d - %d,%d\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
738 trace("rcClient: %d,%d - %d,%d\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
740 /* win2k and XP return broken border info in GetWindowInfo most of
741 * the time, so there is no point in testing it.
745 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
746 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
747 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
748 ok(info
->cyWindowBorders
== border
,
749 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
751 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
752 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
753 info
->wCreatorVersion
== 0x0500 /* Vista */,
754 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
757 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
759 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
760 /* AdjustWindowRectEx does not include scroll bars */
761 if (style
& WS_VSCROLL
)
763 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
764 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
766 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
768 if (style
& WS_HSCROLL
)
769 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
772 static void test_nonclient_area(HWND hwnd
)
774 DWORD style
, exstyle
;
775 RECT rc_window
, rc_client
, rc
;
777 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
779 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
780 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
781 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
783 GetWindowRect(hwnd
, &rc_window
);
784 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
785 GetClientRect(hwnd
, &rc_client
);
786 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
788 /* avoid some cases when things go wrong */
789 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
790 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
792 CopyRect(&rc
, &rc_client
);
793 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
794 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
796 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
797 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
800 CopyRect(&rc
, &rc_window
);
801 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
802 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
803 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
804 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
806 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
810 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
811 SetRect(&rc_client
, 0, 0, 250, 150);
812 CopyRect(&rc_window
, &rc_client
);
813 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
814 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
815 trace("calc window: (%d,%d)-(%d,%d)\n",
816 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
818 CopyRect(&rc
, &rc_window
);
819 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
820 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
821 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
822 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
825 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
827 static const char *CBT_code_name
[10] = {
838 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
840 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
842 /* on HCBT_DESTROYWND window state is undefined */
843 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
849 /* Win98 actually does check the info.cbSize and doesn't allow
850 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
851 * WinXP do not check it at all.
853 info
.cbSize
= sizeof(WINDOWINFO
);
854 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
855 verify_window_info((HWND
)wParam
, &info
);
863 static const RECT rc_null
;
866 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
867 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
868 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
869 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
871 /* WS_VISIBLE should be turned off yet */
872 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
873 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
874 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
875 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
879 /* Uncomment this once the test succeeds in all cases */
880 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
882 ok(GetParent((HWND
)wParam
) == hwndMessage
,
883 "wrong result from GetParent %p: message window %p\n",
884 GetParent((HWND
)wParam
), hwndMessage
);
887 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
889 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
893 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
894 * Win9x still has them set to 0.
896 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
897 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
899 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
900 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
904 /* Uncomment this once the test succeeds in all cases */
907 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
908 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
909 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
911 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
912 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
913 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
915 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
916 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
919 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
920 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
921 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
922 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
928 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
931 static void test_shell_window(void)
935 HMODULE hinst
, hUser32
;
936 BOOL (WINAPI
*SetShellWindow
)(HWND
);
937 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
938 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
939 HWND shellWindow
, nextWnd
;
941 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
943 trace("Skipping shell window test on Win9x\n");
947 shellWindow
= GetShellWindow();
948 hinst
= GetModuleHandle(0);
949 hUser32
= GetModuleHandleA("user32");
951 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
952 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
954 trace("previous shell window: %p\n", shellWindow
);
960 ret
= DestroyWindow(shellWindow
);
961 error
= GetLastError();
963 ok(!ret
, "DestroyWindow(shellWindow)\n");
964 /* passes on Win XP, but not on Win98 */
965 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
967 /* close old shell instance */
968 GetWindowThreadProcessId(shellWindow
, &pid
);
969 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
970 ret
= TerminateProcess(hProcess
, 0);
971 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
972 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
973 CloseHandle(hProcess
);
976 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
977 trace("created window 1: %p\n", hwnd1
);
979 ret
= SetShellWindow(hwnd1
);
980 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
981 shellWindow
= GetShellWindow();
982 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
984 ret
= SetShellWindow(hwnd1
);
985 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
987 ret
= SetShellWindow(0);
988 error
= GetLastError();
989 /* passes on Win XP, but not on Win98
990 ok(!ret, "reset shell window by SetShellWindow(0)\n");
991 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
993 ret
= SetShellWindow(hwnd1
);
994 /* passes on Win XP, but not on Win98
995 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
997 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
998 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
999 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1001 ret
= DestroyWindow(hwnd1
);
1002 ok(ret
, "DestroyWindow(hwnd1)\n");
1004 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1005 trace("created window 2: %p\n", hwnd2
);
1006 ret
= SetShellWindow(hwnd2
);
1007 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1009 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1010 trace("created window 3: %p\n", hwnd3
);
1012 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1013 trace("created window 4: %p\n", hwnd4
);
1015 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1016 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1018 ret
= SetShellWindow(hwnd4
);
1019 ok(ret
, "SetShellWindow(hwnd4)\n");
1020 shellWindow
= GetShellWindow();
1021 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1023 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1024 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1026 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1027 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1029 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1030 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1032 ret
= SetShellWindow(hwnd3
);
1033 ok(!ret
, "SetShellWindow(hwnd3)\n");
1034 shellWindow
= GetShellWindow();
1035 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1037 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1038 trace("created window 5: %p\n", hwnd5
);
1039 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1040 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1044 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1045 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1048 /* destroy test windows */
1049 DestroyWindow(hwnd2
);
1050 DestroyWindow(hwnd3
);
1051 DestroyWindow(hwnd4
);
1052 DestroyWindow(hwnd5
);
1055 /************** MDI test ****************/
1057 static char mdi_lParam_test_message
[] = "just a test string";
1059 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1061 MDICREATESTRUCTA mdi_cs
;
1063 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1064 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1065 BOOL isWin9x
= FALSE
;
1067 mdi_cs
.szClass
= "MDI_child_Class_1";
1068 mdi_cs
.szTitle
= "MDI child";
1069 mdi_cs
.hOwner
= GetModuleHandle(0);
1070 mdi_cs
.x
= CW_USEDEFAULT
;
1071 mdi_cs
.y
= CW_USEDEFAULT
;
1072 mdi_cs
.cx
= CW_USEDEFAULT
;
1073 mdi_cs
.cy
= CW_USEDEFAULT
;
1075 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1076 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1077 ok(mdi_child
!= 0, "MDI child creation failed\n");
1078 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1079 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1080 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1082 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1083 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1084 ok(mdi_child
!= 0, "MDI child creation failed\n");
1085 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1086 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1087 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1089 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1090 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1091 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1093 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1097 ok(mdi_child
!= 0, "MDI child creation failed\n");
1098 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1099 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1100 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1103 /* test MDICREATESTRUCT A<->W mapping */
1104 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1106 mdi_cs
.szClass
= (LPCSTR
)classW
;
1107 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1108 SetLastError(0xdeadbeef);
1109 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1112 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1115 ok(mdi_child
!= 0, "MDI child creation failed\n");
1119 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1120 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1121 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1124 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1126 CW_USEDEFAULT
, CW_USEDEFAULT
,
1127 CW_USEDEFAULT
, CW_USEDEFAULT
,
1128 mdi_client
, GetModuleHandle(0),
1129 (LPARAM
)mdi_lParam_test_message
);
1130 ok(mdi_child
!= 0, "MDI child creation failed\n");
1131 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1132 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1133 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1135 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1136 0x7fffffff, /* without WS_POPUP */
1137 CW_USEDEFAULT
, CW_USEDEFAULT
,
1138 CW_USEDEFAULT
, CW_USEDEFAULT
,
1139 mdi_client
, GetModuleHandle(0),
1140 (LPARAM
)mdi_lParam_test_message
);
1141 ok(mdi_child
!= 0, "MDI child creation failed\n");
1142 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1143 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1144 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1146 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1147 0xffffffff, /* with WS_POPUP */
1148 CW_USEDEFAULT
, CW_USEDEFAULT
,
1149 CW_USEDEFAULT
, CW_USEDEFAULT
,
1150 mdi_client
, GetModuleHandle(0),
1151 (LPARAM
)mdi_lParam_test_message
);
1152 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1154 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1158 ok(mdi_child
!= 0, "MDI child creation failed\n");
1159 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1160 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1161 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1164 /* test MDICREATESTRUCT A<->W mapping */
1165 SetLastError(0xdeadbeef);
1166 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1168 CW_USEDEFAULT
, CW_USEDEFAULT
,
1169 CW_USEDEFAULT
, CW_USEDEFAULT
,
1170 mdi_client
, GetModuleHandle(0),
1171 (LPARAM
)mdi_lParam_test_message
);
1174 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1177 ok(mdi_child
!= 0, "MDI child creation failed\n");
1181 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1182 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1183 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1186 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1188 CW_USEDEFAULT
, CW_USEDEFAULT
,
1189 CW_USEDEFAULT
, CW_USEDEFAULT
,
1190 mdi_client
, 0, GetModuleHandle(0),
1191 (LPVOID
)mdi_lParam_test_message
);
1192 ok(mdi_child
!= 0, "MDI child creation failed\n");
1193 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1194 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1195 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1197 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1198 0x7fffffff, /* without WS_POPUP */
1199 CW_USEDEFAULT
, CW_USEDEFAULT
,
1200 CW_USEDEFAULT
, CW_USEDEFAULT
,
1201 mdi_client
, 0, GetModuleHandle(0),
1202 (LPVOID
)mdi_lParam_test_message
);
1203 ok(mdi_child
!= 0, "MDI child creation failed\n");
1204 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1205 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1206 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1208 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1209 0xffffffff, /* with WS_POPUP */
1210 CW_USEDEFAULT
, CW_USEDEFAULT
,
1211 CW_USEDEFAULT
, CW_USEDEFAULT
,
1212 mdi_client
, 0, GetModuleHandle(0),
1213 (LPVOID
)mdi_lParam_test_message
);
1214 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1216 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1220 ok(mdi_child
!= 0, "MDI child creation failed\n");
1221 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1222 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1223 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1226 /* test MDICREATESTRUCT A<->W mapping */
1227 SetLastError(0xdeadbeef);
1228 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1230 CW_USEDEFAULT
, CW_USEDEFAULT
,
1231 CW_USEDEFAULT
, CW_USEDEFAULT
,
1232 mdi_client
, 0, GetModuleHandle(0),
1233 (LPVOID
)mdi_lParam_test_message
);
1236 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1239 ok(mdi_child
!= 0, "MDI child creation failed\n");
1243 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1244 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1245 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1248 /* This test fails on Win9x */
1251 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1253 CW_USEDEFAULT
, CW_USEDEFAULT
,
1254 CW_USEDEFAULT
, CW_USEDEFAULT
,
1255 parent
, 0, GetModuleHandle(0),
1256 (LPVOID
)mdi_lParam_test_message
);
1257 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1260 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1261 WS_CHILD
, /* without WS_POPUP */
1262 CW_USEDEFAULT
, CW_USEDEFAULT
,
1263 CW_USEDEFAULT
, CW_USEDEFAULT
,
1264 mdi_client
, 0, GetModuleHandle(0),
1265 (LPVOID
)mdi_lParam_test_message
);
1266 ok(mdi_child
!= 0, "MDI child creation failed\n");
1267 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1268 DestroyWindow(mdi_child
);
1270 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1271 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1272 CW_USEDEFAULT
, CW_USEDEFAULT
,
1273 CW_USEDEFAULT
, CW_USEDEFAULT
,
1274 mdi_client
, 0, GetModuleHandle(0),
1275 (LPVOID
)mdi_lParam_test_message
);
1276 ok(mdi_child
!= 0, "MDI child creation failed\n");
1277 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1278 DestroyWindow(mdi_child
);
1280 /* maximized child */
1281 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1282 WS_CHILD
| WS_MAXIMIZE
,
1283 CW_USEDEFAULT
, CW_USEDEFAULT
,
1284 CW_USEDEFAULT
, CW_USEDEFAULT
,
1285 mdi_client
, 0, GetModuleHandle(0),
1286 (LPVOID
)mdi_lParam_test_message
);
1287 ok(mdi_child
!= 0, "MDI child creation failed\n");
1288 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1289 DestroyWindow(mdi_child
);
1291 trace("Creating maximized child with a caption\n");
1292 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1293 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1294 CW_USEDEFAULT
, CW_USEDEFAULT
,
1295 CW_USEDEFAULT
, CW_USEDEFAULT
,
1296 mdi_client
, 0, GetModuleHandle(0),
1297 (LPVOID
)mdi_lParam_test_message
);
1298 ok(mdi_child
!= 0, "MDI child creation failed\n");
1299 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1300 DestroyWindow(mdi_child
);
1302 trace("Creating maximized child with a caption and a thick frame\n");
1303 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1304 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1305 CW_USEDEFAULT
, CW_USEDEFAULT
,
1306 CW_USEDEFAULT
, CW_USEDEFAULT
,
1307 mdi_client
, 0, GetModuleHandle(0),
1308 (LPVOID
)mdi_lParam_test_message
);
1309 ok(mdi_child
!= 0, "MDI child creation failed\n");
1310 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1311 DestroyWindow(mdi_child
);
1314 /**********************************************************************
1315 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1317 * Note: The rule here is that client rect of the maximized MDI child
1318 * is equal to the client rect of the MDI client window.
1320 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1324 GetClientRect( client
, &rect
);
1325 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1326 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1328 rect
.right
-= rect
.left
;
1329 rect
.bottom
-= rect
.top
;
1330 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1331 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1333 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1334 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1336 trace("max rect (%d,%d - %d, %d)\n",
1337 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1340 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1347 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1348 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1350 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1351 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1353 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1354 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1355 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1356 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1357 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1359 /* MDICREATESTRUCT should have original values */
1360 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1361 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1362 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1363 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1364 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1365 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1367 /* CREATESTRUCT should have fixed values */
1368 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1369 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1371 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1372 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1373 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1375 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1377 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1379 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1380 ok(cs
->style
== style
,
1381 "cs->style does not match (%08x)\n", cs
->style
);
1385 LONG style
= mdi_cs
->style
;
1387 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1388 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1389 ok(cs
->style
== style
,
1390 "cs->style does not match (%08x)\n", cs
->style
);
1395 case WM_GETMINMAXINFO
:
1397 HWND client
= GetParent(hwnd
);
1399 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1400 MINMAXINFO my_minmax
;
1401 LONG style
, exstyle
;
1403 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1404 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1406 GetWindowRect(client
, &rc
);
1407 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1408 GetClientRect(client
, &rc
);
1409 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1410 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1411 GetSystemMetrics(SM_CYSCREEN
));
1413 GetClientRect(client
, &rc
);
1414 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1415 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1416 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1417 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1419 trace("ptReserved = (%d,%d)\n"
1420 "ptMaxSize = (%d,%d)\n"
1421 "ptMaxPosition = (%d,%d)\n"
1422 "ptMinTrackSize = (%d,%d)\n"
1423 "ptMaxTrackSize = (%d,%d)\n",
1424 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1425 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1426 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1427 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1428 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1430 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1431 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1432 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1433 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1435 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1437 trace("DefMDIChildProc returned:\n"
1438 "ptReserved = (%d,%d)\n"
1439 "ptMaxSize = (%d,%d)\n"
1440 "ptMaxPosition = (%d,%d)\n"
1441 "ptMinTrackSize = (%d,%d)\n"
1442 "ptMaxTrackSize = (%d,%d)\n",
1443 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1444 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1445 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1446 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1447 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1449 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1450 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1451 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1452 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1453 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1458 case WM_MDIACTIVATE
:
1460 HWND active
, client
= GetParent(hwnd
);
1461 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1462 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1463 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1464 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1466 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1470 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1473 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1480 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1482 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1483 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1485 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1486 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1488 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1489 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1491 /* CREATESTRUCT should have fixed values */
1492 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1494 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1495 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1497 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1498 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1499 while Win95, Win2k, WinXP do. */
1500 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1501 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1505 case WM_GETMINMAXINFO
:
1507 HWND parent
= GetParent(hwnd
);
1509 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1510 LONG style
, exstyle
;
1512 trace("WM_GETMINMAXINFO\n");
1514 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1515 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1517 GetClientRect(parent
, &rc
);
1518 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1520 GetClientRect(parent
, &rc
);
1521 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1522 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1523 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1524 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1526 trace("ptReserved = (%d,%d)\n"
1527 "ptMaxSize = (%d,%d)\n"
1528 "ptMaxPosition = (%d,%d)\n"
1529 "ptMinTrackSize = (%d,%d)\n"
1530 "ptMaxTrackSize = (%d,%d)\n",
1531 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1532 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1533 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1534 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1535 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1537 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1538 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1539 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1540 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1544 case WM_WINDOWPOSCHANGED
:
1546 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1549 GetWindowRect(hwnd
, &rc1
);
1550 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1551 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1552 /* note: winpos coordinates are relative to parent */
1553 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1554 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1555 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1557 GetWindowRect(hwnd
, &rc1
);
1558 GetClientRect(hwnd
, &rc2
);
1559 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1560 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1561 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1564 case WM_WINDOWPOSCHANGING
:
1566 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1567 WINDOWPOS my_winpos
= *winpos
;
1569 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1570 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1571 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1572 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1574 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1576 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1577 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1578 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1580 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1581 "DefWindowProc should not change WINDOWPOS values\n");
1586 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1589 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1591 static HWND mdi_client
;
1597 CLIENTCREATESTRUCT client_cs
;
1600 GetClientRect(hwnd
, &rc
);
1602 client_cs
.hWindowMenu
= 0;
1603 client_cs
.idFirstChild
= 1;
1605 /* MDIClient without MDIS_ALLCHILDSTYLES */
1606 mdi_client
= CreateWindowExA(0, "mdiclient",
1608 WS_CHILD
/*| WS_VISIBLE*/,
1609 /* tests depend on a not zero MDIClient size */
1610 0, 0, rc
.right
, rc
.bottom
,
1611 hwnd
, 0, GetModuleHandle(0),
1612 (LPVOID
)&client_cs
);
1614 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1615 DestroyWindow(mdi_client
);
1617 /* MDIClient with MDIS_ALLCHILDSTYLES */
1618 mdi_client
= CreateWindowExA(0, "mdiclient",
1620 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1621 /* tests depend on a not zero MDIClient size */
1622 0, 0, rc
.right
, rc
.bottom
,
1623 hwnd
, 0, GetModuleHandle(0),
1624 (LPVOID
)&client_cs
);
1626 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1627 DestroyWindow(mdi_client
);
1631 case WM_WINDOWPOSCHANGED
:
1633 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1636 GetWindowRect(hwnd
, &rc1
);
1637 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1638 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1639 /* note: winpos coordinates are relative to parent */
1640 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1641 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1642 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1644 GetWindowRect(hwnd
, &rc1
);
1645 GetClientRect(hwnd
, &rc2
);
1646 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1647 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1648 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1651 case WM_WINDOWPOSCHANGING
:
1653 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1654 WINDOWPOS my_winpos
= *winpos
;
1656 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1657 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1658 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1659 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1661 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1663 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1664 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1665 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1667 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1668 "DefWindowProc should not change WINDOWPOS values\n");
1677 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1680 static BOOL
mdi_RegisterWindowClasses(void)
1685 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1688 cls
.hInstance
= GetModuleHandleA(0);
1690 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1691 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1692 cls
.lpszMenuName
= NULL
;
1693 cls
.lpszClassName
= "MDI_parent_Class";
1694 if(!RegisterClassA(&cls
)) return FALSE
;
1696 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1697 cls
.lpszClassName
= "MDI_child_Class_1";
1698 if(!RegisterClassA(&cls
)) return FALSE
;
1700 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1701 cls
.lpszClassName
= "MDI_child_Class_2";
1702 if(!RegisterClassA(&cls
)) return FALSE
;
1707 static void test_mdi(void)
1712 if (!mdi_RegisterWindowClasses()) assert(0);
1714 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1715 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1716 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1717 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1718 GetDesktopWindow(), 0,
1719 GetModuleHandle(0), NULL
);
1720 assert(mdi_hwndMain
);
1722 while(GetMessage(&msg, 0, 0, 0))
1724 TranslateMessage(&msg);
1725 DispatchMessage(&msg);
1728 DestroyWindow(mdi_hwndMain
);
1731 static void test_icons(void)
1735 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1736 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1737 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1738 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1741 cls
.cbSize
= sizeof(cls
);
1743 cls
.lpfnWndProc
= DefWindowProcA
;
1747 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1748 cls
.hIconSm
= small_icon
;
1749 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1750 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1751 cls
.lpszMenuName
= NULL
;
1752 cls
.lpszClassName
= "IconWindowClass";
1754 RegisterClassExA(&cls
);
1756 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1757 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1760 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1761 ok( res
== 0, "wrong big icon %p/0\n", res
);
1762 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1763 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1764 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1765 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1766 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1767 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1768 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1769 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1771 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1772 ok( res
== 0, "wrong small icon %p/0\n", res
);
1773 /* this test is XP specific */
1774 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1775 ok( res != 0, "wrong small icon %p\n", res );*/
1776 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1777 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1778 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1779 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1780 /* this test is XP specific */
1781 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1782 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1783 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1784 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1785 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1786 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1787 /* this test is XP specific */
1788 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1789 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1791 /* make sure the big icon hasn't changed */
1792 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1793 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1795 DestroyWindow( hwnd
);
1798 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1800 if (msg
== WM_NCCALCSIZE
)
1802 RECT
*rect
= (RECT
*)lparam
;
1803 /* first time around increase the rectangle, next time decrease it */
1804 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1805 else InflateRect( rect
, -10, -10 );
1808 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1811 static void test_SetWindowPos(HWND hwnd
)
1813 RECT orig_win_rc
, rect
;
1815 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1817 SetRect(&rect
, 111, 222, 333, 444);
1818 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1819 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1820 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1822 SetRect(&rect
, 111, 222, 333, 444);
1823 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1824 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1825 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1827 GetWindowRect(hwnd
, &orig_win_rc
);
1829 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1830 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1831 GetWindowRect( hwnd
, &rect
);
1832 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1833 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1834 GetClientRect( hwnd
, &rect
);
1835 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1836 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1837 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1839 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1840 GetWindowRect( hwnd
, &rect
);
1841 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1842 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1843 GetClientRect( hwnd
, &rect
);
1844 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1845 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1846 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1848 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1849 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1850 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1852 /* Win9x truncates coordinates to 16-bit irrespectively */
1855 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1856 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1858 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1859 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1862 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1863 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1865 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1866 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1867 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1868 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1869 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1870 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1871 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1874 static void test_SetMenu(HWND parent
)
1878 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1882 hMenu
= CreateMenu();
1885 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1888 /* fails on (at least) Wine, NT4, XP SP2 */
1889 test_nonclient_area(parent
);
1891 ret
= GetMenu(parent
);
1892 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1893 /* test whether we can destroy a menu assigned to a window */
1894 retok
= DestroyMenu(hMenu
);
1895 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1896 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1897 ret
= GetMenu(parent
);
1898 /* This test fails on Win9x */
1900 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1901 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1902 test_nonclient_area(parent
);
1904 hMenu
= CreateMenu();
1908 ret
= GetMenu(parent
);
1909 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1911 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1912 test_nonclient_area(parent
);
1913 ret
= GetMenu(parent
);
1914 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1916 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1919 /* fails on (at least) Wine, NT4, XP SP2 */
1920 test_nonclient_area(parent
);
1922 ret
= GetMenu(parent
);
1923 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1925 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1926 test_nonclient_area(parent
);
1927 ret
= GetMenu(parent
);
1928 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1931 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1934 ret
= GetMenu(child
);
1935 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1937 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1938 test_nonclient_area(child
);
1939 ret
= GetMenu(child
);
1940 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1942 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1943 test_nonclient_area(child
);
1944 ret
= GetMenu(child
);
1945 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1947 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1948 test_nonclient_area(child
);
1949 ret
= GetMenu(child
);
1950 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1952 style
= GetWindowLong(child
, GWL_STYLE
);
1953 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1954 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1955 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1956 SetWindowLong(child
, GWL_STYLE
, style
);
1958 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1959 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1960 SetWindowLong(child
, GWL_STYLE
, style
);
1962 DestroyWindow(child
);
1966 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1968 HWND child
[5], hwnd
;
1973 hwnd
= GetWindow(parent
, GW_CHILD
);
1974 ok(!hwnd
, "have to start without children to perform the test\n");
1976 for (i
= 0; i
< total
; i
++)
1978 if (style
[i
] & DS_CONTROL
)
1980 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1981 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1982 if (style
[i
] & WS_VISIBLE
)
1983 ShowWindow(child
[i
], SW_SHOW
);
1985 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1988 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1989 parent
, (HMENU
)i
, 0, NULL
);
1990 trace("child[%d] = %p\n", i
, child
[i
]);
1991 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1994 hwnd
= GetWindow(parent
, GW_CHILD
);
1995 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1996 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1997 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1999 for (i
= 0; i
< total
; i
++)
2001 trace("hwnd[%d] = %p\n", i
, hwnd
);
2002 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
2004 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2007 for (i
= 0; i
< total
; i
++)
2008 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2011 static void test_children_zorder(HWND parent
)
2013 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2015 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2017 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2018 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2019 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2020 const int complex_order_1
[1] = { 0 };
2021 const int complex_order_2
[2] = { 1, 0 };
2022 const int complex_order_3
[3] = { 1, 0, 2 };
2023 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2024 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2025 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2026 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2027 WS_CHILD
| WS_VISIBLE
};
2028 const int complex_order_6
[3] = { 0, 1, 2 };
2030 /* simple WS_CHILD */
2031 test_window_tree(parent
, simple_style
, simple_order
, 5);
2033 /* complex children styles */
2034 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2035 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2036 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2037 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2038 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2040 /* another set of complex children styles */
2041 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2044 #define check_z_order(hwnd, next, prev, owner, topmost) \
2045 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2048 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2049 BOOL topmost
, const char *file
, int line
)
2054 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2055 /* skip foreign windows */
2056 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2057 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2059 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2060 test
= GetWindow(test
, GW_HWNDNEXT
);
2062 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2064 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2065 /* skip foreign windows */
2066 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2067 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2069 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2070 test
= GetWindow(test
, GW_HWNDPREV
);
2072 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2074 test
= GetWindow(hwnd
, GW_OWNER
);
2075 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2077 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2078 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2081 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2083 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2085 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2087 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2089 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2090 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2092 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2093 WS_OVERLAPPED
| WS_CAPTION
,
2095 0, 0, GetModuleHandle(0), NULL
);
2096 trace("hwnd_F %p\n", hwnd_F
);
2097 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2099 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2100 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2101 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2102 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2104 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2107 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2108 trace("hwnd_C %p\n", hwnd_C
);
2109 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2110 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2111 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2112 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2114 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2117 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2118 trace("hwnd_B %p\n", hwnd_B
);
2119 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2120 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2121 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2122 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2123 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2125 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2128 0, 0, GetModuleHandle(0), NULL
);
2129 trace("hwnd_A %p\n", hwnd_A
);
2130 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2131 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2132 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2133 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2134 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2135 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2137 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A
, hwnd_B
, hwnd_C
, hwnd_D
, hwnd_E
, hwnd_F
);
2139 /* move hwnd_F and its popups up */
2140 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2141 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2142 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2143 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2144 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2145 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2146 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2148 /* move hwnd_F and its popups down */
2149 #if 0 /* enable once Wine is fixed to pass this test */
2150 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2151 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2152 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2153 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2154 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2155 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2156 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2159 DestroyWindow(hwnd_A
);
2160 DestroyWindow(hwnd_B
);
2161 DestroyWindow(hwnd_C
);
2162 DestroyWindow(hwnd_F
);
2165 static void test_vis_rgn( HWND hwnd
)
2167 RECT win_rect
, rgn_rect
;
2168 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2171 ShowWindow(hwnd
,SW_SHOW
);
2172 hdc
= GetDC( hwnd
);
2173 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2174 GetWindowRect( hwnd
, &win_rect
);
2175 GetRgnBox( hrgn
, &rgn_rect
);
2176 if (GetVersion() & 0x80000000)
2178 trace("win9x, mapping to screen coords\n");
2179 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2181 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2182 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2183 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2184 rgn_rect
.left
, win_rect
.left
);
2185 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2186 rgn_rect
.top
, win_rect
.top
);
2187 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2188 rgn_rect
.right
, win_rect
.right
);
2189 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2190 rgn_rect
.bottom
, win_rect
.bottom
);
2191 ReleaseDC( hwnd
, hdc
);
2194 static void test_SetFocus(HWND hwnd
)
2198 /* check if we can set focus to non-visible windows */
2200 ShowWindow(hwnd
, SW_SHOW
);
2203 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2204 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2205 ShowWindow(hwnd
, SW_HIDE
);
2208 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2209 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2210 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2213 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2214 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2215 ShowWindow(child
, SW_SHOW
);
2216 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2217 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2218 ShowWindow(child
, SW_HIDE
);
2219 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2220 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2221 ShowWindow(child
, SW_SHOW
);
2223 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2224 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2225 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2227 ShowWindow(child
, SW_HIDE
);
2229 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2230 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2231 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2232 ShowWindow(child
, SW_HIDE
);
2233 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2235 ShowWindow(hwnd
, SW_SHOW
);
2236 ShowWindow(child
, SW_SHOW
);
2238 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2239 EnableWindow(hwnd
, FALSE
);
2240 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2241 EnableWindow(hwnd
, TRUE
);
2243 DestroyWindow( child
);
2246 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2248 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2250 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2251 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2252 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2255 static void test_SetActiveWindow(HWND hwnd
)
2259 ShowWindow(hwnd
, SW_HIDE
);
2262 check_wnd_state(0, 0, 0, 0);
2264 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2266 ShowWindow(hwnd
, SW_SHOW
);
2267 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2269 hwnd2
= SetActiveWindow(0);
2270 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2271 check_wnd_state(0, 0, 0, 0);
2273 hwnd2
= SetActiveWindow(hwnd
);
2274 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2275 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2277 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2278 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2280 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2281 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2283 ShowWindow(hwnd
, SW_HIDE
);
2284 check_wnd_state(0, 0, 0, 0);
2286 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2287 SetActiveWindow(hwnd
);
2288 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2290 ShowWindow(hwnd
, SW_SHOW
);
2291 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2293 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2294 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2296 DestroyWindow(hwnd2
);
2297 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2299 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2300 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2302 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2303 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2305 DestroyWindow(hwnd2
);
2306 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2309 static void test_SetForegroundWindow(HWND hwnd
)
2314 ShowWindow(hwnd
, SW_HIDE
);
2317 check_wnd_state(0, 0, 0, 0);
2319 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2321 ShowWindow(hwnd
, SW_SHOW
);
2322 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2324 hwnd2
= SetActiveWindow(0);
2325 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2326 check_wnd_state(0, 0, 0, 0);
2328 ret
= SetForegroundWindow(hwnd
);
2329 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2330 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2332 SetLastError(0xdeadbeef);
2333 ret
= SetForegroundWindow(0);
2334 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2335 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2336 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2338 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2339 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2341 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2342 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2344 hwnd2
= GetForegroundWindow();
2345 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2346 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2347 hwnd2
= GetForegroundWindow();
2348 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2350 ShowWindow(hwnd
, SW_HIDE
);
2351 check_wnd_state(0, 0, 0, 0);
2353 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2354 ret
= SetForegroundWindow(hwnd
);
2355 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2356 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2358 ShowWindow(hwnd
, SW_SHOW
);
2359 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2361 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2362 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2364 DestroyWindow(hwnd2
);
2365 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2367 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2368 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2370 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2371 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2373 DestroyWindow(hwnd2
);
2374 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2377 static WNDPROC old_button_proc
;
2379 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2384 key_state
= GetKeyState(VK_LBUTTON
);
2385 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2387 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2389 if (msg
== WM_LBUTTONDOWN
)
2393 check_wnd_state(button
, button
, button
, button
);
2395 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2397 trace("hwnd %p\n", hwnd
);
2399 check_wnd_state(button
, button
, button
, button
);
2401 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2403 check_wnd_state(button
, button
, button
, button
);
2405 DestroyWindow(hwnd
);
2407 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2409 trace("hwnd %p\n", hwnd
);
2411 check_wnd_state(button
, button
, button
, button
);
2413 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2414 * match internal button state.
2416 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2417 check_wnd_state(button
, button
, button
, 0);
2419 ShowWindow(hwnd
, SW_SHOW
);
2420 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2422 capture
= SetCapture(hwnd
);
2423 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2425 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2427 DestroyWindow(hwnd
);
2429 check_wnd_state(button
, 0, button
, 0);
2435 static void test_capture_1(void)
2437 HWND button
, capture
;
2439 capture
= GetCapture();
2440 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2442 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2444 trace("button %p\n", button
);
2446 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2448 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2450 capture
= SetCapture(button
);
2451 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2452 check_wnd_state(button
, 0, button
, button
);
2454 DestroyWindow(button
);
2455 check_wnd_state(0, 0, 0, 0);
2458 static void test_capture_2(void)
2460 HWND button
, hwnd
, capture
;
2462 check_wnd_state(0, 0, 0, 0);
2464 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2466 trace("button %p\n", button
);
2468 check_wnd_state(button
, button
, button
, 0);
2470 capture
= SetCapture(button
);
2471 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2473 check_wnd_state(button
, button
, button
, button
);
2475 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2476 * internal button state.
2478 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2479 check_wnd_state(button
, button
, button
, button
);
2481 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2483 trace("hwnd %p\n", hwnd
);
2485 check_wnd_state(button
, button
, button
, button
);
2487 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2489 check_wnd_state(button
, button
, button
, button
);
2491 DestroyWindow(hwnd
);
2493 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2495 trace("hwnd %p\n", hwnd
);
2497 check_wnd_state(button
, button
, button
, button
);
2499 ShowWindow(hwnd
, SW_SHOW
);
2501 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2503 capture
= SetCapture(hwnd
);
2504 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2506 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2508 DestroyWindow(hwnd
);
2509 check_wnd_state(button
, button
, button
, 0);
2511 DestroyWindow(button
);
2512 check_wnd_state(0, 0, 0, 0);
2515 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2519 ShowWindow(hwnd1
, SW_HIDE
);
2520 ShowWindow(hwnd2
, SW_HIDE
);
2522 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2523 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2526 check_wnd_state(0, 0, 0, hwnd1
);
2529 check_wnd_state(0, 0, 0, hwnd2
);
2531 ShowWindow(hwnd1
, SW_SHOW
);
2532 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2534 ret
= ReleaseCapture();
2535 ok (ret
, "releasecapture did not return TRUE.\n");
2536 ret
= ReleaseCapture();
2537 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2540 static void test_keyboard_input(HWND hwnd
)
2545 ShowWindow(hwnd
, SW_SHOW
);
2549 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2552 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2556 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2557 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2558 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2559 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2560 ok( !ret
, "message %04x available\n", msg
.message
);
2562 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2564 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2565 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2566 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2567 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2568 ok( !ret
, "message %04x available\n", msg
.message
);
2570 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2572 keybd_event(VK_SPACE
, 0, 0, 0);
2573 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2574 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2575 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2576 ok( !ret
, "message %04x available\n", msg
.message
);
2579 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2583 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2584 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2585 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2586 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2587 ok( !ret
, "message %04x available\n", msg
.message
);
2589 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2591 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2592 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2593 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2594 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2595 ok( !ret
, "message %04x available\n", msg
.message
);
2597 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2599 keybd_event(VK_SPACE
, 0, 0, 0);
2600 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2601 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2602 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2603 ok( !ret
, "message %04x available\n", msg
.message
);
2606 static void test_mouse_input(HWND hwnd
)
2616 ShowWindow(hwnd
, SW_SHOW
);
2619 GetWindowRect(hwnd
, &rc
);
2620 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2622 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2623 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2626 ShowWindow(popup
, SW_SHOW
);
2627 UpdateWindow(popup
);
2629 GetWindowRect(popup
, &rc
);
2630 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2632 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2633 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2634 trace("setting cursor to (%d,%d)\n", x
, y
);
2638 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2642 /* Check that setting the same position will generate WM_MOUSEMOVE */
2645 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2646 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2647 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n", x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2649 /* force the system to update its internal queue mouse position,
2650 * otherwise it won't generate relative mouse movements below.
2652 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2656 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2657 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2658 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2659 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2660 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2661 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2662 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2663 ok( !ret
, "message %04x available\n", msg
.message
);
2665 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2666 ShowWindow(popup
, SW_HIDE
);
2667 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2668 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2671 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2672 ShowWindow(hwnd
, SW_HIDE
);
2673 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2674 ok( !ret
, "message %04x available\n", msg
.message
);
2676 /* test mouse clicks */
2678 ShowWindow(hwnd
, SW_SHOW
);
2679 ShowWindow(popup
, SW_SHOW
);
2682 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2683 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2684 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2685 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2687 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2688 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2689 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2690 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2692 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2693 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2694 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2695 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2697 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2698 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2699 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2700 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2702 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2703 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2704 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2705 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2707 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2708 ok(!ret
, "message %04x available\n", msg
.message
);
2710 ShowWindow(popup
, SW_HIDE
);
2713 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2714 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2715 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2716 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2718 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2719 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2720 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2721 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2723 test_lbuttondown_flag
= TRUE
;
2724 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2725 test_lbuttondown_flag
= FALSE
;
2727 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2728 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2729 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2730 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2731 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2733 /* Test WM_MOUSEACTIVATE */
2734 #define TEST_MOUSEACTIVATE(A,B) \
2735 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2736 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2738 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2739 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2740 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2741 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2742 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2743 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2744 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2745 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2746 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2747 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2748 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2749 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2750 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2751 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2752 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2753 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2754 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2755 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2756 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2757 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2758 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2759 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2760 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2761 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2763 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2766 DestroyWindow(popup
);
2769 static void test_validatergn(HWND hwnd
)
2775 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2776 ShowWindow(hwnd
, SW_SHOW
);
2777 UpdateWindow( hwnd
);
2778 /* test that ValidateRect validates children*/
2779 InvalidateRect( child
, NULL
, 1);
2780 GetWindowRect( child
, &rc
);
2781 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2782 ret
= GetUpdateRect( child
, &rc2
, 0);
2783 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2784 "Update rectangle is empty!\n");
2785 ValidateRect( hwnd
, &rc
);
2786 ret
= GetUpdateRect( child
, &rc2
, 0);
2787 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2788 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2789 rc2
.right
, rc2
.bottom
);
2791 /* now test ValidateRgn */
2792 InvalidateRect( child
, NULL
, 1);
2793 GetWindowRect( child
, &rc
);
2794 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2795 rgn
= CreateRectRgnIndirect( &rc
);
2796 ValidateRgn( hwnd
, rgn
);
2797 ret
= GetUpdateRect( child
, &rc2
, 0);
2798 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2799 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2800 rc2
.right
, rc2
.bottom
);
2803 DestroyWindow( child
);
2806 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2808 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2809 GetWindowRect( hwnd
, prc
);
2810 trace("window rect is %d,%d - %d,%d\n",
2811 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2812 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2813 trace("nccalc rect is %d,%d - %d,%d\n",
2814 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2817 static void test_nccalcscroll(HWND parent
)
2820 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2821 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2822 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2823 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2824 10, 10, 200, 200, parent
, 0, 0, NULL
);
2825 ShowWindow( parent
, SW_SHOW
);
2826 UpdateWindow( parent
);
2828 /* test window too low for a horizontal scroll bar */
2829 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2830 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2831 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2833 /* test window just high enough for a horizontal scroll bar */
2834 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2835 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2836 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2838 /* test window too narrow for a vertical scroll bar */
2839 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2840 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2841 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2843 /* test window just wide enough for a vertical scroll bar */
2844 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2845 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2846 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2848 /* same test, but with client edge: not enough width */
2849 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2850 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2851 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2852 "Width should be %d size is %d,%d - %d,%d\n",
2853 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2855 DestroyWindow( hwnd
);
2858 static void test_SetParent(void)
2861 HWND desktop
= GetDesktopWindow();
2863 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2864 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2866 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2867 100, 100, 200, 200, 0, 0, 0, NULL
);
2868 assert(parent
!= 0);
2869 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2870 0, 0, 50, 50, parent
, 0, 0, NULL
);
2871 assert(child1
!= 0);
2872 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2873 0, 0, 50, 50, child1
, 0, 0, NULL
);
2874 assert(child2
!= 0);
2875 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2876 0, 0, 50, 50, child2
, 0, 0, NULL
);
2877 assert(child3
!= 0);
2878 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2879 0, 0, 50, 50, child3
, 0, 0, NULL
);
2880 assert(child4
!= 0);
2882 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2883 parent
, child1
, child2
, child3
, child4
);
2885 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2886 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2887 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2888 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2889 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2891 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2892 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2893 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2894 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2895 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2897 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2898 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2899 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2900 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2901 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2902 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2903 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2904 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2905 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2907 if (!is_win9x
) /* Win9x doesn't survive this test */
2909 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2910 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2911 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2912 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2913 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2914 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2915 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2917 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2918 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2919 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2920 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2921 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2924 hMenu
= CreateMenu();
2925 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2926 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2927 assert(sibling
!= 0);
2929 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2930 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2932 ret
= DestroyWindow(parent
);
2933 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2935 ok(!IsWindow(parent
), "parent still exists\n");
2936 ok(!IsWindow(sibling
), "sibling still exists\n");
2937 ok(!IsWindow(child1
), "child1 still exists\n");
2938 ok(!IsWindow(child2
), "child2 still exists\n");
2939 ok(!IsWindow(child3
), "child3 still exists\n");
2940 ok(!IsWindow(child4
), "child4 still exists\n");
2943 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2945 LPCREATESTRUCT lpcs
;
2952 lpcs
= (LPCREATESTRUCT
)lparam
;
2953 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2956 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2957 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2958 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2959 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2961 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2963 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2964 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2965 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2967 ok(lpss
->styleNew
== lpcs
->style
,
2968 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2969 lpss
->styleNew
, lpcs
->style
);
2973 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2976 static ATOM atomStyleCheckClass
;
2978 static void register_style_check_class(void)
2986 GetModuleHandle(NULL
),
2988 LoadCursor(NULL
, IDC_ARROW
),
2989 (HBRUSH
)(COLOR_BTNFACE
+1),
2991 TEXT("WineStyleCheck"),
2994 atomStyleCheckClass
= RegisterClass(&wc
);
2997 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
2999 DWORD dwActualStyle
;
3000 DWORD dwActualExStyle
;
3003 HWND hwndParent
= NULL
;
3005 ss
.styleNew
= dwStyleIn
;
3006 ss
.styleOld
= dwExStyleIn
;
3008 if (dwStyleIn
& WS_CHILD
)
3010 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3011 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3014 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3015 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3020 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3021 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3022 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3023 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3024 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3026 DestroyWindow(hwnd
);
3027 if (hwndParent
) DestroyWindow(hwndParent
);
3030 /* tests what window styles the window manager automatically adds */
3031 static void test_window_styles(void)
3033 register_style_check_class();
3035 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3036 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3037 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3038 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3039 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3040 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3041 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3042 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3043 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3044 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3045 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3048 static void test_scrollvalidate( HWND parent
)
3051 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3052 HRGN exprgn
, tmprgn
, clipping
;
3053 RECT rc
, rcu
, cliprc
;
3054 /* create two overlapping child windows. The visual region
3055 * of hwnd1 is clipped by the overlapping part of
3056 * hwnd2 because of the WS_CLIPSIBLING style */
3059 clipping
= CreateRectRgn(0,0,0,0);
3060 tmprgn
= CreateRectRgn(0,0,0,0);
3061 exprgn
= CreateRectRgn(0,0,0,0);
3062 hwnd2
= CreateWindowExA(0, "static", NULL
,
3063 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3064 75, 30, 100, 100, parent
, 0, 0, NULL
);
3065 hwnd1
= CreateWindowExA(0, "static", NULL
,
3066 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3067 25, 50, 100, 100, parent
, 0, 0, NULL
);
3068 ShowWindow( parent
, SW_SHOW
);
3069 UpdateWindow( parent
);
3070 GetClientRect( hwnd1
, &rc
);
3072 SetRectRgn( clipping
, 10, 10, 90, 90);
3073 hdc
= GetDC( hwnd1
);
3074 /* for a visual touch */
3075 TextOut( hdc
, 0,10, "0123456789", 10);
3076 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3077 if (winetest_debug
> 0) dump_region(hrgn
);
3078 /* create a region with what is expected */
3079 SetRectRgn( exprgn
, 39,0,49,74);
3080 SetRectRgn( tmprgn
, 88,79,98,93);
3081 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3082 SetRectRgn( tmprgn
, 0,93,98,98);
3083 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3084 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3085 trace("update rect is %d,%d - %d,%d\n",
3086 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3087 /* now with clipping region */
3088 SelectClipRgn( hdc
, clipping
);
3089 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3090 if (winetest_debug
> 0) dump_region(hrgn
);
3091 /* create a region with what is expected */
3092 SetRectRgn( exprgn
, 39,10,49,74);
3093 SetRectRgn( tmprgn
, 80,79,90,85);
3094 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3095 SetRectRgn( tmprgn
, 10,85,90,90);
3096 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3097 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3098 trace("update rect is %d,%d - %d,%d\n",
3099 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3100 ReleaseDC( hwnd1
, hdc
);
3102 /* test scrolling a window with an update region */
3103 DestroyWindow( hwnd2
);
3104 ValidateRect( hwnd1
, NULL
);
3105 SetRect( &rc
, 40,40, 50,50);
3106 InvalidateRect( hwnd1
, &rc
, 1);
3107 GetClientRect( hwnd1
, &rc
);
3109 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3110 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3111 if (winetest_debug
> 0) dump_region(hrgn
);
3112 SetRectRgn( exprgn
, 88,0,98,98);
3113 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3114 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3115 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3117 /* clear an update region */
3118 UpdateWindow( hwnd1
);
3120 SetRect( &rc
, 0,40, 100,60);
3121 SetRect( &cliprc
, 0,0, 100,100);
3122 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3123 if (winetest_debug
> 0) dump_region( hrgn
);
3124 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3125 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3127 /* now test ScrollWindowEx with a combination of
3128 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3129 /* make hwnd2 the child of hwnd1 */
3130 hwnd2
= CreateWindowExA(0, "static", NULL
,
3131 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3132 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3133 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3134 GetClientRect( hwnd1
, &rc
);
3137 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3138 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3139 ValidateRect( hwnd1
, NULL
);
3140 ValidateRect( hwnd2
, NULL
);
3141 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3142 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3143 if (winetest_debug
> 0) dump_region(hrgn
);
3144 SetRectRgn( exprgn
, 88,0,98,88);
3145 SetRectRgn( tmprgn
, 0,88,98,98);
3146 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3147 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3149 /* SW_SCROLLCHILDREN */
3150 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3151 ValidateRect( hwnd1
, NULL
);
3152 ValidateRect( hwnd2
, NULL
);
3153 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3154 if (winetest_debug
> 0) dump_region(hrgn
);
3155 /* expected region is the same as in previous test */
3156 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3158 /* no SW_SCROLLCHILDREN */
3159 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3160 ValidateRect( hwnd1
, NULL
);
3161 ValidateRect( hwnd2
, NULL
);
3162 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3163 if (winetest_debug
> 0) dump_region(hrgn
);
3164 /* expected region is the same as in previous test */
3165 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3167 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3168 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3169 ValidateRect( hwnd1
, NULL
);
3170 ValidateRect( hwnd2
, NULL
);
3171 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3172 if (winetest_debug
> 0) dump_region(hrgn
);
3173 SetRectRgn( exprgn
, 88,0,98,20);
3174 SetRectRgn( tmprgn
, 20,20,98,30);
3175 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3176 SetRectRgn( tmprgn
, 20,30,30,88);
3177 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3178 SetRectRgn( tmprgn
, 0,88,30,98);
3179 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3180 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3183 DeleteObject( hrgn
);
3184 DeleteObject( exprgn
);
3185 DeleteObject( tmprgn
);
3186 DestroyWindow( hwnd1
);
3187 DestroyWindow( hwnd2
);
3190 /* couple of tests of return values of scrollbar functions
3191 * called on a scrollbarless window */
3192 static void test_scroll(void)
3197 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3198 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3199 100, 100, 200, 200, 0, 0, 0, NULL
);
3201 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3202 ok( ret
, "GetScrollRange returns FALSE\n");
3203 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3204 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3205 si
.cbSize
= sizeof( si
);
3206 si
.fMask
= SIF_PAGE
;
3207 si
.nPage
= 0xdeadbeef;
3208 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3209 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3210 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3212 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3213 ok( ret
, "GetScrollRange returns FALSE\n");
3214 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3215 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3216 si
.cbSize
= sizeof( si
);
3217 si
.fMask
= SIF_PAGE
;
3218 si
.nPage
= 0xdeadbeef;
3219 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3220 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3221 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3223 DestroyWindow( hwnd
);
3226 static void test_scrolldc( HWND parent
)
3229 HRGN exprgn
, tmprgn
, hrgn
;
3230 RECT rc
, rc2
, rcu
, cliprc
;
3234 hrgn
= CreateRectRgn(0,0,0,0);
3235 tmprgn
= CreateRectRgn(0,0,0,0);
3236 exprgn
= CreateRectRgn(0,0,0,0);
3238 hwnd1
= CreateWindowExA(0, "static", NULL
,
3239 WS_CHILD
| WS_VISIBLE
,
3240 25, 50, 100, 100, parent
, 0, 0, NULL
);
3241 ShowWindow( parent
, SW_SHOW
);
3242 UpdateWindow( parent
);
3243 GetClientRect( hwnd1
, &rc
);
3244 hdc
= GetDC( hwnd1
);
3245 /* paint the upper half of the window black */
3247 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3248 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3249 /* clip region is the lower half */
3251 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3252 /* test whether scrolled pixels are properly clipped */
3253 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3254 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3255 /* this scroll should not cause any visible changes */
3256 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3257 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3258 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3259 /* test with NULL clip rect */
3260 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3261 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3262 trace("update rect: %d,%d - %d,%d\n",
3263 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3264 if (winetest_debug
> 0) dump_region(hrgn
);
3265 SetRect(&rc2
, 0, 0, 100, 100);
3266 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3267 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3269 SetRectRgn( exprgn
, 0, 0, 20, 80);
3270 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3271 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3272 if (winetest_debug
> 0) dump_region(exprgn
);
3273 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3274 /* test clip rect > scroll rect */
3275 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3277 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3278 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3279 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3280 SetRectRgn( exprgn
, 25, 25, 75, 35);
3281 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3282 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3283 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3284 colr
= GetPixel( hdc
, 80, 80);
3285 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3286 trace("update rect: %d,%d - %d,%d\n",
3287 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3288 if (winetest_debug
> 0) dump_region(hrgn
);
3292 DeleteObject(exprgn
);
3293 DeleteObject(tmprgn
);
3294 DestroyWindow(hwnd1
);
3297 static void test_params(void)
3302 /* Just a param check */
3303 SetLastError(0xdeadbeef);
3304 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3305 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3307 SetLastError(0xdeadbeef);
3308 hwnd
=CreateWindow("LISTBOX", "TestList",
3309 (LBS_STANDARD
& ~LBS_SORT
),
3311 NULL
, (HMENU
)1, NULL
, 0);
3313 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3314 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3315 GetLastError() == 0xdeadbeef, /* Win9x */
3316 "wrong last error value %d\n", GetLastError());
3319 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3323 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3330 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3333 ShowWindow(hwnd
, SW_SHOW
);
3335 test_nonclient_area(hwnd
);
3338 DestroyWindow(hwnd
);
3341 static BOOL
AWR_init(void)
3345 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3346 class.lpfnWndProc
= DefWindowProcA
;
3347 class.cbClsExtra
= 0;
3348 class.cbWndExtra
= 0;
3349 class.hInstance
= 0;
3350 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3351 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3352 class.hbrBackground
= 0;
3353 class.lpszMenuName
= 0;
3354 class.lpszClassName
= szAWRClass
;
3356 if (!RegisterClass (&class)) {
3357 ok(FALSE
, "RegisterClass failed\n");
3361 hmenu
= CreateMenu();
3364 ok(hmenu
!= 0, "Failed to create menu\n");
3365 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3371 static void test_AWR_window_size(BOOL menu
)
3375 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3378 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3379 WS_HSCROLL
, WS_VSCROLL
3383 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3386 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3387 WS_EX_DLGMODALFRAME
,
3394 /* A exhaustive check of all the styles takes too long
3395 * so just do a (hopefully representative) sample
3397 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3398 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3399 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3400 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3401 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3406 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3408 static void test_AdjustWindowRect(void)
3413 SHOWSYSMETRIC(SM_CYCAPTION
);
3414 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3415 SHOWSYSMETRIC(SM_CYMENU
);
3416 SHOWSYSMETRIC(SM_CXEDGE
);
3417 SHOWSYSMETRIC(SM_CYEDGE
);
3418 SHOWSYSMETRIC(SM_CXVSCROLL
);
3419 SHOWSYSMETRIC(SM_CYHSCROLL
);
3420 SHOWSYSMETRIC(SM_CXFRAME
);
3421 SHOWSYSMETRIC(SM_CYFRAME
);
3422 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3423 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3424 SHOWSYSMETRIC(SM_CXBORDER
);
3425 SHOWSYSMETRIC(SM_CYBORDER
);
3427 test_AWR_window_size(FALSE
);
3428 test_AWR_window_size(TRUE
);
3432 #undef SHOWSYSMETRIC
3435 /* Global variables to trigger exit from loop */
3436 static int redrawComplete
, WMPAINT_count
;
3438 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3443 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3445 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3447 BeginPaint(hwnd
, &ps
);
3448 EndPaint(hwnd
, &ps
);
3453 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3456 /* Ensure we exit from RedrawNow regardless of invalidated area */
3457 static void test_redrawnow(void)
3462 cls
.style
= CS_DBLCLKS
;
3463 cls
.lpfnWndProc
= redraw_window_procA
;
3466 cls
.hInstance
= GetModuleHandleA(0);
3468 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3469 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3470 cls
.lpszMenuName
= NULL
;
3471 cls
.lpszClassName
= "RedrawWindowClass";
3473 if(!RegisterClassA(&cls
)) {
3474 trace("Register failed %d\n", GetLastError());
3478 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3479 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3481 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3482 ShowWindow(hwndMain
, SW_SHOW
);
3483 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3484 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3485 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3486 redrawComplete
= TRUE
;
3487 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3490 DestroyWindow( hwndMain
);
3493 struct parentdc_stat
{
3499 struct parentdc_test
{
3500 struct parentdc_stat main
, main_todo
;
3501 struct parentdc_stat child1
, child1_todo
;
3502 struct parentdc_stat child2
, child2_todo
;
3505 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3510 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3515 trace("doing WM_PAINT on %p\n", hwnd
);
3516 GetClientRect(hwnd
, &rc
);
3517 CopyRect(&t
->client
, &rc
);
3518 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3519 GetWindowRect(hwnd
, &rc
);
3520 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3521 BeginPaint(hwnd
, &ps
);
3522 CopyRect(&t
->paint
, &ps
.rcPaint
);
3523 GetClipBox(ps
.hdc
, &rc
);
3524 CopyRect(&t
->clip
, &rc
);
3525 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3526 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3527 EndPaint(hwnd
, &ps
);
3530 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3533 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3535 SetRectEmpty(&t
->client
);
3536 SetRectEmpty(&t
->clip
);
3537 SetRectEmpty(&t
->paint
);
3540 static void zero_parentdc_test(struct parentdc_test
*t
)
3542 zero_parentdc_stat(&t
->main
);
3543 zero_parentdc_stat(&t
->child1
);
3544 zero_parentdc_stat(&t
->child2
);
3547 #define parentdc_field_ok(t, w, r, f, got) \
3548 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3549 ": expected %d, got %d\n", \
3552 #define parentdc_todo_field_ok(t, w, r, f, got) \
3553 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3554 else parentdc_field_ok(t, w, r, f, got)
3556 #define parentdc_rect_ok(t, w, r, got) \
3557 parentdc_todo_field_ok(t, w, r, left, got); \
3558 parentdc_todo_field_ok(t, w, r, top, got); \
3559 parentdc_todo_field_ok(t, w, r, right, got); \
3560 parentdc_todo_field_ok(t, w, r, bottom, got);
3562 #define parentdc_win_ok(t, w, got) \
3563 parentdc_rect_ok(t, w, client, got); \
3564 parentdc_rect_ok(t, w, clip, got); \
3565 parentdc_rect_ok(t, w, paint, got);
3567 #define parentdc_ok(t, got) \
3568 parentdc_win_ok(t, main, got); \
3569 parentdc_win_ok(t, child1, got); \
3570 parentdc_win_ok(t, child2, got);
3572 static void test_csparentdc(void)
3574 WNDCLASSA clsMain
, cls
;
3575 HWND hwndMain
, hwnd1
, hwnd2
;
3578 struct parentdc_test test_answer
;
3580 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3581 const struct parentdc_test test1
=
3583 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3584 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3585 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3588 const struct parentdc_test test2
=
3590 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3591 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3592 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3595 const struct parentdc_test test3
=
3597 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3598 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3599 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3602 const struct parentdc_test test4
=
3604 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3605 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3606 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3609 const struct parentdc_test test5
=
3611 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3612 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3613 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3616 const struct parentdc_test test6
=
3618 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3619 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3620 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3623 const struct parentdc_test test7
=
3625 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3626 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3627 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3631 clsMain
.style
= CS_DBLCLKS
;
3632 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3633 clsMain
.cbClsExtra
= 0;
3634 clsMain
.cbWndExtra
= 0;
3635 clsMain
.hInstance
= GetModuleHandleA(0);
3637 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3638 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3639 clsMain
.lpszMenuName
= NULL
;
3640 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3642 if(!RegisterClassA(&clsMain
)) {
3643 trace("Register failed %d\n", GetLastError());
3647 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3648 cls
.lpfnWndProc
= parentdc_window_procA
;
3651 cls
.hInstance
= GetModuleHandleA(0);
3653 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3654 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3655 cls
.lpszMenuName
= NULL
;
3656 cls
.lpszClassName
= "ParentDcWindowClass";
3658 if(!RegisterClassA(&cls
)) {
3659 trace("Register failed %d\n", GetLastError());
3663 SetRect(&rc
, 0, 0, 150, 150);
3664 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3665 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3666 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3667 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3668 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3669 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3670 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3671 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3672 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3673 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3674 ShowWindow(hwndMain
, SW_SHOW
);
3675 ShowWindow(hwnd1
, SW_SHOW
);
3676 ShowWindow(hwnd2
, SW_SHOW
);
3679 zero_parentdc_test(&test_answer
);
3680 InvalidateRect(hwndMain
, NULL
, TRUE
);
3682 parentdc_ok(test1
, test_answer
);
3684 zero_parentdc_test(&test_answer
);
3685 SetRect(&rc
, 0, 0, 50, 50);
3686 InvalidateRect(hwndMain
, &rc
, TRUE
);
3688 parentdc_ok(test2
, test_answer
);
3690 zero_parentdc_test(&test_answer
);
3691 SetRect(&rc
, 0, 0, 10, 10);
3692 InvalidateRect(hwndMain
, &rc
, TRUE
);
3694 parentdc_ok(test3
, test_answer
);
3696 zero_parentdc_test(&test_answer
);
3697 SetRect(&rc
, 40, 40, 50, 50);
3698 InvalidateRect(hwndMain
, &rc
, TRUE
);
3700 parentdc_ok(test4
, test_answer
);
3702 zero_parentdc_test(&test_answer
);
3703 SetRect(&rc
, 20, 20, 60, 60);
3704 InvalidateRect(hwndMain
, &rc
, TRUE
);
3706 parentdc_ok(test5
, test_answer
);
3708 zero_parentdc_test(&test_answer
);
3709 SetRect(&rc
, 0, 0, 10, 10);
3710 InvalidateRect(hwnd1
, &rc
, TRUE
);
3712 parentdc_ok(test6
, test_answer
);
3714 zero_parentdc_test(&test_answer
);
3715 SetRect(&rc
, -5, -5, 65, 65);
3716 InvalidateRect(hwnd1
, &rc
, TRUE
);
3718 parentdc_ok(test7
, test_answer
);
3720 DestroyWindow(hwndMain
);
3721 DestroyWindow(hwnd1
);
3722 DestroyWindow(hwnd2
);
3725 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3727 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3730 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3732 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3735 static void test_IsWindowUnicode(void)
3737 static const char ansi_class_nameA
[] = "ansi class name";
3738 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3739 static const char unicode_class_nameA
[] = "unicode class name";
3740 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3745 memset(&classW
, 0, sizeof(classW
));
3746 classW
.hInstance
= GetModuleHandleA(0);
3747 classW
.lpfnWndProc
= def_window_procW
;
3748 classW
.lpszClassName
= unicode_class_nameW
;
3749 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3751 memset(&classA
, 0, sizeof(classA
));
3752 classA
.hInstance
= GetModuleHandleA(0);
3753 classA
.lpfnWndProc
= def_window_procA
;
3754 classA
.lpszClassName
= ansi_class_nameA
;
3755 assert(RegisterClassA(&classA
));
3757 /* unicode class: window proc */
3758 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3759 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3762 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3763 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3764 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3765 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3766 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3768 DestroyWindow(hwnd
);
3770 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3771 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3774 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3775 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3776 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3777 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3778 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3780 DestroyWindow(hwnd
);
3782 /* ansi class: window proc */
3783 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3784 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3787 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3788 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3789 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3790 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3791 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3793 DestroyWindow(hwnd
);
3795 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3796 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3799 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3800 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3801 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3802 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3803 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3805 DestroyWindow(hwnd
);
3807 /* unicode class: class proc */
3808 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3809 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3812 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3813 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3814 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3815 /* do not restore class window proc back to unicode */
3817 DestroyWindow(hwnd
);
3819 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3820 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3823 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3824 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3825 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3827 DestroyWindow(hwnd
);
3829 /* ansi class: class proc */
3830 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3831 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3834 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3835 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3836 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3837 /* do not restore class window proc back to ansi */
3839 DestroyWindow(hwnd
);
3841 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3842 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3845 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3846 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3847 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3849 DestroyWindow(hwnd
);
3852 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3856 if (msg
!= WM_GETMINMAXINFO
)
3857 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3859 minmax
= (MINMAXINFO
*)lp
;
3861 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3863 minmax
->ptReserved
.x
= 0;
3864 minmax
->ptReserved
.y
= 0;
3865 minmax
->ptMaxSize
.x
= 400;
3866 minmax
->ptMaxSize
.y
= 400;
3867 minmax
->ptMaxPosition
.x
= 300;
3868 minmax
->ptMaxPosition
.y
= 300;
3869 minmax
->ptMaxTrackSize
.x
= 200;
3870 minmax
->ptMaxTrackSize
.y
= 200;
3871 minmax
->ptMinTrackSize
.x
= 100;
3872 minmax
->ptMinTrackSize
.y
= 100;
3875 DefWindowProc(hwnd
, msg
, wp
, lp
);
3879 static int expected_cx
, expected_cy
;
3880 static RECT expected_rect
;
3882 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3886 case WM_GETMINMAXINFO
:
3889 GetWindowRect( hwnd
, &rect
);
3890 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3891 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3892 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3897 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3899 GetWindowRect( hwnd
, &rect
);
3900 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3901 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3902 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3903 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3904 ok( rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3905 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
,
3906 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3907 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3908 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3909 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3912 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3916 static void test_CreateWindow(void)
3924 #define expect_menu(window, menu) \
3925 SetLastError(0xdeadbeef); \
3926 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3928 #define expect_style(window, style)\
3929 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3931 #define expect_ex_style(window, ex_style)\
3932 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3934 hmenu
= CreateMenu();
3936 parent
= GetDesktopWindow();
3937 assert(parent
!= 0);
3939 SetLastError(0xdeadbeef);
3940 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3943 SetLastError(0xdeadbeef);
3944 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3945 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3946 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3947 expect_menu(hwnd
, 1);
3948 expect_style(hwnd
, WS_CHILD
);
3949 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3950 DestroyWindow(hwnd
);
3952 SetLastError(0xdeadbeef);
3953 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3954 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3955 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3956 expect_menu(hwnd
, 1);
3957 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3958 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3959 DestroyWindow(hwnd
);
3961 SetLastError(0xdeadbeef);
3962 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3963 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3964 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3965 expect_menu(hwnd
, 1);
3966 expect_style(hwnd
, WS_CHILD
);
3967 expect_ex_style(hwnd
, 0);
3968 DestroyWindow(hwnd
);
3970 SetLastError(0xdeadbeef);
3971 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3972 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3973 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3974 expect_menu(hwnd
, 1);
3975 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3976 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
3977 DestroyWindow(hwnd
);
3980 SetLastError(0xdeadbeef);
3981 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
3982 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3983 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3984 expect_menu(hwnd
, hmenu
);
3985 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
3986 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3987 DestroyWindow(hwnd
);
3988 SetLastError(0xdeadbeef);
3989 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
3990 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
3992 hmenu
= CreateMenu();
3994 SetLastError(0xdeadbeef);
3995 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
3996 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
3997 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3998 expect_menu(hwnd
, hmenu
);
3999 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4000 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4001 DestroyWindow(hwnd
);
4002 SetLastError(0xdeadbeef);
4003 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4004 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4006 hmenu
= CreateMenu();
4008 SetLastError(0xdeadbeef);
4009 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4010 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4011 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4012 expect_menu(hwnd
, hmenu
);
4013 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4014 expect_ex_style(hwnd
, 0);
4015 DestroyWindow(hwnd
);
4016 SetLastError(0xdeadbeef);
4017 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4018 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4020 hmenu
= CreateMenu();
4022 SetLastError(0xdeadbeef);
4023 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4024 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4025 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4026 expect_menu(hwnd
, hmenu
);
4027 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4028 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4029 DestroyWindow(hwnd
);
4030 SetLastError(0xdeadbeef);
4031 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4032 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4034 /* WS_CHILD | WS_POPUP */
4035 SetLastError(0xdeadbeef);
4036 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4037 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4038 ok(!hwnd
, "CreateWindowEx should fail\n");
4039 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4041 hmenu
= CreateMenu();
4043 SetLastError(0xdeadbeef);
4044 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4045 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4046 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4047 expect_menu(hwnd
, hmenu
);
4048 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4049 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4050 DestroyWindow(hwnd
);
4051 SetLastError(0xdeadbeef);
4052 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4053 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4055 SetLastError(0xdeadbeef);
4056 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4057 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4058 ok(!hwnd
, "CreateWindowEx should fail\n");
4059 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4061 hmenu
= CreateMenu();
4063 SetLastError(0xdeadbeef);
4064 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4065 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4066 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4067 expect_menu(hwnd
, hmenu
);
4068 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4069 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4070 DestroyWindow(hwnd
);
4071 SetLastError(0xdeadbeef);
4072 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4073 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4075 SetLastError(0xdeadbeef);
4076 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4077 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4078 ok(!hwnd
, "CreateWindowEx should fail\n");
4079 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4081 hmenu
= CreateMenu();
4083 SetLastError(0xdeadbeef);
4084 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4085 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4086 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4087 expect_menu(hwnd
, hmenu
);
4088 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4089 expect_ex_style(hwnd
, 0);
4090 DestroyWindow(hwnd
);
4091 SetLastError(0xdeadbeef);
4092 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4093 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4095 SetLastError(0xdeadbeef);
4096 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4097 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4098 ok(!hwnd
, "CreateWindowEx should fail\n");
4099 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4101 hmenu
= CreateMenu();
4103 SetLastError(0xdeadbeef);
4104 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4105 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4106 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4107 expect_menu(hwnd
, hmenu
);
4108 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4109 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4110 DestroyWindow(hwnd
);
4111 SetLastError(0xdeadbeef);
4112 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4113 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4115 /* test child window sizing */
4117 cls
.lpfnWndProc
= minmax_wnd_proc
;
4120 cls
.hInstance
= GetModuleHandle(0);
4122 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4123 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4124 cls
.lpszMenuName
= NULL
;
4125 cls
.lpszClassName
= "MinMax_WndClass";
4126 RegisterClass(&cls
);
4128 SetLastError(0xdeadbeef);
4129 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4130 0, 0, 100, 100, 0, 0, 0, NULL
);
4131 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4132 expect_menu(parent
, 0);
4133 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4134 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4136 memset(&minmax
, 0, sizeof(minmax
));
4137 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4138 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4139 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4140 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4141 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4143 GetWindowRect(parent
, &rc
);
4144 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4145 GetClientRect(parent
, &rc
);
4146 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4148 InflateRect(&rc
, 200, 200);
4149 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4151 SetLastError(0xdeadbeef);
4152 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4153 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4154 parent
, (HMENU
)1, 0, NULL
);
4155 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4156 expect_menu(hwnd
, 1);
4157 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4158 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4160 memset(&minmax
, 0, sizeof(minmax
));
4161 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4162 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4164 GetWindowRect(hwnd
, &rc
);
4165 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4166 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4167 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4168 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4169 DestroyWindow(hwnd
);
4171 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4172 cls
.lpszClassName
= "Sizes_WndClass";
4173 RegisterClass(&cls
);
4175 expected_cx
= expected_cy
= 200000;
4176 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4177 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4178 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4179 GetClientRect( hwnd
, &rc
);
4180 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4181 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4182 DestroyWindow(hwnd
);
4184 expected_cx
= expected_cy
= -10;
4185 SetRect( &expected_rect
, 0, 0, 0, 0 );
4186 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4187 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4188 GetClientRect( hwnd
, &rc
);
4189 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4190 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4191 DestroyWindow(hwnd
);
4193 expected_cx
= expected_cy
= -200000;
4194 SetRect( &expected_rect
, 0, 0, 0, 0 );
4195 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4196 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4197 GetClientRect( hwnd
, &rc
);
4198 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4199 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4200 DestroyWindow(hwnd
);
4202 /* top level window */
4203 expected_cx
= expected_cy
= 200000;
4204 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4205 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4206 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4207 GetClientRect( hwnd
, &rc
);
4208 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4209 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4210 DestroyWindow(hwnd
);
4212 DestroyWindow(parent
);
4214 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4215 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4219 #undef expect_ex_style
4222 /* function that remembers whether the system the test is running on sets the
4223 * last error for user32 functions to make the tests stricter */
4224 static int check_error(DWORD actual
, DWORD expected
)
4226 static int sets_last_error
= -1;
4227 if (sets_last_error
== -1)
4228 sets_last_error
= (actual
!= 0xdeadbeef);
4229 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4232 static void test_SetWindowLong(void)
4235 WNDPROC old_window_procW
;
4237 SetLastError(0xdeadbeef);
4238 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4239 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4240 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4241 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4243 SetLastError(0xdeadbeef);
4244 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4245 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4246 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4247 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4249 SetLastError(0xdeadbeef);
4250 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4251 ok((WNDPROC
)retval
== main_window_procA
,
4252 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4253 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4254 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4255 ok((WNDPROC
)retval
== main_window_procA
,
4256 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4257 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4259 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4260 SetLastError(0xdeadbeef);
4261 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4262 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4264 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4265 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4266 ok((WNDPROC
)retval
== old_window_procW
,
4267 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4268 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4270 /* set it back to ANSI */
4271 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4275 static void test_ShowWindow(void)
4282 SetRect(&rcMain
, 120, 120, 210, 210);
4284 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4285 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4286 WS_MAXIMIZEBOX
| WS_POPUP
,
4287 rcMain
.left
, rcMain
.top
,
4288 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4292 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4293 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4294 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4295 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4296 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4297 GetWindowRect(hwnd
, &rc
);
4298 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4300 ret
= ShowWindow(hwnd
, SW_SHOW
);
4301 ok(!ret
, "not expected ret: %lu\n", ret
);
4302 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4303 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4304 ok(style
& WS_VISIBLE
, "window should be visible\n");
4305 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4306 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4307 GetWindowRect(hwnd
, &rc
);
4308 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4310 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4311 ok(ret
, "not expected ret: %lu\n", ret
);
4312 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4313 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4314 ok(style
& WS_VISIBLE
, "window should be visible\n");
4315 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4316 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4317 GetWindowRect(hwnd
, &rc
);
4318 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4320 ShowWindow(hwnd
, SW_RESTORE
);
4321 ok(ret
, "not expected ret: %lu\n", ret
);
4322 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4323 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4324 ok(style
& WS_VISIBLE
, "window should be visible\n");
4325 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4326 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4327 GetWindowRect(hwnd
, &rc
);
4328 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4330 ret
= EnableWindow(hwnd
, FALSE
);
4331 ok(!ret
, "not expected ret: %lu\n", ret
);
4332 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4333 ok(style
& WS_DISABLED
, "window should be disabled\n");
4335 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4336 ok(!ret
, "not expected ret: %lu\n", ret
);
4337 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4338 ok(style
& WS_DISABLED
, "window should be disabled\n");
4339 ok(style
& WS_VISIBLE
, "window should be visible\n");
4340 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4341 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4342 GetWindowRect(hwnd
, &rc
);
4343 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4345 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4346 ok(!ret
, "not expected ret: %lu\n", ret
);
4347 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4348 ok(style
& WS_DISABLED
, "window should be disabled\n");
4349 ok(style
& WS_VISIBLE
, "window should be visible\n");
4350 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4351 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4352 GetWindowRect(hwnd
, &rc
);
4353 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4355 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4356 ok(ret
, "not expected ret: %lu\n", ret
);
4357 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4358 ok(style
& WS_DISABLED
, "window should be disabled\n");
4359 ok(style
& WS_VISIBLE
, "window should be visible\n");
4360 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4361 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4362 GetWindowRect(hwnd
, &rc
);
4363 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4365 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4366 ok(!ret
, "not expected ret: %lu\n", ret
);
4367 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4368 ok(style
& WS_DISABLED
, "window should be disabled\n");
4369 ok(style
& WS_VISIBLE
, "window should be visible\n");
4370 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4371 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4372 GetWindowRect(hwnd
, &rc
);
4373 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4375 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4376 ok(ret
, "not expected ret: %lu\n", ret
);
4377 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4378 ok(style
& WS_DISABLED
, "window should be disabled\n");
4379 ok(style
& WS_VISIBLE
, "window should be visible\n");
4380 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4381 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4382 GetWindowRect(hwnd
, &rc
);
4383 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4385 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4386 ok(!ret
, "not expected ret: %lu\n", ret
);
4387 ok(IsWindow(hwnd
), "window should exist\n");
4389 ret
= EnableWindow(hwnd
, TRUE
);
4390 ok(ret
, "not expected ret: %lu\n", ret
);
4392 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4393 ok(!ret
, "not expected ret: %lu\n", ret
);
4394 ok(!IsWindow(hwnd
), "window should not exist\n");
4397 static void test_gettext(void)
4400 LPCSTR clsname
= "gettexttest";
4404 memset( &cls
, 0, sizeof cls
);
4405 cls
.lpfnWndProc
= DefWindowProc
;
4406 cls
.lpszClassName
= clsname
;
4407 cls
.hInstance
= GetModuleHandle(NULL
);
4409 if (!RegisterClass( &cls
)) return;
4411 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4412 ok( hwnd
!= NULL
, "window was null\n");
4414 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4415 ok( r
== 0, "settext should return zero\n");
4417 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4418 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4420 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4421 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4423 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4424 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4426 DestroyWindow(hwnd
);
4427 UnregisterClass( clsname
, NULL
);
4431 static void test_GetUpdateRect(void)
4434 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4436 HWND hgrandparent
, hparent
, hchild
;
4438 static const char classNameA
[] = "GetUpdateRectClass";
4440 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4441 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4443 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4444 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4446 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4447 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4449 ShowWindow(hgrandparent
, SW_SHOW
);
4450 UpdateWindow(hgrandparent
);
4453 ShowWindow(hchild
, SW_HIDE
);
4454 SetRect(&rc2
, 0, 0, 0, 0);
4455 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4456 ok(!ret
, "GetUpdateRect returned not empty region\n");
4457 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4458 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4459 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4461 SetRect(&rc2
, 10, 10, 40, 40);
4462 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4463 ok(ret
, "GetUpdateRect returned empty region\n");
4464 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4465 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4466 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4468 parent_wm_paint
= FALSE
;
4469 grandparent_wm_paint
= FALSE
;
4470 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4472 if (msg
.message
== WM_PAINT
)
4474 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4475 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4477 DispatchMessage(&msg
);
4479 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4480 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4482 DestroyWindow(hgrandparent
);
4485 cls
.lpfnWndProc
= DefWindowProcA
;
4488 cls
.hInstance
= GetModuleHandleA(0);
4490 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4491 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4492 cls
.lpszMenuName
= NULL
;
4493 cls
.lpszClassName
= classNameA
;
4495 if(!RegisterClassA(&cls
)) {
4496 trace("Register failed %d\n", GetLastError());
4500 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4501 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4503 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4504 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4506 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4507 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4509 ShowWindow(hgrandparent
, SW_SHOW
);
4510 UpdateWindow(hgrandparent
);
4513 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4514 ok(!ret
, "GetUpdateRect returned not empty region\n");
4516 ShowWindow(hchild
, SW_HIDE
);
4518 SetRect(&rc2
, 0, 0, 0, 0);
4519 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4520 ok(!ret
, "GetUpdateRect returned not empty region\n");
4521 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4522 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4523 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4525 SetRect(&rc2
, 10, 10, 40, 40);
4526 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4527 ok(ret
, "GetUpdateRect returned empty region\n");
4528 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4529 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4530 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4532 parent_wm_paint
= FALSE
;
4533 grandparent_wm_paint
= FALSE
;
4534 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4536 if (msg
.message
== WM_PAINT
)
4538 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4539 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4541 DispatchMessage(&msg
);
4543 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4544 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4546 DestroyWindow(hgrandparent
);
4551 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4552 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4554 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
4557 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
4560 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
4561 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4562 trace("hwndMessage %p\n", hwndMessage
);
4564 DestroyWindow(hwndMain
);
4567 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4569 if (!RegisterWindowClasses()) assert(0);
4571 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4574 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4575 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4576 WS_MAXIMIZEBOX
| WS_POPUP
,
4578 0, 0, GetModuleHandle(0), NULL
);
4579 test_nonclient_area(hwndMain
);
4581 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4582 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4583 WS_MAXIMIZEBOX
| WS_POPUP
,
4585 0, 0, GetModuleHandle(0), NULL
);
4587 assert( hwndMain2
);
4589 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4591 /* Add the tests below this line */
4596 test_capture_3(hwndMain
, hwndMain2
);
4598 test_CreateWindow();
4599 test_parent_owner();
4601 test_shell_window();
4605 test_SetWindowPos(hwndMain
);
4606 test_SetMenu(hwndMain
);
4607 test_SetFocus(hwndMain
);
4608 test_SetActiveWindow(hwndMain
);
4609 test_SetForegroundWindow(hwndMain
);
4611 test_children_zorder(hwndMain
);
4612 test_popup_zorder(hwndMain2
, hwndMain
);
4613 test_keyboard_input(hwndMain
);
4614 test_mouse_input(hwndMain
);
4615 test_validatergn(hwndMain
);
4616 test_nccalcscroll( hwndMain
);
4617 test_scrollvalidate( hwndMain
);
4618 test_scrolldc( hwndMain
);
4620 test_IsWindowUnicode();
4621 test_vis_rgn(hwndMain
);
4623 test_AdjustWindowRect();
4624 test_window_styles();
4627 test_SetWindowLong();
4630 test_GetUpdateRect();
4632 /* add the tests above this line */
4633 UnhookWindowsHookEx(hhook
);