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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 void dump_region(HRGN hrgn);
50 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
51 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
53 static BOOL test_lbuttondown_flag;
54 static HWND hwndMessage;
55 static HWND hwndMain, hwndMain2;
58 static const char* szAWRClass = "Winsize";
61 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
63 /* try to make sure pending X events have been processed before continuing */
64 static void flush_events(void)
68 DWORD time = GetTickCount() + diff;
72 MsgWaitForMultipleObjects( 0, NULL, FALSE, diff, QS_ALLINPUT );
73 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
74 diff = time - GetTickCount();
78 /* check the values returned by the various parent/owner functions on a given window */
79 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
80 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
86 res = pGetAncestor( hwnd, GA_PARENT );
87 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
89 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
90 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
91 res = GetParent( hwnd );
92 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
93 res = GetWindow( hwnd, GW_OWNER );
94 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
97 res = pGetAncestor( hwnd, GA_ROOT );
98 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
99 res = pGetAncestor( hwnd, GA_ROOTOWNER );
100 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
104 BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
107 trace("EnumChildProc on %p\n", hwndChild);
108 if (*(LPINT)lParam > 1) return FALSE;
112 /* will search for the given window */
113 BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
115 trace("EnumChildProc1 on %p\n", hwndChild);
116 if ((HWND)lParam == hwndChild) return FALSE;
120 static HWND create_tool_window( LONG style, HWND parent )
122 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
123 0, 0, 100, 100, parent, 0, 0, NULL );
124 ok( ret != 0, "Creation failed\n" );
128 /* test parent and owner values for various combinations */
129 static void test_parent_owner(void)
132 HWND test, owner, ret;
133 HWND desktop = GetDesktopWindow();
134 HWND child = create_tool_window( WS_CHILD, hwndMain );
137 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
139 /* child without parent, should fail */
140 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
141 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
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 );
323 #if 0 /* this test succeeds on NT but crashes on win9x systems */
324 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
325 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
326 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
327 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
328 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
330 /* normal child window */
331 test = create_tool_window( WS_CHILD, hwndMain );
332 trace( "created child %p\n", test );
334 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
335 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
336 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
338 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
339 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
340 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
342 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
343 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
344 check_parents( test, desktop, 0, desktop, 0, test, desktop );
346 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
347 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
348 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
349 check_parents( test, desktop, child, desktop, child, test, desktop );
351 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
352 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
353 check_parents( test, desktop, 0, desktop, 0, test, desktop );
354 DestroyWindow( test );
356 /* not owned top-level window */
357 test = create_tool_window( 0, 0 );
358 trace( "created top-level %p\n", test );
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
361 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
362 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
365 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
366 check_parents( test, desktop, child, 0, child, test, test );
368 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
369 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
370 check_parents( test, desktop, 0, 0, 0, test, test );
371 DestroyWindow( test );
373 /* not owned popup */
374 test = create_tool_window( WS_POPUP, 0 );
375 trace( "created popup %p\n", test );
377 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
378 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
379 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
381 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
382 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
383 check_parents( test, desktop, child, child, child, test, hwndMain );
385 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
386 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
387 check_parents( test, desktop, 0, 0, 0, test, test );
388 DestroyWindow( test );
390 /* normal child window */
391 test = create_tool_window( WS_CHILD, hwndMain );
392 trace( "created child %p\n", test );
394 ret = SetParent( test, desktop );
395 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
396 check_parents( test, desktop, 0, desktop, 0, test, desktop );
398 ret = SetParent( test, child );
399 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
400 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
402 ret = SetParent( test, hwndMain2 );
403 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
404 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
405 DestroyWindow( test );
407 /* not owned top-level window */
408 test = create_tool_window( 0, 0 );
409 trace( "created top-level %p\n", test );
411 ret = SetParent( test, child );
412 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
413 check_parents( test, child, child, 0, 0, hwndMain, test );
414 DestroyWindow( test );
417 test = create_tool_window( WS_POPUP, hwndMain2 );
418 trace( "created owned popup %p\n", test );
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
424 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
425 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
426 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
427 DestroyWindow( test );
429 /**************** test owner destruction *******************/
431 /* owned child popup */
432 owner = create_tool_window( 0, 0 );
433 test = create_tool_window( WS_POPUP, owner );
434 trace( "created owner %p and popup %p\n", owner, test );
435 ret = SetParent( test, child );
436 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
437 check_parents( test, child, child, owner, owner, hwndMain, owner );
438 /* window is now child of 'child' but owned by 'owner' */
439 DestroyWindow( owner );
440 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
441 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
442 * while Win95, Win2k, WinXP do.
444 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
445 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
448 /* owned top-level popup */
449 owner = create_tool_window( 0, 0 );
450 test = create_tool_window( WS_POPUP, owner );
451 trace( "created owner %p and popup %p\n", owner, test );
452 check_parents( test, desktop, owner, owner, owner, test, owner );
453 DestroyWindow( owner );
454 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
456 /* top-level popup owned by child */
457 owner = create_tool_window( WS_CHILD, hwndMain2 );
458 test = create_tool_window( WS_POPUP, 0 );
459 trace( "created owner %p and popup %p\n", owner, test );
460 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
461 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
462 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
463 DestroyWindow( owner );
464 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
465 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
466 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
467 * while Win95, Win2k, WinXP do.
469 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
473 DestroyWindow(child);
476 owner = create_tool_window( WS_OVERLAPPED, 0 );
477 test = create_tool_window( WS_POPUP, desktop );
479 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
481 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
482 "EnumChildWindows should have returned FALSE\n" );
483 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
485 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
486 ret = SetParent( test, owner );
487 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
490 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
491 "EnumChildWindows should have returned TRUE\n" );
492 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
494 child = create_tool_window( WS_CHILD, owner );
496 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
497 "EnumChildWindows should have returned FALSE\n" );
498 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
499 DestroyWindow( child );
501 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
502 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
504 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
505 "EnumChildWindows should have returned TRUE\n" );
506 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
508 ret = SetParent( child, owner );
509 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
510 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
512 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned FALSE\n" );
514 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
516 ret = SetParent( child, NULL );
517 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
518 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
520 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
521 "EnumChildWindows should have returned TRUE\n" );
522 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
524 /* even GW_OWNER == owner it's still a desktop's child */
525 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
526 "EnumChildWindows should have found %p and returned FALSE\n", child );
528 DestroyWindow( child );
529 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
531 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
532 "EnumChildWindows should have found %p and returned FALSE\n", child );
534 DestroyWindow( child );
535 DestroyWindow( test );
536 DestroyWindow( owner );
540 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
544 case WM_GETMINMAXINFO:
546 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
548 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
549 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
550 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
551 minmax->ptReserved.x, minmax->ptReserved.y,
552 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
553 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
554 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
555 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
556 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
559 case WM_WINDOWPOSCHANGING:
561 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
562 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
563 trace("main: WM_WINDOWPOSCHANGING\n");
564 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
565 winpos->hwnd, winpos->hwndInsertAfter,
566 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
567 if (!(winpos->flags & SWP_NOMOVE))
569 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
570 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
572 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
573 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
575 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
576 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
580 case WM_WINDOWPOSCHANGED:
583 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
584 trace("main: WM_WINDOWPOSCHANGED\n");
585 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
586 winpos->hwnd, winpos->hwndInsertAfter,
587 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
588 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
589 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
591 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
592 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
594 GetWindowRect(hwnd, &rc1);
595 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
596 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
597 /* note: winpos coordinates are relative to parent */
598 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
599 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
600 #if 0 /* Uncomment this once the test succeeds in all cases */
601 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
604 GetClientRect(hwnd, &rc2);
605 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
606 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
607 ok(EqualRect(&rc1, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
608 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
613 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
614 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
616 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
617 if (got_getminmaxinfo)
618 trace("%p got WM_GETMINMAXINFO\n", hwnd);
620 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
621 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
623 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
627 if (test_lbuttondown_flag)
628 ShowWindow((HWND)wparam, SW_SHOW);
632 return DefWindowProcA(hwnd, msg, wparam, lparam);
635 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
639 case WM_GETMINMAXINFO:
641 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
643 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
644 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
645 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
646 minmax->ptReserved.x, minmax->ptReserved.y,
647 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
648 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
649 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
650 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
651 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
656 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
657 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
659 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
660 if (got_getminmaxinfo)
661 trace("%p got WM_GETMINMAXINFO\n", hwnd);
663 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
664 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
666 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
671 return DefWindowProcA(hwnd, msg, wparam, lparam);
674 static BOOL RegisterWindowClasses(void)
678 cls.style = CS_DBLCLKS;
679 cls.lpfnWndProc = main_window_procA;
682 cls.hInstance = GetModuleHandleA(0);
684 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
685 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
686 cls.lpszMenuName = NULL;
687 cls.lpszClassName = "MainWindowClass";
689 if(!RegisterClassA(&cls)) return FALSE;
692 cls.lpfnWndProc = tool_window_procA;
695 cls.hInstance = GetModuleHandleA(0);
697 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
698 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
699 cls.lpszMenuName = NULL;
700 cls.lpszClassName = "ToolWindowClass";
702 if(!RegisterClassA(&cls)) return FALSE;
707 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
709 RECT rcWindow, rcClient;
713 ok(IsWindow(hwnd), "bad window handle\n");
715 GetWindowRect(hwnd, &rcWindow);
716 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
718 GetClientRect(hwnd, &rcClient);
719 /* translate to screen coordinates */
720 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
721 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
723 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
724 "wrong dwStyle: %08lx != %08lx\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
725 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
726 "wrong dwExStyle: %08lx != %08lx\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
727 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
728 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04lx != %04lx\n",
729 info->dwWindowStatus, status);
731 if (test_borders && !IsRectEmpty(&rcWindow))
733 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
734 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
736 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
737 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
738 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
739 ok(info->cyWindowBorders == border,
740 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
743 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
744 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
747 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
749 AdjustWindowRectEx(rc, style, menu, exstyle);
750 /* AdjustWindowRectEx does not include scroll bars */
751 if (style & WS_VSCROLL)
753 if(exstyle & WS_EX_LEFTSCROLLBAR)
754 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
756 rc->right += GetSystemMetrics(SM_CXVSCROLL);
758 if (style & WS_HSCROLL)
759 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
762 static void test_nonclient_area(HWND hwnd)
764 DWORD style, exstyle;
765 RECT rc_window, rc_client, rc;
767 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
769 style = GetWindowLongA(hwnd, GWL_STYLE);
770 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
771 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
773 GetWindowRect(hwnd, &rc_window);
774 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
775 GetClientRect(hwnd, &rc_client);
776 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
778 /* avoid some cases when things go wrong */
779 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
780 rc_window.right > 32768 || rc_window.bottom > 32768) return;
782 CopyRect(&rc, &rc_client);
783 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
784 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
786 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
787 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
790 CopyRect(&rc, &rc_window);
791 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
792 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
793 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
794 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
796 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
800 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
801 SetRect(&rc_client, 0, 0, 250, 150);
802 CopyRect(&rc_window, &rc_client);
803 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
804 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
805 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
806 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
808 CopyRect(&rc, &rc_window);
809 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
810 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
811 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
812 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
815 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
817 static const char *CBT_code_name[10] = {
828 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
830 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
832 /* on HCBT_DESTROYWND window state is undefined */
833 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
839 /* Win98 actually does check the info.cbSize and doesn't allow
840 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
841 * WinXP do not check it at all.
843 info.cbSize = sizeof(WINDOWINFO);
844 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
845 /* win2k SP4 returns broken border info if GetWindowInfo
846 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
848 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
856 #if 0 /* Uncomment this once the test succeeds in all cases */
857 static const RECT rc_null;
861 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
862 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
863 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
864 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
866 /* WS_VISIBLE should be turned off yet */
867 style = createwnd->lpcs->style & ~WS_VISIBLE;
868 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
869 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
870 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
872 #if 0 /* Uncomment this once the test succeeds in all cases */
873 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
875 ok(GetParent((HWND)wParam) == hwndMessage,
876 "wrong result from GetParent %p: message window %p\n",
877 GetParent((HWND)wParam), hwndMessage);
880 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
882 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
884 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
885 * Win9x still has them set to 0.
887 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
888 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
890 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
891 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
893 #if 0 /* Uncomment this once the test succeeds in all cases */
896 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
897 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
898 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
900 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
901 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
902 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
904 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
905 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
908 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
909 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
910 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
911 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
917 return CallNextHookEx(hhook, nCode, wParam, lParam);
920 static void test_shell_window(void)
924 HMODULE hinst, hUser32;
925 BOOL (WINAPI*SetShellWindow)(HWND);
926 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
927 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
928 HWND shellWindow, nextWnd;
930 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
932 trace("Skipping shell window test on Win9x\n");
936 shellWindow = GetShellWindow();
937 hinst = GetModuleHandle(0);
938 hUser32 = GetModuleHandleA("user32");
940 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
941 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
943 trace("previous shell window: %p\n", shellWindow);
949 ret = DestroyWindow(shellWindow);
950 error = GetLastError();
952 ok(!ret, "DestroyWindow(shellWindow)\n");
953 /* passes on Win XP, but not on Win98 */
954 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
956 /* close old shell instance */
957 GetWindowThreadProcessId(shellWindow, &pid);
958 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
959 ret = TerminateProcess(hProcess, 0);
960 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
961 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
962 CloseHandle(hProcess);
965 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
966 trace("created window 1: %p\n", hwnd1);
968 ret = SetShellWindow(hwnd1);
969 ok(ret, "first call to SetShellWindow(hwnd1)\n");
970 shellWindow = GetShellWindow();
971 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
973 ret = SetShellWindow(hwnd1);
974 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
976 ret = SetShellWindow(0);
977 error = GetLastError();
978 /* passes on Win XP, but not on Win98
979 ok(!ret, "reset shell window by SetShellWindow(0)\n");
980 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
982 ret = SetShellWindow(hwnd1);
983 /* passes on Win XP, but not on Win98
984 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
988 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
989 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
990 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
993 ret = DestroyWindow(hwnd1);
994 ok(ret, "DestroyWindow(hwnd1)\n");
996 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
997 trace("created window 2: %p\n", hwnd2);
998 ret = SetShellWindow(hwnd2);
999 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1001 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1002 trace("created window 3: %p\n", hwnd3);
1004 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1005 trace("created window 4: %p\n", hwnd4);
1007 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1008 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1010 ret = SetShellWindow(hwnd4);
1011 ok(ret, "SetShellWindow(hwnd4)\n");
1012 shellWindow = GetShellWindow();
1013 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1015 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1016 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1018 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1019 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1021 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1022 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1024 ret = SetShellWindow(hwnd3);
1025 ok(!ret, "SetShellWindow(hwnd3)\n");
1026 shellWindow = GetShellWindow();
1027 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1029 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1030 trace("created window 5: %p\n", hwnd5);
1031 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1032 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1036 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1037 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1040 /* destroy test windows */
1041 DestroyWindow(hwnd2);
1042 DestroyWindow(hwnd3);
1043 DestroyWindow(hwnd4);
1044 DestroyWindow(hwnd5);
1047 /************** MDI test ****************/
1049 static const char mdi_lParam_test_message[] = "just a test string";
1051 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1053 MDICREATESTRUCTA mdi_cs;
1055 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1056 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1057 BOOL isWin9x = FALSE;
1059 mdi_cs.szClass = "MDI_child_Class_1";
1060 mdi_cs.szTitle = "MDI child";
1061 mdi_cs.hOwner = GetModuleHandle(0);
1062 mdi_cs.x = CW_USEDEFAULT;
1063 mdi_cs.y = CW_USEDEFAULT;
1064 mdi_cs.cx = CW_USEDEFAULT;
1065 mdi_cs.cy = CW_USEDEFAULT;
1067 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1068 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1069 ok(mdi_child != 0, "MDI child creation failed\n");
1070 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1071 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1072 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1074 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1075 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1076 ok(mdi_child != 0, "MDI child creation failed\n");
1077 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1078 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1079 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1081 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1082 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1083 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1085 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1089 ok(mdi_child != 0, "MDI child creation failed\n");
1090 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1091 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1092 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1095 /* test MDICREATESTRUCT A<->W mapping */
1096 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1098 mdi_cs.szClass = (LPCSTR)classW;
1099 mdi_cs.szTitle = (LPCSTR)titleW;
1100 SetLastError(0xdeadbeef);
1101 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1104 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1107 ok(mdi_child != 0, "MDI child creation failed\n");
1111 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1112 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1113 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1116 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1118 CW_USEDEFAULT, CW_USEDEFAULT,
1119 CW_USEDEFAULT, CW_USEDEFAULT,
1120 mdi_client, GetModuleHandle(0),
1121 (LPARAM)mdi_lParam_test_message);
1122 ok(mdi_child != 0, "MDI child creation failed\n");
1123 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1124 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1125 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1127 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1128 0x7fffffff, /* without WS_POPUP */
1129 CW_USEDEFAULT, CW_USEDEFAULT,
1130 CW_USEDEFAULT, CW_USEDEFAULT,
1131 mdi_client, GetModuleHandle(0),
1132 (LPARAM)mdi_lParam_test_message);
1133 ok(mdi_child != 0, "MDI child creation failed\n");
1134 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1135 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1136 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1138 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1139 0xffffffff, /* with WS_POPUP */
1140 CW_USEDEFAULT, CW_USEDEFAULT,
1141 CW_USEDEFAULT, CW_USEDEFAULT,
1142 mdi_client, GetModuleHandle(0),
1143 (LPARAM)mdi_lParam_test_message);
1144 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1146 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1150 ok(mdi_child != 0, "MDI child creation failed\n");
1151 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1152 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1153 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1156 /* test MDICREATESTRUCT A<->W mapping */
1157 SetLastError(0xdeadbeef);
1158 mdi_child = CreateMDIWindowW(classW, titleW,
1160 CW_USEDEFAULT, CW_USEDEFAULT,
1161 CW_USEDEFAULT, CW_USEDEFAULT,
1162 mdi_client, GetModuleHandle(0),
1163 (LPARAM)mdi_lParam_test_message);
1166 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1169 ok(mdi_child != 0, "MDI child creation failed\n");
1173 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1174 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1175 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1178 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1180 CW_USEDEFAULT, CW_USEDEFAULT,
1181 CW_USEDEFAULT, CW_USEDEFAULT,
1182 mdi_client, 0, GetModuleHandle(0),
1183 (LPVOID)mdi_lParam_test_message);
1184 ok(mdi_child != 0, "MDI child creation failed\n");
1185 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1186 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1187 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1189 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1190 0x7fffffff, /* without WS_POPUP */
1191 CW_USEDEFAULT, CW_USEDEFAULT,
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 mdi_client, 0, GetModuleHandle(0),
1194 (LPVOID)mdi_lParam_test_message);
1195 ok(mdi_child != 0, "MDI child creation failed\n");
1196 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1197 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1198 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1200 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1201 0xffffffff, /* with WS_POPUP */
1202 CW_USEDEFAULT, CW_USEDEFAULT,
1203 CW_USEDEFAULT, CW_USEDEFAULT,
1204 mdi_client, 0, GetModuleHandle(0),
1205 (LPVOID)mdi_lParam_test_message);
1206 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1208 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1212 ok(mdi_child != 0, "MDI child creation failed\n");
1213 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1214 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1215 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1218 /* test MDICREATESTRUCT A<->W mapping */
1219 SetLastError(0xdeadbeef);
1220 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1222 CW_USEDEFAULT, CW_USEDEFAULT,
1223 CW_USEDEFAULT, CW_USEDEFAULT,
1224 mdi_client, 0, GetModuleHandle(0),
1225 (LPVOID)mdi_lParam_test_message);
1228 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1231 ok(mdi_child != 0, "MDI child creation failed\n");
1235 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1236 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1237 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1240 /* This test fails on Win9x */
1243 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1245 CW_USEDEFAULT, CW_USEDEFAULT,
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 parent, 0, GetModuleHandle(0),
1248 (LPVOID)mdi_lParam_test_message);
1249 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1252 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1253 WS_CHILD, /* without WS_POPUP */
1254 CW_USEDEFAULT, CW_USEDEFAULT,
1255 CW_USEDEFAULT, CW_USEDEFAULT,
1256 mdi_client, 0, GetModuleHandle(0),
1257 (LPVOID)mdi_lParam_test_message);
1258 ok(mdi_child != 0, "MDI child creation failed\n");
1259 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1260 DestroyWindow(mdi_child);
1262 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1263 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1264 CW_USEDEFAULT, CW_USEDEFAULT,
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1266 mdi_client, 0, GetModuleHandle(0),
1267 (LPVOID)mdi_lParam_test_message);
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1270 DestroyWindow(mdi_child);
1272 /* maximized child */
1273 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1274 WS_CHILD | WS_MAXIMIZE,
1275 CW_USEDEFAULT, CW_USEDEFAULT,
1276 CW_USEDEFAULT, CW_USEDEFAULT,
1277 mdi_client, 0, GetModuleHandle(0),
1278 (LPVOID)mdi_lParam_test_message);
1279 ok(mdi_child != 0, "MDI child creation failed\n");
1280 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1281 DestroyWindow(mdi_child);
1283 trace("Creating maximized child with a caption\n");
1284 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1285 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 CW_USEDEFAULT, CW_USEDEFAULT,
1288 mdi_client, 0, GetModuleHandle(0),
1289 (LPVOID)mdi_lParam_test_message);
1290 ok(mdi_child != 0, "MDI child creation failed\n");
1291 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1292 DestroyWindow(mdi_child);
1294 trace("Creating maximized child with a caption and a thick frame\n");
1295 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1296 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1297 CW_USEDEFAULT, CW_USEDEFAULT,
1298 CW_USEDEFAULT, CW_USEDEFAULT,
1299 mdi_client, 0, GetModuleHandle(0),
1300 (LPVOID)mdi_lParam_test_message);
1301 ok(mdi_child != 0, "MDI child creation failed\n");
1302 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1303 DestroyWindow(mdi_child);
1306 /**********************************************************************
1307 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1309 * Note: The rule here is that client rect of the maximized MDI child
1310 * is equal to the client rect of the MDI client window.
1312 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1316 GetClientRect( client, &rect );
1317 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1318 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1320 rect.right -= rect.left;
1321 rect.bottom -= rect.top;
1322 lpMinMax->ptMaxSize.x = rect.right;
1323 lpMinMax->ptMaxSize.y = rect.bottom;
1325 lpMinMax->ptMaxPosition.x = rect.left;
1326 lpMinMax->ptMaxPosition.y = rect.top;
1328 trace("max rect (%ld,%ld - %ld, %ld)\n",
1329 rect.left, rect.top, rect.right, rect.bottom);
1332 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1339 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1340 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1342 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1343 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1345 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1346 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1347 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1348 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1349 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1351 /* MDICREATESTRUCT should have original values */
1352 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1353 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1354 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1355 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1356 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1357 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1359 /* CREATESTRUCT should have fixed values */
1360 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1361 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1363 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1364 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1365 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1367 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1369 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1371 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1372 ok(cs->style == style,
1373 "cs->style does not match (%08lx)\n", cs->style);
1377 LONG style = mdi_cs->style;
1379 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1380 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1381 ok(cs->style == style,
1382 "cs->style does not match (%08lx)\n", cs->style);
1387 case WM_GETMINMAXINFO:
1389 HWND client = GetParent(hwnd);
1391 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1392 MINMAXINFO my_minmax;
1393 LONG style, exstyle;
1395 style = GetWindowLongA(hwnd, GWL_STYLE);
1396 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1398 GetWindowRect(client, &rc);
1399 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1400 GetClientRect(client, &rc);
1401 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1402 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1403 GetSystemMetrics(SM_CYSCREEN));
1405 GetClientRect(client, &rc);
1406 if ((style & WS_CAPTION) == WS_CAPTION)
1407 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1408 AdjustWindowRectEx(&rc, style, 0, exstyle);
1409 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1411 trace("ptReserved = (%ld,%ld)\n"
1412 "ptMaxSize = (%ld,%ld)\n"
1413 "ptMaxPosition = (%ld,%ld)\n"
1414 "ptMinTrackSize = (%ld,%ld)\n"
1415 "ptMaxTrackSize = (%ld,%ld)\n",
1416 minmax->ptReserved.x, minmax->ptReserved.y,
1417 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1418 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1419 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1420 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1422 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1423 minmax->ptMaxSize.x, rc.right - rc.left);
1424 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1425 minmax->ptMaxSize.y, rc.bottom - rc.top);
1427 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1429 trace("DefMDIChildProc returned:\n"
1430 "ptReserved = (%ld,%ld)\n"
1431 "ptMaxSize = (%ld,%ld)\n"
1432 "ptMaxPosition = (%ld,%ld)\n"
1433 "ptMinTrackSize = (%ld,%ld)\n"
1434 "ptMaxTrackSize = (%ld,%ld)\n",
1435 minmax->ptReserved.x, minmax->ptReserved.y,
1436 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1437 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1438 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1439 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1441 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1442 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1443 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1444 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1445 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1450 case WM_MDIACTIVATE:
1452 HWND active, client = GetParent(hwnd);
1453 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1454 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1455 if (hwnd == (HWND)lparam) /* if we are being activated */
1456 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1458 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1462 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1465 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1472 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1474 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1475 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1477 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1478 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1480 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1481 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1483 /* CREATESTRUCT should have fixed values */
1484 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1486 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1487 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1489 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1490 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1491 while Win95, Win2k, WinXP do. */
1492 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1493 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1497 case WM_GETMINMAXINFO:
1499 HWND parent = GetParent(hwnd);
1501 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1502 LONG style, exstyle;
1504 trace("WM_GETMINMAXINFO\n");
1506 style = GetWindowLongA(hwnd, GWL_STYLE);
1507 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1509 GetClientRect(parent, &rc);
1510 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1512 GetClientRect(parent, &rc);
1513 if ((style & WS_CAPTION) == WS_CAPTION)
1514 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1515 AdjustWindowRectEx(&rc, style, 0, exstyle);
1516 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1518 trace("ptReserved = (%ld,%ld)\n"
1519 "ptMaxSize = (%ld,%ld)\n"
1520 "ptMaxPosition = (%ld,%ld)\n"
1521 "ptMinTrackSize = (%ld,%ld)\n"
1522 "ptMaxTrackSize = (%ld,%ld)\n",
1523 minmax->ptReserved.x, minmax->ptReserved.y,
1524 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1525 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1526 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1527 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1529 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1530 minmax->ptMaxSize.x, rc.right - rc.left);
1531 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1532 minmax->ptMaxSize.y, rc.bottom - rc.top);
1536 case WM_WINDOWPOSCHANGED:
1538 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1541 GetWindowRect(hwnd, &rc1);
1542 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1543 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1544 /* note: winpos coordinates are relative to parent */
1545 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1546 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1547 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1549 GetWindowRect(hwnd, &rc1);
1550 GetClientRect(hwnd, &rc2);
1551 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1552 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1553 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1556 case WM_WINDOWPOSCHANGING:
1558 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1559 WINDOWPOS my_winpos = *winpos;
1561 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1562 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1563 winpos->hwnd, winpos->hwndInsertAfter,
1564 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1566 DefWindowProcA(hwnd, msg, wparam, lparam);
1568 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1569 winpos->hwnd, winpos->hwndInsertAfter,
1570 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1572 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1573 "DefWindowProc should not change WINDOWPOS values\n");
1578 return DefWindowProcA(hwnd, msg, wparam, lparam);
1581 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1583 static HWND mdi_client;
1589 CLIENTCREATESTRUCT client_cs;
1592 GetClientRect(hwnd, &rc);
1594 client_cs.hWindowMenu = 0;
1595 client_cs.idFirstChild = 1;
1597 /* MDIClient without MDIS_ALLCHILDSTYLES */
1598 mdi_client = CreateWindowExA(0, "mdiclient",
1600 WS_CHILD /*| WS_VISIBLE*/,
1601 /* tests depend on a not zero MDIClient size */
1602 0, 0, rc.right, rc.bottom,
1603 hwnd, 0, GetModuleHandle(0),
1604 (LPVOID)&client_cs);
1606 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1607 DestroyWindow(mdi_client);
1609 /* MDIClient with MDIS_ALLCHILDSTYLES */
1610 mdi_client = CreateWindowExA(0, "mdiclient",
1612 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1613 /* tests depend on a not zero MDIClient size */
1614 0, 0, rc.right, rc.bottom,
1615 hwnd, 0, GetModuleHandle(0),
1616 (LPVOID)&client_cs);
1618 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1619 DestroyWindow(mdi_client);
1623 case WM_WINDOWPOSCHANGED:
1625 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1628 GetWindowRect(hwnd, &rc1);
1629 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1630 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1631 /* note: winpos coordinates are relative to parent */
1632 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1633 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1634 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1636 GetWindowRect(hwnd, &rc1);
1637 GetClientRect(hwnd, &rc2);
1638 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1639 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1640 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1643 case WM_WINDOWPOSCHANGING:
1645 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1646 WINDOWPOS my_winpos = *winpos;
1648 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1649 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1650 winpos->hwnd, winpos->hwndInsertAfter,
1651 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1653 DefWindowProcA(hwnd, msg, wparam, lparam);
1655 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1656 winpos->hwnd, winpos->hwndInsertAfter,
1657 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1659 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1660 "DefWindowProc should not change WINDOWPOS values\n");
1669 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1672 static BOOL mdi_RegisterWindowClasses(void)
1677 cls.lpfnWndProc = mdi_main_wnd_procA;
1680 cls.hInstance = GetModuleHandleA(0);
1682 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1683 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1684 cls.lpszMenuName = NULL;
1685 cls.lpszClassName = "MDI_parent_Class";
1686 if(!RegisterClassA(&cls)) return FALSE;
1688 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1689 cls.lpszClassName = "MDI_child_Class_1";
1690 if(!RegisterClassA(&cls)) return FALSE;
1692 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1693 cls.lpszClassName = "MDI_child_Class_2";
1694 if(!RegisterClassA(&cls)) return FALSE;
1699 static void test_mdi(void)
1704 if (!mdi_RegisterWindowClasses()) assert(0);
1706 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1707 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1708 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1709 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1710 GetDesktopWindow(), 0,
1711 GetModuleHandle(0), NULL);
1712 assert(mdi_hwndMain);
1714 while(GetMessage(&msg, 0, 0, 0))
1716 TranslateMessage(&msg);
1717 DispatchMessage(&msg);
1722 static void test_icons(void)
1726 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1727 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1728 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1729 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1732 cls.cbSize = sizeof(cls);
1734 cls.lpfnWndProc = DefWindowProcA;
1738 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1739 cls.hIconSm = small_icon;
1740 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1741 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1742 cls.lpszMenuName = NULL;
1743 cls.lpszClassName = "IconWindowClass";
1745 RegisterClassExA(&cls);
1747 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1748 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1751 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1752 ok( res == 0, "wrong big icon %p/0\n", res );
1753 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1754 ok( res == 0, "wrong previous big icon %p/0\n", res );
1755 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1756 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1757 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1758 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1759 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1760 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1762 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1763 ok( res == 0, "wrong small icon %p/0\n", res );
1764 /* this test is XP specific */
1765 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1766 ok( res != 0, "wrong small icon %p\n", res );*/
1767 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1768 ok( res == 0, "wrong previous small icon %p/0\n", res );
1769 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1770 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1771 /* this test is XP specific */
1772 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1773 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1774 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1775 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1776 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1777 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1778 /* this test is XP specific */
1779 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1780 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1782 /* make sure the big icon hasn't changed */
1783 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1784 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1787 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1789 if (msg == WM_NCCALCSIZE)
1791 RECT *rect = (RECT *)lparam;
1792 /* first time around increase the rectangle, next time decrease it */
1793 if (rect->left == 100) InflateRect( rect, 10, 10 );
1794 else InflateRect( rect, -10, -10 );
1797 return DefWindowProc( hwnd, msg, wparam, lparam );
1800 static void test_SetWindowPos(HWND hwnd)
1802 RECT orig_win_rc, rect;
1804 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1806 SetRect(&rect, 111, 222, 333, 444);
1807 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1808 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1809 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1811 SetRect(&rect, 111, 222, 333, 444);
1812 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1813 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1814 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1816 GetWindowRect(hwnd, &orig_win_rc);
1818 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1819 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1820 GetWindowRect( hwnd, &rect );
1821 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1822 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1823 GetClientRect( hwnd, &rect );
1824 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1825 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1826 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1828 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1829 GetWindowRect( hwnd, &rect );
1830 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1831 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1832 GetClientRect( hwnd, &rect );
1833 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1834 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1835 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1837 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1838 orig_win_rc.right, orig_win_rc.bottom, 0);
1839 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1841 /* Win9x truncates coordinates to 16-bit irrespectively */
1844 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1845 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1847 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1848 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1851 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1852 orig_win_rc.right, orig_win_rc.bottom, 0);
1855 static void test_SetMenu(HWND parent)
1859 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1863 hMenu = CreateMenu();
1866 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1868 /* fails on (at least) Wine, NT4, XP SP2 */
1869 test_nonclient_area(parent);
1871 ret = GetMenu(parent);
1872 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1873 /* test whether we can destroy a menu assigned to a window */
1874 retok = DestroyMenu(hMenu);
1875 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1876 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1877 ret = GetMenu(parent);
1878 /* This test fails on Win9x */
1880 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1881 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1882 test_nonclient_area(parent);
1884 hMenu = CreateMenu();
1888 ret = GetMenu(parent);
1889 ok(ret == 0, "unexpected menu id %p\n", ret);
1891 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1892 test_nonclient_area(parent);
1893 ret = GetMenu(parent);
1894 ok(ret == 0, "unexpected menu id %p\n", ret);
1896 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1898 /* fails on (at least) Wine, NT4, XP SP2 */
1899 test_nonclient_area(parent);
1901 ret = GetMenu(parent);
1902 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1904 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1905 test_nonclient_area(parent);
1906 ret = GetMenu(parent);
1907 ok(ret == 0, "unexpected menu id %p\n", ret);
1910 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1913 ret = GetMenu(child);
1914 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1916 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1917 test_nonclient_area(child);
1918 ret = GetMenu(child);
1919 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1921 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1922 test_nonclient_area(child);
1923 ret = GetMenu(child);
1924 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1926 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1927 test_nonclient_area(child);
1928 ret = GetMenu(child);
1929 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1931 style = GetWindowLong(child, GWL_STYLE);
1932 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1933 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1934 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1935 SetWindowLong(child, GWL_STYLE, style);
1937 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1938 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1939 SetWindowLong(child, GWL_STYLE, style);
1941 DestroyWindow(child);
1945 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1947 HWND child[5], hwnd;
1952 hwnd = GetWindow(parent, GW_CHILD);
1953 ok(!hwnd, "have to start without children to perform the test\n");
1955 for (i = 0; i < total; i++)
1957 if (style[i] & DS_CONTROL)
1959 child[i] = CreateWindowExA(0, MAKEINTATOMA(32770), "", style[i] & ~WS_VISIBLE,
1960 0,0,0,0, parent, (HMENU)i, 0, NULL);
1961 if (style[i] & WS_VISIBLE)
1962 ShowWindow(child[i], SW_SHOW);
1964 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1967 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1968 parent, (HMENU)i, 0, NULL);
1969 trace("child[%d] = %p\n", i, child[i]);
1970 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1973 hwnd = GetWindow(parent, GW_CHILD);
1974 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1975 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1976 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1978 for (i = 0; i < total; i++)
1980 trace("hwnd[%d] = %p\n", i, hwnd);
1981 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1983 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1986 for (i = 0; i < total; i++)
1987 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1990 static void test_children_zorder(HWND parent)
1992 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1994 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1996 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1997 WS_CHILD | WS_VISIBLE, WS_CHILD,
1998 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1999 const int complex_order_1[1] = { 0 };
2000 const int complex_order_2[2] = { 1, 0 };
2001 const int complex_order_3[3] = { 1, 0, 2 };
2002 const int complex_order_4[4] = { 1, 0, 2, 3 };
2003 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2004 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2005 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2006 WS_CHILD | WS_VISIBLE };
2007 const int complex_order_6[3] = { 0, 1, 2 };
2009 /* simple WS_CHILD */
2010 test_window_tree(parent, simple_style, simple_order, 5);
2012 /* complex children styles */
2013 test_window_tree(parent, complex_style, complex_order_1, 1);
2014 test_window_tree(parent, complex_style, complex_order_2, 2);
2015 test_window_tree(parent, complex_style, complex_order_3, 3);
2016 test_window_tree(parent, complex_style, complex_order_4, 4);
2017 test_window_tree(parent, complex_style, complex_order_5, 5);
2019 /* another set of complex children styles */
2020 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2023 static void test_vis_rgn( HWND hwnd )
2025 RECT win_rect, rgn_rect;
2026 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2029 ShowWindow(hwnd,SW_SHOW);
2030 hdc = GetDC( hwnd );
2031 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2032 GetWindowRect( hwnd, &win_rect );
2033 GetRgnBox( hrgn, &rgn_rect );
2034 if (GetVersion() & 0x80000000)
2036 trace("win9x, mapping to screen coords\n");
2037 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2039 trace("win: %ld,%ld-%ld,%ld\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2040 trace("rgn: %ld,%ld-%ld,%ld\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2041 ok( win_rect.left <= rgn_rect.left, "rgn left %ld not inside win rect %ld\n",
2042 rgn_rect.left, win_rect.left );
2043 ok( win_rect.top <= rgn_rect.top, "rgn top %ld not inside win rect %ld\n",
2044 rgn_rect.top, win_rect.top );
2045 ok( win_rect.right >= rgn_rect.right, "rgn right %ld not inside win rect %ld\n",
2046 rgn_rect.right, win_rect.right );
2047 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %ld not inside win rect %ld\n",
2048 rgn_rect.bottom, win_rect.bottom );
2049 ReleaseDC( hwnd, hdc );
2052 static void test_SetFocus(HWND hwnd)
2056 /* check if we can set focus to non-visible windows */
2058 ShowWindow(hwnd, SW_SHOW);
2061 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2062 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2063 ShowWindow(hwnd, SW_HIDE);
2066 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2067 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2068 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2071 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2072 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2073 ShowWindow(child, SW_SHOW);
2074 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2075 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2076 ShowWindow(child, SW_HIDE);
2077 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2078 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2079 ShowWindow(child, SW_SHOW);
2081 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2082 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2083 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2085 ShowWindow(child, SW_HIDE);
2087 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2088 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2089 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2090 ShowWindow(child, SW_HIDE);
2091 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2093 ShowWindow(hwnd, SW_SHOW);
2094 ShowWindow(child, SW_SHOW);
2096 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2097 EnableWindow(hwnd, FALSE);
2098 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2099 EnableWindow(hwnd, TRUE);
2101 DestroyWindow( child );
2104 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2106 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2108 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2109 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2110 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2113 static void test_SetActiveWindow(HWND hwnd)
2117 ShowWindow(hwnd, SW_HIDE);
2120 check_wnd_state(0, 0, 0, 0);
2122 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2124 ShowWindow(hwnd, SW_SHOW);
2125 check_wnd_state(hwnd, hwnd, hwnd, 0);
2127 hwnd2 = SetActiveWindow(0);
2128 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2129 check_wnd_state(0, 0, 0, 0);
2131 hwnd2 = SetActiveWindow(hwnd);
2132 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2133 check_wnd_state(hwnd, hwnd, hwnd, 0);
2135 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2136 check_wnd_state(hwnd, hwnd, hwnd, 0);
2138 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2139 check_wnd_state(hwnd, hwnd, hwnd, 0);
2141 ShowWindow(hwnd, SW_HIDE);
2142 check_wnd_state(0, 0, 0, 0);
2144 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2145 SetActiveWindow(hwnd);
2146 check_wnd_state(hwnd, hwnd, hwnd, 0);
2148 ShowWindow(hwnd, SW_SHOW);
2149 check_wnd_state(hwnd, hwnd, hwnd, 0);
2151 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2152 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2154 DestroyWindow(hwnd2);
2155 check_wnd_state(hwnd, hwnd, hwnd, 0);
2157 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2158 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2160 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2161 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2163 DestroyWindow(hwnd2);
2164 check_wnd_state(hwnd, hwnd, hwnd, 0);
2167 static void test_SetForegroundWindow(HWND hwnd)
2172 ShowWindow(hwnd, SW_HIDE);
2175 check_wnd_state(0, 0, 0, 0);
2177 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2179 ShowWindow(hwnd, SW_SHOW);
2180 check_wnd_state(hwnd, hwnd, hwnd, 0);
2182 hwnd2 = SetActiveWindow(0);
2183 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2184 check_wnd_state(0, 0, 0, 0);
2186 ret = SetForegroundWindow(hwnd);
2187 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2188 check_wnd_state(hwnd, hwnd, hwnd, 0);
2190 SetLastError(0xdeadbeef);
2191 ret = SetForegroundWindow(0);
2192 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2193 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %ld expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2194 check_wnd_state(hwnd, hwnd, hwnd, 0);
2196 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2197 check_wnd_state(hwnd, hwnd, hwnd, 0);
2199 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2200 check_wnd_state(hwnd, hwnd, hwnd, 0);
2202 ShowWindow(hwnd, SW_HIDE);
2203 check_wnd_state(0, 0, 0, 0);
2205 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2206 ret = SetForegroundWindow(hwnd);
2207 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2208 check_wnd_state(hwnd, hwnd, hwnd, 0);
2210 ShowWindow(hwnd, SW_SHOW);
2211 check_wnd_state(hwnd, hwnd, hwnd, 0);
2213 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2214 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2216 DestroyWindow(hwnd2);
2217 check_wnd_state(hwnd, hwnd, hwnd, 0);
2219 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2220 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2222 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2223 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2225 DestroyWindow(hwnd2);
2226 check_wnd_state(hwnd, hwnd, hwnd, 0);
2229 static WNDPROC old_button_proc;
2231 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2236 key_state = GetKeyState(VK_LBUTTON);
2237 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2239 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2241 if (msg == WM_LBUTTONDOWN)
2245 check_wnd_state(button, button, button, button);
2247 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2249 trace("hwnd %p\n", hwnd);
2251 check_wnd_state(button, button, button, button);
2253 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2255 check_wnd_state(button, button, button, button);
2257 DestroyWindow(hwnd);
2259 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2261 trace("hwnd %p\n", hwnd);
2263 check_wnd_state(button, button, button, button);
2265 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2266 * match internal button state.
2268 SendMessage(button, WM_KILLFOCUS, 0, 0);
2269 check_wnd_state(button, button, button, 0);
2271 ShowWindow(hwnd, SW_SHOW);
2272 check_wnd_state(hwnd, hwnd, hwnd, 0);
2274 capture = SetCapture(hwnd);
2275 ok(capture == 0, "SetCapture() = %p\n", capture);
2277 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2279 DestroyWindow(hwnd);
2281 check_wnd_state(button, 0, button, 0);
2287 static void test_capture_1(void)
2289 HWND button, capture;
2291 capture = GetCapture();
2292 ok(capture == 0, "GetCapture() = %p\n", capture);
2294 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2296 trace("button %p\n", button);
2298 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2300 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2302 capture = SetCapture(button);
2303 ok(capture == 0, "SetCapture() = %p\n", capture);
2304 check_wnd_state(button, 0, button, button);
2306 DestroyWindow(button);
2307 check_wnd_state(0, 0, 0, 0);
2310 static void test_capture_2(void)
2312 HWND button, hwnd, capture;
2314 check_wnd_state(0, 0, 0, 0);
2316 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2318 trace("button %p\n", button);
2320 check_wnd_state(button, button, button, 0);
2322 capture = SetCapture(button);
2323 ok(capture == 0, "SetCapture() = %p\n", capture);
2325 check_wnd_state(button, button, button, button);
2327 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2328 * internal button state.
2330 SendMessage(button, WM_KILLFOCUS, 0, 0);
2331 check_wnd_state(button, button, button, button);
2333 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2335 trace("hwnd %p\n", hwnd);
2337 check_wnd_state(button, button, button, button);
2339 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2341 check_wnd_state(button, button, button, button);
2343 DestroyWindow(hwnd);
2345 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2347 trace("hwnd %p\n", hwnd);
2349 check_wnd_state(button, button, button, button);
2351 ShowWindow(hwnd, SW_SHOW);
2353 check_wnd_state(hwnd, hwnd, hwnd, button);
2355 capture = SetCapture(hwnd);
2356 ok(capture == button, "SetCapture() = %p\n", capture);
2358 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2360 DestroyWindow(hwnd);
2361 check_wnd_state(button, button, button, 0);
2363 DestroyWindow(button);
2364 check_wnd_state(0, 0, 0, 0);
2367 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2371 ShowWindow(hwnd1, SW_HIDE);
2372 ShowWindow(hwnd2, SW_HIDE);
2374 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2375 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2378 check_wnd_state(0, 0, 0, hwnd1);
2381 check_wnd_state(0, 0, 0, hwnd2);
2383 ShowWindow(hwnd1, SW_SHOW);
2384 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2386 ret = ReleaseCapture();
2387 ok (ret, "releasecapture did not return TRUE.\n");
2388 ret = ReleaseCapture();
2389 ok (ret, "releasecapture did not return TRUE after second try.\n");
2392 static void test_keyboard_input(HWND hwnd)
2397 ShowWindow(hwnd, SW_SHOW);
2401 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2404 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2406 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2408 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2409 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2410 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2411 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2412 ok( !ret, "message %04x available\n", msg.message);
2414 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2416 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2417 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2418 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2419 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2420 ok( !ret, "message %04x available\n", msg.message);
2422 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2424 keybd_event(VK_SPACE, 0, 0, 0);
2425 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2426 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2427 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2428 ok( !ret, "message %04x available\n", msg.message);
2431 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2433 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2435 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2436 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2437 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2438 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2439 ok( !ret, "message %04x available\n", msg.message);
2441 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2443 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2444 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2445 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2446 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2447 ok( !ret, "message %04x available\n", msg.message);
2449 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2451 keybd_event(VK_SPACE, 0, 0, 0);
2452 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2453 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2454 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2455 ok( !ret, "message %04x available\n", msg.message);
2458 static void test_mouse_input(HWND hwnd)
2468 ShowWindow(hwnd, SW_SHOW);
2471 GetWindowRect(hwnd, &rc);
2472 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2474 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2475 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2478 ShowWindow(popup, SW_SHOW);
2479 UpdateWindow(popup);
2481 GetWindowRect(popup, &rc);
2482 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2484 x = rc.left + (rc.right - rc.left) / 2;
2485 y = rc.top + (rc.bottom - rc.top) / 2;
2486 trace("setting cursor to (%d,%d)\n", x, y);
2490 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2492 /* force the system to update its internal queue mouse position,
2493 * otherwise it won't generate relative mouse movements below.
2495 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2496 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2499 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2500 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2501 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2502 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2503 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2504 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2505 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2506 ok( !ret, "message %04x available\n", msg.message);
2508 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2509 ShowWindow(popup, SW_HIDE);
2510 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2511 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2512 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2514 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2515 ShowWindow(hwnd, SW_HIDE);
2516 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2517 ok( !ret, "message %04x available\n", msg.message);
2519 /* test mouse clicks */
2521 ShowWindow(hwnd, SW_SHOW);
2522 ShowWindow(popup, SW_SHOW);
2524 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2526 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2527 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2528 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2529 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2531 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2532 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2533 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2534 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2536 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2537 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2538 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2539 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2541 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2542 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2543 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2544 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2546 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2547 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2548 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2549 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2551 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2552 ok(!ret, "message %04x available\n", msg.message);
2554 ShowWindow(popup, SW_HIDE);
2555 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2557 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2558 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2559 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2560 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2562 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2563 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2564 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2565 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2567 test_lbuttondown_flag = TRUE;
2568 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2569 test_lbuttondown_flag = FALSE;
2571 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2572 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2573 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2574 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2575 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2577 /* Test WM_MOUSEACTIVATE */
2578 #define TEST_MOUSEACTIVATE(A,B) \
2579 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2580 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2582 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2583 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2584 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2585 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2586 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2587 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2588 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2589 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2590 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2591 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2592 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2593 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2594 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2595 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2596 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2597 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2598 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2599 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2600 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2601 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2602 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2603 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2604 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2605 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2607 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2608 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2610 DestroyWindow(popup);
2613 static void test_validatergn(HWND hwnd)
2619 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2620 ShowWindow(hwnd, SW_SHOW);
2621 UpdateWindow( hwnd);
2622 /* test that ValidateRect validates children*/
2623 InvalidateRect( child, NULL, 1);
2624 GetWindowRect( child, &rc);
2625 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2626 ret = GetUpdateRect( child, &rc2, 0);
2627 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2628 "Update rectangle is empty!\n");
2629 ValidateRect( hwnd, &rc);
2630 ret = GetUpdateRect( child, &rc2, 0);
2631 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2632 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2633 rc2.right, rc2.bottom);
2635 /* now test ValidateRgn */
2636 InvalidateRect( child, NULL, 1);
2637 GetWindowRect( child, &rc);
2638 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2639 rgn = CreateRectRgnIndirect( &rc);
2640 ValidateRgn( hwnd, rgn);
2641 ret = GetUpdateRect( child, &rc2, 0);
2642 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2643 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2644 rc2.right, rc2.bottom);
2647 DestroyWindow( child );
2650 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2652 MoveWindow( hwnd, 0, 0, x, y, 0);
2653 GetWindowRect( hwnd, prc);
2654 trace("window rect is %ld,%ld - %ld,%ld\n",
2655 prc->left,prc->top,prc->right,prc->bottom);
2656 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2657 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2658 prc->left,prc->top,prc->right,prc->bottom);
2661 static void test_nccalcscroll(HWND parent)
2664 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2665 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2666 HWND hwnd = CreateWindowExA(0, "static", NULL,
2667 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2668 10, 10, 200, 200, parent, 0, 0, NULL);
2669 ShowWindow( parent, SW_SHOW);
2670 UpdateWindow( parent);
2672 /* test window too low for a horizontal scroll bar */
2673 nccalchelper( hwnd, 100, sbheight, &rc1);
2674 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2675 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2677 /* test window just high enough for a horizontal scroll bar */
2678 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2679 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2680 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2682 /* test window too narrow for a vertical scroll bar */
2683 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2684 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2685 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2687 /* test window just wide enough for a vertical scroll bar */
2688 nccalchelper( hwnd, sbwidth, 100, &rc1);
2689 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2690 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2692 /* same test, but with client edge: not enough width */
2693 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2694 nccalchelper( hwnd, sbwidth, 100, &rc1);
2695 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2696 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2697 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2699 DestroyWindow( hwnd);
2702 static void test_SetParent(void)
2705 HWND desktop = GetDesktopWindow();
2707 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2708 HWND parent, child1, child2, child3, child4, sibling;
2710 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2711 100, 100, 200, 200, 0, 0, 0, NULL);
2712 assert(parent != 0);
2713 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2714 0, 0, 50, 50, parent, 0, 0, NULL);
2715 assert(child1 != 0);
2716 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2717 0, 0, 50, 50, child1, 0, 0, NULL);
2718 assert(child2 != 0);
2719 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2720 0, 0, 50, 50, child2, 0, 0, NULL);
2721 assert(child3 != 0);
2722 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2723 0, 0, 50, 50, child3, 0, 0, NULL);
2724 assert(child4 != 0);
2726 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2727 parent, child1, child2, child3, child4);
2729 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2730 check_parents(child1, parent, parent, parent, 0, parent, parent);
2731 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2732 check_parents(child3, child2, child2, child2, 0, child2, parent);
2733 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2736 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2737 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2738 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2739 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2740 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2743 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2745 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2747 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2748 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2749 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2750 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2751 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2752 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2754 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2757 if (!is_win9x) /* Win9x doesn't survive this test */
2759 ok(!SetParent(parent, child1), "SetParent should fail\n");
2760 ok(!SetParent(child2, child3), "SetParent should fail\n");
2761 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2762 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2763 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2764 ok(!SetParent(child2, parent), "SetParent should fail\n");
2765 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2767 check_parents(parent, child4, child4, 0, 0, child4, parent);
2768 check_parents(child1, parent, parent, parent, 0, child4, parent);
2769 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2770 check_parents(child3, child2, child2, child2, 0, child2, parent);
2771 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2774 hMenu = CreateMenu();
2775 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2776 100, 100, 200, 200, 0, hMenu, 0, NULL);
2777 assert(sibling != 0);
2779 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2780 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2782 ret = DestroyWindow(parent);
2783 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2785 ok(!IsWindow(parent), "parent still exists\n");
2786 ok(!IsWindow(sibling), "sibling still exists\n");
2787 ok(!IsWindow(child1), "child1 still exists\n");
2788 ok(!IsWindow(child2), "child2 still exists\n");
2789 ok(!IsWindow(child3), "child3 still exists\n");
2790 ok(!IsWindow(child4), "child4 still exists\n");
2793 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2795 LPCREATESTRUCT lpcs;
2802 lpcs = (LPCREATESTRUCT)lparam;
2803 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2806 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2807 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2808 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2809 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2811 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2813 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2814 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2815 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2817 ok(lpss->styleNew == lpcs->style,
2818 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2819 lpss->styleNew, lpcs->style);
2823 return DefWindowProc(hwnd, msg, wparam, lparam);
2826 static ATOM atomStyleCheckClass;
2828 static void register_style_check_class(void)
2836 GetModuleHandle(NULL),
2838 LoadCursor(NULL, IDC_ARROW),
2839 (HBRUSH)(COLOR_BTNFACE+1),
2841 TEXT("WineStyleCheck"),
2844 atomStyleCheckClass = RegisterClass(&wc);
2847 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2849 DWORD dwActualStyle;
2850 DWORD dwActualExStyle;
2853 HWND hwndParent = NULL;
2856 ss.styleNew = dwStyleIn;
2857 ss.styleOld = dwExStyleIn;
2859 if (dwStyleIn & WS_CHILD)
2861 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2862 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2865 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2866 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2869 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2871 TranslateMessage(&msg);
2872 DispatchMessage(&msg);
2875 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2876 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2877 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2878 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2879 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2881 DestroyWindow(hwnd);
2882 if (hwndParent) DestroyWindow(hwndParent);
2885 /* tests what window styles the window manager automatically adds */
2886 static void test_window_styles(void)
2888 register_style_check_class();
2890 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2891 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2892 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2893 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2894 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2895 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2896 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2897 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2898 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2899 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2900 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2903 static void test_scrollvalidate( HWND parent)
2906 HRGN hrgn=CreateRectRgn(0,0,0,0);
2907 HRGN exprgn, tmprgn, clipping;
2908 RECT rc, rcu, cliprc;
2909 /* create two overlapping child windows. The visual region
2910 * of hwnd1 is clipped by the overlapping part of
2911 * hwnd2 because of the WS_CLIPSIBLING style */
2914 clipping = CreateRectRgn(0,0,0,0);
2915 tmprgn = CreateRectRgn(0,0,0,0);
2916 exprgn = CreateRectRgn(0,0,0,0);
2917 hwnd2 = CreateWindowExA(0, "static", NULL,
2918 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2919 75, 30, 100, 100, parent, 0, 0, NULL);
2920 hwnd1 = CreateWindowExA(0, "static", NULL,
2921 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2922 25, 50, 100, 100, parent, 0, 0, NULL);
2923 ShowWindow( parent, SW_SHOW);
2924 UpdateWindow( parent);
2925 GetClientRect( hwnd1, &rc);
2927 SetRectRgn( clipping, 10, 10, 90, 90);
2928 hdc = GetDC( hwnd1);
2929 /* for a visual touch */
2930 TextOut( hdc, 0,10, "0123456789", 10);
2931 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2932 if (winetest_debug > 0) dump_region(hrgn);
2933 /* create a region with what is expected */
2934 SetRectRgn( exprgn, 39,0,49,74);
2935 SetRectRgn( tmprgn, 88,79,98,93);
2936 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2937 SetRectRgn( tmprgn, 0,93,98,98);
2938 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2939 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2940 trace("update rect is %ld,%ld - %ld,%ld\n",
2941 rcu.left,rcu.top,rcu.right,rcu.bottom);
2942 /* now with clipping region */
2943 SelectClipRgn( hdc, clipping);
2944 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2945 if (winetest_debug > 0) dump_region(hrgn);
2946 /* create a region with what is expected */
2947 SetRectRgn( exprgn, 39,10,49,74);
2948 SetRectRgn( tmprgn, 80,79,90,85);
2949 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2950 SetRectRgn( tmprgn, 10,85,90,90);
2951 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2952 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2953 trace("update rect is %ld,%ld - %ld,%ld\n",
2954 rcu.left,rcu.top,rcu.right,rcu.bottom);
2955 ReleaseDC( hwnd1, hdc);
2957 /* test scrolling a window with an update region */
2958 DestroyWindow( hwnd2);
2959 ValidateRect( hwnd1, NULL);
2960 SetRect( &rc, 40,40, 50,50);
2961 InvalidateRect( hwnd1, &rc, 1);
2962 GetClientRect( hwnd1, &rc);
2964 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2965 SW_SCROLLCHILDREN | SW_INVALIDATE);
2966 if (winetest_debug > 0) dump_region(hrgn);
2967 SetRectRgn( exprgn, 88,0,98,98);
2968 SetRectRgn( tmprgn, 30, 40, 50, 50);
2969 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2970 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2972 /* now test ScrollWindowEx with a combination of
2973 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2974 /* make hwnd2 the child of hwnd1 */
2975 hwnd2 = CreateWindowExA(0, "static", NULL,
2976 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2977 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2978 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2979 GetClientRect( hwnd1, &rc);
2982 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2983 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2984 ValidateRect( hwnd1, NULL);
2985 ValidateRect( hwnd2, NULL);
2986 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2987 SW_SCROLLCHILDREN | SW_INVALIDATE);
2988 if (winetest_debug > 0) dump_region(hrgn);
2989 SetRectRgn( exprgn, 88,0,98,88);
2990 SetRectRgn( tmprgn, 0,88,98,98);
2991 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2992 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2994 /* SW_SCROLLCHILDREN */
2995 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2996 ValidateRect( hwnd1, NULL);
2997 ValidateRect( hwnd2, NULL);
2998 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
2999 if (winetest_debug > 0) dump_region(hrgn);
3000 /* expected region is the same as in previous test */
3001 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3003 /* no SW_SCROLLCHILDREN */
3004 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3005 ValidateRect( hwnd1, NULL);
3006 ValidateRect( hwnd2, NULL);
3007 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3008 if (winetest_debug > 0) dump_region(hrgn);
3009 /* expected region is the same as in previous test */
3010 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3012 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3013 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3014 ValidateRect( hwnd1, NULL);
3015 ValidateRect( hwnd2, NULL);
3016 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3017 if (winetest_debug > 0) dump_region(hrgn);
3018 SetRectRgn( exprgn, 88,0,98,20);
3019 SetRectRgn( tmprgn, 20,20,98,30);
3020 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3021 SetRectRgn( tmprgn, 20,30,30,88);
3022 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3023 SetRectRgn( tmprgn, 0,88,30,98);
3024 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3025 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3028 DeleteObject( hrgn);
3029 DeleteObject( exprgn);
3030 DeleteObject( tmprgn);
3031 DestroyWindow( hwnd1);
3032 DestroyWindow( hwnd2);
3035 /* couple of tests of return values of scrollbar functions
3036 * called on a scrollbarless window */
3037 static void test_scroll(void)
3042 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3043 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3044 100, 100, 200, 200, 0, 0, 0, NULL);
3046 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3047 ok( ret, "GetScrollRange returns FALSE\n");
3048 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3049 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3050 si.cbSize = sizeof( si);
3051 si.fMask = SIF_PAGE;
3052 si.nPage = 0xdeadbeef;
3053 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3054 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3055 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3057 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3058 ok( ret, "GetScrollRange returns FALSE\n");
3059 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3060 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3061 si.cbSize = sizeof( si);
3062 si.fMask = SIF_PAGE;
3063 si.nPage = 0xdeadbeef;
3064 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3065 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3066 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3068 DestroyWindow( hwnd);
3071 static void test_scrolldc( HWND parent)
3074 HRGN exprgn, tmprgn, hrgn;
3075 RECT rc, rc2, rcu, cliprc;
3079 hrgn = CreateRectRgn(0,0,0,0);
3080 tmprgn = CreateRectRgn(0,0,0,0);
3081 exprgn = CreateRectRgn(0,0,0,0);
3083 hwnd1 = CreateWindowExA(0, "static", NULL,
3084 WS_CHILD| WS_VISIBLE,
3085 25, 50, 100, 100, parent, 0, 0, NULL);
3086 ShowWindow( parent, SW_SHOW);
3087 UpdateWindow( parent);
3088 GetClientRect( hwnd1, &rc);
3089 hdc = GetDC( hwnd1);
3090 /* paint the upper half of the window black */
3092 rc2.bottom = ( rc.top + rc.bottom) /2;
3093 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3094 /* clip region is the lower half */
3096 cliprc.top = (rc.top + rc.bottom) /2;
3097 /* test whether scrolled pixels are properly clipped */
3098 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3099 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3100 /* this scroll should not cause any visible changes */
3101 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3102 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3103 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3104 /* test with NULL clip rect */
3105 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3106 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3107 trace("update rect: %ld,%ld - %ld,%ld\n",
3108 rcu.left, rcu.top, rcu.right, rcu.bottom);
3109 if (winetest_debug > 0) dump_region(hrgn);
3110 SetRect(&rc2, 0, 0, 100, 100);
3111 ok(EqualRect(&rcu, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
3112 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3114 SetRectRgn( exprgn, 0, 0, 20, 80);
3115 SetRectRgn( tmprgn, 0, 80, 100, 100);
3116 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3117 if (winetest_debug > 0) dump_region(exprgn);
3118 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3119 /* test clip rect > scroll rect */
3120 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3122 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3123 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3124 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3125 SetRectRgn( exprgn, 25, 25, 75, 35);
3126 SetRectRgn( tmprgn, 25, 35, 35, 75);
3127 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3128 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3129 colr = GetPixel( hdc, 80, 80);
3130 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3131 trace("update rect: %ld,%ld - %ld,%ld\n",
3132 rcu.left, rcu.top, rcu.right, rcu.bottom);
3133 if (winetest_debug > 0) dump_region(hrgn);
3137 DeleteObject(exprgn);
3138 DeleteObject(tmprgn);
3139 DestroyWindow(hwnd1);
3142 static void test_params(void)
3147 /* Just a param check */
3148 SetLastError(0xdeadbeef);
3149 rc = GetWindowText(hwndMain2, NULL, 1024);
3150 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
3152 SetLastError(0xdeadbeef);
3153 hwnd=CreateWindow("LISTBOX", "TestList",
3154 (LBS_STANDARD & ~LBS_SORT),
3156 NULL, (HMENU)1, NULL, 0);
3158 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3159 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3160 GetLastError() == 0xdeadbeef, /* Win9x */
3161 "wrong last error value %ld\n", GetLastError());
3164 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3168 hwnd = CreateWindowEx(exStyle, class, class, style,
3175 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
3178 ShowWindow(hwnd, SW_SHOW);
3180 test_nonclient_area(hwnd);
3183 DestroyWindow(hwnd);
3186 static BOOL AWR_init(void)
3190 class.style = CS_HREDRAW | CS_VREDRAW;
3191 class.lpfnWndProc = DefWindowProcA;
3192 class.cbClsExtra = 0;
3193 class.cbWndExtra = 0;
3194 class.hInstance = 0;
3195 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3196 class.hCursor = LoadCursor (0, IDC_ARROW);
3197 class.hbrBackground = 0;
3198 class.lpszMenuName = 0;
3199 class.lpszClassName = szAWRClass;
3201 if (!RegisterClass (&class)) {
3202 ok(FALSE, "RegisterClass failed\n");
3206 hmenu = CreateMenu();
3209 ok(hmenu != 0, "Failed to create menu\n");
3210 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3216 static void test_AWR_window_size(BOOL menu)
3220 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3223 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3224 WS_HSCROLL, WS_VSCROLL
3228 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3231 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3232 WS_EX_DLGMODALFRAME,
3239 /* A exhaustive check of all the styles takes too long
3240 * so just do a (hopefully representative) sample
3242 for (i = 0; i < COUNTOF(styles); ++i)
3243 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3244 for (i = 0; i < COUNTOF(exStyles); ++i) {
3245 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3246 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3251 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3253 static void test_AdjustWindowRect(void)
3258 SHOWSYSMETRIC(SM_CYCAPTION);
3259 SHOWSYSMETRIC(SM_CYSMCAPTION);
3260 SHOWSYSMETRIC(SM_CYMENU);
3261 SHOWSYSMETRIC(SM_CXEDGE);
3262 SHOWSYSMETRIC(SM_CYEDGE);
3263 SHOWSYSMETRIC(SM_CXVSCROLL);
3264 SHOWSYSMETRIC(SM_CYHSCROLL);
3265 SHOWSYSMETRIC(SM_CXFRAME);
3266 SHOWSYSMETRIC(SM_CYFRAME);
3267 SHOWSYSMETRIC(SM_CXDLGFRAME);
3268 SHOWSYSMETRIC(SM_CYDLGFRAME);
3269 SHOWSYSMETRIC(SM_CXBORDER);
3270 SHOWSYSMETRIC(SM_CYBORDER);
3272 test_AWR_window_size(FALSE);
3273 test_AWR_window_size(TRUE);
3277 #undef SHOWSYSMETRIC
3280 /* Global variables to trigger exit from loop */
3281 static int redrawComplete, WMPAINT_count;
3283 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3288 trace("doing WM_PAINT %d\n", WMPAINT_count);
3290 if (WMPAINT_count > 10 && redrawComplete == 0) {
3292 BeginPaint(hwnd, &ps);
3293 EndPaint(hwnd, &ps);
3299 return DefWindowProc(hwnd, msg, wparam, lparam);
3302 /* Ensure we exit from RedrawNow regardless of invalidated area */
3303 static void test_redrawnow(void)
3308 cls.style = CS_DBLCLKS;
3309 cls.lpfnWndProc = redraw_window_procA;
3312 cls.hInstance = GetModuleHandleA(0);
3314 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3315 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3316 cls.lpszMenuName = NULL;
3317 cls.lpszClassName = "RedrawWindowClass";
3319 if(!RegisterClassA(&cls)) {
3320 trace("Register failed %ld\n", GetLastError());
3324 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3325 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3327 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3328 ShowWindow(hwndMain, SW_SHOW);
3329 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3330 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3331 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3332 redrawComplete = TRUE;
3333 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3336 DestroyWindow( hwndMain);
3339 struct parentdc_stat {
3345 struct parentdc_test {
3346 struct parentdc_stat main, main_todo;
3347 struct parentdc_stat child1, child1_todo;
3348 struct parentdc_stat child2, child2_todo;
3351 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3356 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3361 trace("doing WM_PAINT on %p\n", hwnd);
3362 GetClientRect(hwnd, &rc);
3363 CopyRect(&t->client, &rc);
3364 trace("client rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3365 GetWindowRect(hwnd, &rc);
3366 trace("window rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3367 BeginPaint(hwnd, &ps);
3368 CopyRect(&t->paint, &ps.rcPaint);
3369 GetClipBox(ps.hdc, &rc);
3370 CopyRect(&t->clip, &rc);
3371 trace("clip rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3372 trace("paint rect (%ld, %ld)-(%ld, %ld)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3373 EndPaint(hwnd, &ps);
3376 return DefWindowProc(hwnd, msg, wparam, lparam);
3379 static void zero_parentdc_stat(struct parentdc_stat *t)
3381 SetRectEmpty(&t->client);
3382 SetRectEmpty(&t->clip);
3383 SetRectEmpty(&t->paint);
3386 static void zero_parentdc_test(struct parentdc_test *t)
3388 zero_parentdc_stat(&t->main);
3389 zero_parentdc_stat(&t->child1);
3390 zero_parentdc_stat(&t->child2);
3393 #define parentdc_field_ok(t, w, r, f, got) \
3394 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3395 ": expected %ld, got %ld\n", \
3398 #define parentdc_todo_field_ok(t, w, r, f, got) \
3399 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3400 else parentdc_field_ok(t, w, r, f, got)
3402 #define parentdc_rect_ok(t, w, r, got) \
3403 parentdc_todo_field_ok(t, w, r, left, got); \
3404 parentdc_todo_field_ok(t, w, r, top, got); \
3405 parentdc_todo_field_ok(t, w, r, right, got); \
3406 parentdc_todo_field_ok(t, w, r, bottom, got);
3408 #define parentdc_win_ok(t, w, got) \
3409 parentdc_rect_ok(t, w, client, got); \
3410 parentdc_rect_ok(t, w, clip, got); \
3411 parentdc_rect_ok(t, w, paint, got);
3413 #define parentdc_ok(t, got) \
3414 parentdc_win_ok(t, main, got); \
3415 parentdc_win_ok(t, child1, got); \
3416 parentdc_win_ok(t, child2, got);
3418 static void test_csparentdc(void)
3420 WNDCLASSA clsMain, cls;
3421 HWND hwndMain, hwnd1, hwnd2;
3425 struct parentdc_test test_answer;
3427 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3428 const struct parentdc_test test1 =
3430 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3431 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3432 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3435 const struct parentdc_test test2 =
3437 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3438 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3439 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3442 const struct parentdc_test test3 =
3444 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3445 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3446 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3449 const struct parentdc_test test4 =
3451 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3452 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3453 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3456 const struct parentdc_test test5 =
3458 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3459 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3460 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3463 const struct parentdc_test test6 =
3465 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3466 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3467 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3470 const struct parentdc_test test7 =
3472 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3473 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3474 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3478 clsMain.style = CS_DBLCLKS;
3479 clsMain.lpfnWndProc = parentdc_window_procA;
3480 clsMain.cbClsExtra = 0;
3481 clsMain.cbWndExtra = 0;
3482 clsMain.hInstance = GetModuleHandleA(0);
3484 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3485 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3486 clsMain.lpszMenuName = NULL;
3487 clsMain.lpszClassName = "ParentDcMainWindowClass";
3489 if(!RegisterClassA(&clsMain)) {
3490 trace("Register failed %ld\n", GetLastError());
3494 cls.style = CS_DBLCLKS | CS_PARENTDC;
3495 cls.lpfnWndProc = parentdc_window_procA;
3498 cls.hInstance = GetModuleHandleA(0);
3500 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3501 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3502 cls.lpszMenuName = NULL;
3503 cls.lpszClassName = "ParentDcWindowClass";
3505 if(!RegisterClassA(&cls)) {
3506 trace("Register failed %ld\n", GetLastError());
3510 SetRect(&rc, 0, 0, 150, 150);
3511 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3512 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3513 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3514 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3515 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3516 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3517 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3518 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3519 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3520 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3521 ShowWindow(hwndMain, SW_SHOW);
3522 ShowWindow(hwnd1, SW_SHOW);
3523 ShowWindow(hwnd2, SW_SHOW);
3526 zero_parentdc_test(&test_answer);
3527 InvalidateRect(hwndMain, NULL, TRUE);
3528 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3529 parentdc_ok(test1, test_answer);
3531 zero_parentdc_test(&test_answer);
3532 SetRect(&rc, 0, 0, 50, 50);
3533 InvalidateRect(hwndMain, &rc, TRUE);
3534 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3535 parentdc_ok(test2, test_answer);
3537 zero_parentdc_test(&test_answer);
3538 SetRect(&rc, 0, 0, 10, 10);
3539 InvalidateRect(hwndMain, &rc, TRUE);
3540 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3541 parentdc_ok(test3, test_answer);
3543 zero_parentdc_test(&test_answer);
3544 SetRect(&rc, 40, 40, 50, 50);
3545 InvalidateRect(hwndMain, &rc, TRUE);
3546 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3547 parentdc_ok(test4, test_answer);
3549 zero_parentdc_test(&test_answer);
3550 SetRect(&rc, 20, 20, 60, 60);
3551 InvalidateRect(hwndMain, &rc, TRUE);
3552 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3553 parentdc_ok(test5, test_answer);
3555 zero_parentdc_test(&test_answer);
3556 SetRect(&rc, 0, 0, 10, 10);
3557 InvalidateRect(hwnd1, &rc, TRUE);
3558 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3559 parentdc_ok(test6, test_answer);
3561 zero_parentdc_test(&test_answer);
3562 SetRect(&rc, -5, -5, 65, 65);
3563 InvalidateRect(hwnd1, &rc, TRUE);
3564 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3565 parentdc_ok(test7, test_answer);
3567 DestroyWindow(hwndMain);
3568 DestroyWindow(hwnd1);
3569 DestroyWindow(hwnd2);
3572 static void test_IsWindowUnicode(void)
3574 static const char ansi_class_nameA[] = "ansi class name";
3575 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3576 static const char unicode_class_nameA[] = "unicode class name";
3577 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3582 memset(&classW, 0, sizeof(classW));
3583 classW.hInstance = GetModuleHandleA(0);
3584 classW.lpfnWndProc = DefWindowProcW;
3585 classW.lpszClassName = unicode_class_nameW;
3586 if (!RegisterClassW(&classW)) return;
3588 memset(&classA, 0, sizeof(classA));
3589 classA.hInstance = GetModuleHandleA(0);
3590 classA.lpfnWndProc = DefWindowProcA;
3591 classA.lpszClassName = ansi_class_nameA;
3592 assert(RegisterClassA(&classA));
3594 /* unicode class: window proc */
3595 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3596 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3599 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3600 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3601 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3602 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3603 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3605 DestroyWindow(hwnd);
3607 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3608 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3611 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3612 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3613 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3614 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3615 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3617 DestroyWindow(hwnd);
3619 /* ansi class: window proc */
3620 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3621 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3624 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3625 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3626 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3627 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3628 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3630 DestroyWindow(hwnd);
3632 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3633 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3636 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3637 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3638 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3639 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3640 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3642 DestroyWindow(hwnd);
3644 /* unicode class: class proc */
3645 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3646 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3649 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3650 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3651 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3652 /* do not restore class window proc back to unicode */
3654 DestroyWindow(hwnd);
3656 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3657 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3660 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3661 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3662 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3664 DestroyWindow(hwnd);
3666 /* ansi class: class proc */
3667 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3668 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3671 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3672 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3673 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3674 /* do not restore class window proc back to ansi */
3676 DestroyWindow(hwnd);
3678 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3679 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3682 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3683 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3684 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3686 DestroyWindow(hwnd);
3689 static void test_CreateWindow(void)
3694 #define expect_menu(window, menu) \
3695 SetLastError(0xdeadbeef); \
3696 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %ld\n", GetLastError())
3698 #define expect_style(window, style)\
3699 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %lx != %lx\n", (long)(style), GetWindowLong(window, GWL_STYLE))
3701 #define expect_ex_style(window, ex_style)\
3702 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %lx != %lx\n", (long)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3704 hmenu = CreateMenu();
3706 parent = GetDesktopWindow();
3707 assert(parent != 0);
3709 SetLastError(0xdeadbeef);
3710 ok(IsMenu(hmenu), "IsMenu error %ld\n", GetLastError());
3712 SetLastError(0xdeadbeef);
3713 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3714 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3715 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3716 expect_menu(hwnd, 1);
3717 expect_style(hwnd, WS_CHILD);
3718 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3719 DestroyWindow(hwnd);
3721 SetLastError(0xdeadbeef);
3722 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3723 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3724 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3725 expect_menu(hwnd, 1);
3726 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3727 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3728 DestroyWindow(hwnd);
3730 SetLastError(0xdeadbeef);
3731 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3732 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3733 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3734 expect_menu(hwnd, 1);
3735 expect_style(hwnd, WS_CHILD);
3736 expect_ex_style(hwnd, 0);
3737 DestroyWindow(hwnd);
3739 SetLastError(0xdeadbeef);
3740 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3741 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3742 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3743 expect_menu(hwnd, 1);
3744 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3745 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3746 DestroyWindow(hwnd);
3748 SetLastError(0xdeadbeef);
3749 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3750 0, 0, 100, 100, parent, hmenu, 0, NULL);
3751 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3752 expect_menu(hwnd, hmenu);
3753 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3754 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3755 DestroyWindow(hwnd);
3756 SetLastError(0xdeadbeef);
3757 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3758 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3760 hmenu = CreateMenu();
3762 SetLastError(0xdeadbeef);
3763 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
3764 0, 0, 100, 100, parent, hmenu, 0, NULL);
3765 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3766 expect_menu(hwnd, hmenu);
3767 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3768 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3769 DestroyWindow(hwnd);
3770 SetLastError(0xdeadbeef);
3771 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3772 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3774 hmenu = CreateMenu();
3776 SetLastError(0xdeadbeef);
3777 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3778 0, 0, 100, 100, parent, hmenu, 0, NULL);
3779 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3780 expect_menu(hwnd, hmenu);
3781 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3782 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3783 DestroyWindow(hwnd);
3784 SetLastError(0xdeadbeef);
3785 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3786 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3788 hmenu = CreateMenu();
3790 SetLastError(0xdeadbeef);
3791 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
3792 0, 0, 100, 100, parent, hmenu, 0, NULL);
3793 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3794 expect_menu(hwnd, hmenu);
3795 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3796 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3797 DestroyWindow(hwnd);
3798 SetLastError(0xdeadbeef);
3799 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3800 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3802 hmenu = CreateMenu();
3804 SetLastError(0xdeadbeef);
3805 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
3806 0, 0, 100, 100, parent, hmenu, 0, NULL);
3807 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3808 expect_menu(hwnd, hmenu);
3809 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3810 expect_ex_style(hwnd, 0);
3811 DestroyWindow(hwnd);
3812 SetLastError(0xdeadbeef);
3813 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3814 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3818 #undef expect_ex_style
3823 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3824 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3826 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3829 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3832 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3833 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3834 trace("hwndMessage %p\n", hwndMessage);
3836 DestroyWindow(hwndMain);
3839 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3841 if (!RegisterWindowClasses()) assert(0);
3843 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3846 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3847 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3848 WS_MAXIMIZEBOX | WS_POPUP,
3851 test_nonclient_area(hwndMain);
3853 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3854 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3855 WS_MAXIMIZEBOX | WS_POPUP,
3859 assert( hwndMain2 );
3861 /* Add the tests below this line */
3866 test_capture_3(hwndMain, hwndMain2);
3868 test_CreateWindow();
3869 test_parent_owner();
3871 test_shell_window();
3875 test_SetWindowPos(hwndMain);
3876 test_SetMenu(hwndMain);
3877 test_SetFocus(hwndMain);
3878 test_SetActiveWindow(hwndMain);
3879 test_SetForegroundWindow(hwndMain);
3881 test_children_zorder(hwndMain);
3882 test_keyboard_input(hwndMain);
3883 test_mouse_input(hwndMain);
3884 test_validatergn(hwndMain);
3885 test_nccalcscroll( hwndMain);
3886 test_scrollvalidate( hwndMain);
3887 test_scrolldc( hwndMain);
3889 test_IsWindowUnicode();
3890 test_vis_rgn(hwndMain);
3892 test_AdjustWindowRect();
3893 test_window_styles();
3897 /* add the tests above this line */
3898 UnhookWindowsHookEx(hhook);