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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
46 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
48 static HWND hwndMessage;
49 static HWND hwndMain, hwndMain2;
52 /* check the values returned by the various parent/owner functions on a given window */
53 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
54 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
60 res = pGetAncestor( hwnd, GA_PARENT );
61 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
63 res = (HWND)GetWindowLongA( hwnd, GWL_HWNDPARENT );
64 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
65 res = GetParent( hwnd );
66 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
67 res = GetWindow( hwnd, GW_OWNER );
68 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
71 res = pGetAncestor( hwnd, GA_ROOT );
72 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
73 res = pGetAncestor( hwnd, GA_ROOTOWNER );
74 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
79 static HWND create_tool_window( LONG style, HWND parent )
81 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
82 0, 0, 100, 100, parent, 0, 0, NULL );
83 ok( ret != 0, "Creation failed\n" );
87 /* test parent and owner values for various combinations */
88 static void test_parent_owner(void)
91 HWND test, owner, ret;
92 HWND desktop = GetDesktopWindow();
93 HWND child = create_tool_window( WS_CHILD, hwndMain );
95 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
97 /* child without parent, should fail */
98 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
99 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
100 ok( !test, "WS_CHILD without parent created\n" );
103 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
104 style = GetWindowLongA( desktop, GWL_STYLE );
105 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
106 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
107 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
109 /* normal child window */
110 test = create_tool_window( WS_CHILD, hwndMain );
111 trace( "created child %p\n", test );
112 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
113 SetWindowLongA( test, GWL_STYLE, 0 );
114 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
115 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
116 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
117 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
118 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
119 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
120 DestroyWindow( test );
122 /* normal child window with WS_MAXIMIZE */
123 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
124 DestroyWindow( test );
126 /* normal child window with WS_THICKFRAME */
127 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
128 DestroyWindow( test );
130 /* popup window with WS_THICKFRAME */
131 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
132 DestroyWindow( test );
134 /* child of desktop */
135 test = create_tool_window( WS_CHILD, desktop );
136 trace( "created child of desktop %p\n", test );
137 check_parents( test, desktop, 0, desktop, 0, test, desktop );
138 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
139 check_parents( test, desktop, 0, 0, 0, test, test );
140 SetWindowLongA( test, GWL_STYLE, 0 );
141 check_parents( test, desktop, 0, 0, 0, test, test );
142 DestroyWindow( test );
144 /* child of desktop with WS_MAXIMIZE */
145 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
146 DestroyWindow( test );
148 /* child of desktop with WS_MINIMIZE */
149 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
150 DestroyWindow( test );
153 test = create_tool_window( WS_CHILD, child );
154 trace( "created child of child %p\n", test );
155 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
156 SetWindowLongA( test, GWL_STYLE, 0 );
157 check_parents( test, child, child, 0, 0, hwndMain, test );
158 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
159 check_parents( test, child, child, 0, 0, hwndMain, test );
160 DestroyWindow( test );
162 /* child of child with WS_MAXIMIZE */
163 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
164 DestroyWindow( test );
166 /* child of child with WS_MINIMIZE */
167 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
168 DestroyWindow( test );
170 /* not owned top-level window */
171 test = create_tool_window( 0, 0 );
172 trace( "created top-level %p\n", test );
173 check_parents( test, desktop, 0, 0, 0, test, test );
174 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
175 check_parents( test, desktop, 0, 0, 0, test, test );
176 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
177 check_parents( test, desktop, 0, desktop, 0, test, desktop );
178 DestroyWindow( test );
180 /* not owned top-level window with WS_MAXIMIZE */
181 test = create_tool_window( WS_MAXIMIZE, 0 );
182 DestroyWindow( test );
184 /* owned top-level window */
185 test = create_tool_window( 0, hwndMain );
186 trace( "created owned top-level %p\n", test );
187 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
188 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
189 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
190 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
191 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
192 DestroyWindow( test );
194 /* owned top-level window with WS_MAXIMIZE */
195 test = create_tool_window( WS_MAXIMIZE, hwndMain );
196 DestroyWindow( test );
198 /* not owned popup */
199 test = create_tool_window( WS_POPUP, 0 );
200 trace( "created popup %p\n", test );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
203 check_parents( test, desktop, 0, desktop, 0, test, desktop );
204 SetWindowLongA( test, GWL_STYLE, 0 );
205 check_parents( test, desktop, 0, 0, 0, test, test );
206 DestroyWindow( test );
208 /* not owned popup with WS_MAXIMIZE */
209 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
210 DestroyWindow( test );
213 test = create_tool_window( WS_POPUP, hwndMain );
214 trace( "created owned popup %p\n", test );
215 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
216 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
217 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
218 SetWindowLongA( test, GWL_STYLE, 0 );
219 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
220 DestroyWindow( test );
222 /* owned popup with WS_MAXIMIZE */
223 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
224 DestroyWindow( test );
226 /* top-level window owned by child (same as owned by top-level) */
227 test = create_tool_window( 0, child );
228 trace( "created top-level owned by child %p\n", test );
229 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
230 DestroyWindow( test );
232 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
233 test = create_tool_window( WS_MAXIMIZE, child );
234 DestroyWindow( test );
236 /* popup owned by desktop (same as not owned) */
237 test = create_tool_window( WS_POPUP, desktop );
238 trace( "created popup owned by desktop %p\n", test );
239 check_parents( test, desktop, 0, 0, 0, test, test );
240 DestroyWindow( test );
242 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
243 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
244 DestroyWindow( test );
246 /* popup owned by child (same as owned by top-level) */
247 test = create_tool_window( WS_POPUP, child );
248 trace( "created popup owned by child %p\n", test );
249 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
250 DestroyWindow( test );
252 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
253 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
254 DestroyWindow( test );
256 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
257 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
258 trace( "created WS_CHILD popup %p\n", test );
259 check_parents( test, desktop, 0, 0, 0, test, test );
260 DestroyWindow( test );
262 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
263 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
264 DestroyWindow( test );
266 /* owned popup with WS_CHILD (same as WS_POPUP only) */
267 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
268 trace( "created owned WS_CHILD popup %p\n", test );
269 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
270 DestroyWindow( test );
272 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
273 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
274 DestroyWindow( test );
276 /******************** parent changes *************************/
277 trace( "testing parent changes\n" );
280 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
281 #if 0 /* this test succeeds on NT but crashes on win9x systems */
282 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
283 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
284 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
285 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
286 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
288 /* normal child window */
289 test = create_tool_window( WS_CHILD, hwndMain );
290 trace( "created child %p\n", test );
292 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
293 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
294 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
296 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
297 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
298 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
300 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
301 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
302 check_parents( test, desktop, 0, desktop, 0, test, desktop );
304 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
305 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
306 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
307 check_parents( test, desktop, child, desktop, child, test, desktop );
309 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
310 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
311 check_parents( test, desktop, 0, desktop, 0, test, desktop );
312 DestroyWindow( test );
314 /* not owned top-level window */
315 test = create_tool_window( 0, 0 );
316 trace( "created top-level %p\n", test );
318 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
319 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
320 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
322 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
323 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
324 check_parents( test, desktop, child, 0, child, test, test );
326 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
327 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
328 check_parents( test, desktop, 0, 0, 0, test, test );
329 DestroyWindow( test );
331 /* not owned popup */
332 test = create_tool_window( WS_POPUP, 0 );
333 trace( "created popup %p\n", test );
335 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
336 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
337 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
339 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
340 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
341 check_parents( test, desktop, child, child, child, test, hwndMain );
343 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
344 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
345 check_parents( test, desktop, 0, 0, 0, test, test );
346 DestroyWindow( test );
348 /* normal child window */
349 test = create_tool_window( WS_CHILD, hwndMain );
350 trace( "created child %p\n", test );
352 ret = SetParent( test, desktop );
353 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
354 check_parents( test, desktop, 0, desktop, 0, test, desktop );
356 ret = SetParent( test, child );
357 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
358 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
360 ret = SetParent( test, hwndMain2 );
361 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
362 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
363 DestroyWindow( test );
365 /* not owned top-level window */
366 test = create_tool_window( 0, 0 );
367 trace( "created top-level %p\n", test );
369 ret = SetParent( test, child );
370 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
371 check_parents( test, child, child, 0, 0, hwndMain, test );
372 DestroyWindow( test );
375 test = create_tool_window( WS_POPUP, hwndMain2 );
376 trace( "created owned popup %p\n", test );
378 ret = SetParent( test, child );
379 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
380 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
382 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
383 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
384 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
385 DestroyWindow( test );
387 /**************** test owner destruction *******************/
389 /* owned child popup */
390 owner = create_tool_window( 0, 0 );
391 test = create_tool_window( WS_POPUP, owner );
392 trace( "created owner %p and popup %p\n", owner, test );
393 ret = SetParent( test, child );
394 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
395 check_parents( test, child, child, owner, owner, hwndMain, owner );
396 /* window is now child of 'child' but owned by 'owner' */
397 DestroyWindow( owner );
398 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
399 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
400 * while Win95, Win2k, WinXP do.
402 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
403 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
406 /* owned top-level popup */
407 owner = create_tool_window( 0, 0 );
408 test = create_tool_window( WS_POPUP, owner );
409 trace( "created owner %p and popup %p\n", owner, test );
410 check_parents( test, desktop, owner, owner, owner, test, owner );
411 DestroyWindow( owner );
412 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
414 /* top-level popup owned by child */
415 owner = create_tool_window( WS_CHILD, hwndMain2 );
416 test = create_tool_window( WS_POPUP, 0 );
417 trace( "created owner %p and popup %p\n", owner, test );
418 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
419 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
420 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
421 DestroyWindow( owner );
422 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
423 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
424 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
425 * while Win95, Win2k, WinXP do.
427 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
431 DestroyWindow(child);
435 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
439 case WM_GETMINMAXINFO:
441 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
443 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
444 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
445 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
446 minmax->ptReserved.x, minmax->ptReserved.y,
447 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
448 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
449 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
450 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
451 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
454 case WM_WINDOWPOSCHANGING:
456 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
457 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
458 trace("main: WM_WINDOWPOSCHANGING\n");
459 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
460 winpos->hwnd, winpos->hwndInsertAfter,
461 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
462 if (!(winpos->flags & SWP_NOMOVE))
464 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
465 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
467 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
468 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
470 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
471 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
475 case WM_WINDOWPOSCHANGED:
478 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
479 trace("main: WM_WINDOWPOSCHANGED\n");
480 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
481 winpos->hwnd, winpos->hwndInsertAfter,
482 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
483 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
484 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
486 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
487 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
489 GetWindowRect(hwnd, &rc1);
490 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
491 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
492 /* note: winpos coordinates are relative to parent */
493 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
494 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
495 #if 0 /* Uncomment this once the test succeeds in all cases */
496 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
499 GetClientRect(hwnd, &rc2);
500 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
501 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
502 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
507 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
508 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
510 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
511 if (got_getminmaxinfo)
512 trace("%p got WM_GETMINMAXINFO\n", hwnd);
514 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
515 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
517 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
522 return DefWindowProcA(hwnd, msg, wparam, lparam);
525 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
529 case WM_GETMINMAXINFO:
531 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
533 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
534 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
535 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
536 minmax->ptReserved.x, minmax->ptReserved.y,
537 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
538 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
539 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
540 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
541 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
546 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
547 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
549 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
550 if (got_getminmaxinfo)
551 trace("%p got WM_GETMINMAXINFO\n", hwnd);
553 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
554 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
556 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
561 return DefWindowProcA(hwnd, msg, wparam, lparam);
564 static BOOL RegisterWindowClasses(void)
569 cls.lpfnWndProc = main_window_procA;
572 cls.hInstance = GetModuleHandleA(0);
574 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
575 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
576 cls.lpszMenuName = NULL;
577 cls.lpszClassName = "MainWindowClass";
579 if(!RegisterClassA(&cls)) return FALSE;
582 cls.lpfnWndProc = tool_window_procA;
585 cls.hInstance = GetModuleHandleA(0);
587 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
588 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
589 cls.lpszMenuName = NULL;
590 cls.lpszClassName = "ToolWindowClass";
592 if(!RegisterClassA(&cls)) return FALSE;
597 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
599 RECT rcWindow, rcClient;
603 ok(IsWindow(hwnd), "bad window handle\n");
605 GetWindowRect(hwnd, &rcWindow);
606 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
608 GetClientRect(hwnd, &rcClient);
609 /* translate to screen coordinates */
610 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
611 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
613 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE), "wrong dwStyle\n");
614 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE), "wrong dwExStyle\n");
615 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
616 ok(info->dwWindowStatus == status, "wrong dwWindowStatus\n");
618 if (test_borders && !IsRectEmpty(&rcWindow))
620 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
621 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
623 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
624 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
625 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
626 ok(info->cyWindowBorders == border,
627 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
630 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
631 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
634 static void test_nonclient_area(HWND hwnd)
636 DWORD style, exstyle;
637 RECT rc_window, rc_client, rc;
640 style = GetWindowLongA(hwnd, GWL_STYLE);
641 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
642 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
644 GetWindowRect(hwnd, &rc_window);
645 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
646 GetClientRect(hwnd, &rc_client);
647 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
649 /* avoid some cases when things go wrong */
650 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
651 rc_window.right > 32768 || rc_window.bottom > 32768) return;
653 CopyRect(&rc, &rc_client);
654 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
655 AdjustWindowRectEx(&rc, style, menu, exstyle);
656 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
657 #if 0 /* Uncomment this once the test succeeds in all cases */
658 ok(EqualRect(&rc, &rc_window), "window rect does not match\n");
661 CopyRect(&rc, &rc_window);
662 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
663 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
664 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
665 #if 0 /* Uncomment this once the test succeeds in all cases */
666 ok(EqualRect(&rc, &rc_client), "client rect does not match\n");
669 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
670 SetRect(&rc_client, 0, 0, 250, 150);
671 CopyRect(&rc_window, &rc_client);
672 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
673 AdjustWindowRectEx(&rc_window, style, menu, exstyle);
674 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
675 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
677 CopyRect(&rc, &rc_window);
678 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
679 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
680 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
681 #if 0 /* Uncomment this once the test succeeds in all cases */
682 ok(EqualRect(&rc, &rc_client), "client rect does not match\n");
686 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
688 static const char *CBT_code_name[10] = {
699 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
701 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
703 /* on HCBT_DESTROYWND window state is undefined */
704 if (nCode != HCBT_DESTROYWND && wParam)
706 BOOL is_win9x = GetWindowLongW((HWND)wParam, GWL_WNDPROC) == 0;
707 if (is_win9x && nCode == HCBT_CREATEWND)
708 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
710 test_nonclient_area((HWND)wParam);
716 /* Win98 actually does check the info.cbSize and doesn't allow
717 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
718 * WinXP do not check it at all.
720 info.cbSize = sizeof(WINDOWINFO);
721 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
722 /* win2k SP4 returns broken border info if GetWindowInfo
723 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
725 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
733 #if 0 /* Uncomment this once the test succeeds in all cases */
734 static const RECT rc_null;
738 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
739 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
740 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
741 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
743 /* WS_VISIBLE should be turned off yet */
744 style = createwnd->lpcs->style & ~WS_VISIBLE;
745 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
746 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
747 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
749 #if 0 /* Uncomment this once the test succeeds in all cases */
750 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
752 ok(GetParent((HWND)wParam) == hwndMessage,
753 "wrong result from GetParent %p: message window %p\n",
754 GetParent((HWND)wParam), hwndMessage);
757 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
759 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
761 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
762 * Win9x still has them set to 0.
764 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
765 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
767 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
768 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
770 #if 0 /* Uncomment this once the test succeeds in all cases */
773 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
774 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
775 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
777 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
778 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
779 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
781 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
782 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
785 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
786 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
787 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
788 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
794 return CallNextHookEx(hhook, nCode, wParam, lParam);
797 static void test_shell_window()
801 HMODULE hinst, hUser32;
802 BOOL (WINAPI*SetShellWindow)(HWND);
803 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
804 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
805 HWND shellWindow, nextWnd;
807 shellWindow = GetShellWindow();
808 hinst = GetModuleHandle(0);
809 hUser32 = GetModuleHandleA("user32");
811 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
812 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
814 trace("previous shell window: %p\n", shellWindow);
817 ret = DestroyWindow(shellWindow);
818 error = GetLastError();
820 ok(!ret, "DestroyWindow(shellWindow)\n");
821 /* passes on Win XP, but not on Win98
822 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n"); */
825 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
826 trace("created window 1: %p\n", hwnd1);
828 ret = SetShellWindow(hwnd1);
829 ok(ret, "first call to SetShellWindow(hwnd1)\n");
830 shellWindow = GetShellWindow();
831 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
833 ret = SetShellWindow(hwnd1);
834 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
836 ret = SetShellWindow(0);
837 error = GetLastError();
838 /* passes on Win XP, but not on Win98
839 ok(!ret, "reset shell window by SetShellWindow(0)\n");
840 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
842 ret = SetShellWindow(hwnd1);
843 /* passes on Win XP, but not on Win98
844 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
848 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
849 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
850 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
853 ret = DestroyWindow(hwnd1);
854 ok(ret, "DestroyWindow(hwnd1)\n");
856 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
857 trace("created window 2: %p\n", hwnd2);
858 ret = SetShellWindow(hwnd2);
859 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
861 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
862 trace("created window 3: %p\n", hwnd3);
864 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
865 trace("created window 4: %p\n", hwnd4);
867 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
868 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
870 ret = SetShellWindow(hwnd4);
871 ok(ret, "SetShellWindow(hwnd4)\n");
872 shellWindow = GetShellWindow();
873 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
875 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
876 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
878 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
879 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
881 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
882 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
884 ret = SetShellWindow(hwnd3);
885 ok(!ret, "SetShellWindow(hwnd3)\n");
886 shellWindow = GetShellWindow();
887 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
889 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
890 trace("created window 5: %p\n", hwnd5);
891 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
892 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
896 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
897 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
900 /* destroy test windows */
901 DestroyWindow(hwnd2);
902 DestroyWindow(hwnd3);
903 DestroyWindow(hwnd4);
904 DestroyWindow(hwnd5);
907 /************** MDI test ****************/
909 static const char mdi_lParam_test_message[] = "just a test string";
911 static void test_MDI_create(HWND parent, HWND mdi_client)
913 MDICREATESTRUCTA mdi_cs;
915 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
916 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
917 BOOL isWin9x = FALSE;
919 mdi_cs.szClass = "MDI_child_Class_1";
920 mdi_cs.szTitle = "MDI child";
921 mdi_cs.hOwner = GetModuleHandle(0);
922 mdi_cs.x = CW_USEDEFAULT;
923 mdi_cs.y = CW_USEDEFAULT;
924 mdi_cs.cx = CW_USEDEFAULT;
925 mdi_cs.cy = CW_USEDEFAULT;
927 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
928 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
929 ok(mdi_child != 0, "MDI child creation failed\n");
930 DestroyWindow(mdi_child);
932 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
933 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
934 ok(mdi_child != 0, "MDI child creation failed\n");
935 DestroyWindow(mdi_child);
937 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
938 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
939 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
941 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
942 DestroyWindow(mdi_child);
945 ok(mdi_child != 0, "MDI child creation failed\n");
947 /* test MDICREATESTRUCT A<->W mapping */
948 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
950 mdi_cs.szClass = (LPCSTR)classW;
951 mdi_cs.szTitle = (LPCSTR)titleW;
952 SetLastError(0xdeadbeef);
953 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
956 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
959 ok(mdi_child != 0, "MDI child creation failed\n");
961 DestroyWindow(mdi_child);
963 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
965 CW_USEDEFAULT, CW_USEDEFAULT,
966 CW_USEDEFAULT, CW_USEDEFAULT,
967 mdi_client, GetModuleHandle(0),
968 (LPARAM)mdi_lParam_test_message);
969 ok(mdi_child != 0, "MDI child creation failed\n");
970 DestroyWindow(mdi_child);
972 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
973 0x7fffffff, /* without WS_POPUP */
974 CW_USEDEFAULT, CW_USEDEFAULT,
975 CW_USEDEFAULT, CW_USEDEFAULT,
976 mdi_client, GetModuleHandle(0),
977 (LPARAM)mdi_lParam_test_message);
978 ok(mdi_child != 0, "MDI child creation failed\n");
979 DestroyWindow(mdi_child);
981 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
982 0xffffffff, /* with WS_POPUP */
983 CW_USEDEFAULT, CW_USEDEFAULT,
984 CW_USEDEFAULT, CW_USEDEFAULT,
985 mdi_client, GetModuleHandle(0),
986 (LPARAM)mdi_lParam_test_message);
987 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
989 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
990 DestroyWindow(mdi_child);
993 ok(mdi_child != 0, "MDI child creation failed\n");
995 /* test MDICREATESTRUCT A<->W mapping */
996 SetLastError(0xdeadbeef);
997 mdi_child = CreateMDIWindowW(classW, titleW,
999 CW_USEDEFAULT, CW_USEDEFAULT,
1000 CW_USEDEFAULT, CW_USEDEFAULT,
1001 mdi_client, GetModuleHandle(0),
1002 (LPARAM)mdi_lParam_test_message);
1005 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1008 ok(mdi_child != 0, "MDI child creation failed\n");
1010 DestroyWindow(mdi_child);
1012 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1014 CW_USEDEFAULT, CW_USEDEFAULT,
1015 CW_USEDEFAULT, CW_USEDEFAULT,
1016 mdi_client, 0, GetModuleHandle(0),
1017 (LPVOID)mdi_lParam_test_message);
1018 ok(mdi_child != 0, "MDI child creation failed\n");
1019 DestroyWindow(mdi_child);
1021 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1022 0x7fffffff, /* without WS_POPUP */
1023 CW_USEDEFAULT, CW_USEDEFAULT,
1024 CW_USEDEFAULT, CW_USEDEFAULT,
1025 mdi_client, 0, GetModuleHandle(0),
1026 (LPVOID)mdi_lParam_test_message);
1027 ok(mdi_child != 0, "MDI child creation failed\n");
1028 DestroyWindow(mdi_child);
1030 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1031 0xffffffff, /* with WS_POPUP */
1032 CW_USEDEFAULT, CW_USEDEFAULT,
1033 CW_USEDEFAULT, CW_USEDEFAULT,
1034 mdi_client, 0, GetModuleHandle(0),
1035 (LPVOID)mdi_lParam_test_message);
1036 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1038 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1039 DestroyWindow(mdi_child);
1042 ok(mdi_child != 0, "MDI child creation failed\n");
1044 /* test MDICREATESTRUCT A<->W mapping */
1045 SetLastError(0xdeadbeef);
1046 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1048 CW_USEDEFAULT, CW_USEDEFAULT,
1049 CW_USEDEFAULT, CW_USEDEFAULT,
1050 mdi_client, 0, GetModuleHandle(0),
1051 (LPVOID)mdi_lParam_test_message);
1054 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1057 ok(mdi_child != 0, "MDI child creation failed\n");
1059 DestroyWindow(mdi_child);
1061 /* This test fails on Win9x */
1064 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1066 CW_USEDEFAULT, CW_USEDEFAULT,
1067 CW_USEDEFAULT, CW_USEDEFAULT,
1068 parent, 0, GetModuleHandle(0),
1069 (LPVOID)mdi_lParam_test_message);
1070 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1073 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1074 WS_CHILD, /* without WS_POPUP */
1075 CW_USEDEFAULT, CW_USEDEFAULT,
1076 CW_USEDEFAULT, CW_USEDEFAULT,
1077 mdi_client, 0, GetModuleHandle(0),
1078 (LPVOID)mdi_lParam_test_message);
1079 ok(mdi_child != 0, "MDI child creation failed\n");
1080 DestroyWindow(mdi_child);
1082 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1083 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1084 CW_USEDEFAULT, CW_USEDEFAULT,
1085 CW_USEDEFAULT, CW_USEDEFAULT,
1086 mdi_client, 0, GetModuleHandle(0),
1087 (LPVOID)mdi_lParam_test_message);
1088 ok(mdi_child != 0, "MDI child creation failed\n");
1089 DestroyWindow(mdi_child);
1091 /* maximized child */
1092 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1093 WS_CHILD | WS_MAXIMIZE,
1094 CW_USEDEFAULT, CW_USEDEFAULT,
1095 CW_USEDEFAULT, CW_USEDEFAULT,
1096 mdi_client, 0, GetModuleHandle(0),
1097 (LPVOID)mdi_lParam_test_message);
1098 ok(mdi_child != 0, "MDI child creation failed\n");
1099 DestroyWindow(mdi_child);
1101 trace("Creating maximized child with a caption\n");
1102 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1103 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1104 CW_USEDEFAULT, CW_USEDEFAULT,
1105 CW_USEDEFAULT, CW_USEDEFAULT,
1106 mdi_client, 0, GetModuleHandle(0),
1107 (LPVOID)mdi_lParam_test_message);
1108 ok(mdi_child != 0, "MDI child creation failed\n");
1109 DestroyWindow(mdi_child);
1111 trace("Creating maximized child with a caption and a thick frame\n");
1112 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1113 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1114 CW_USEDEFAULT, CW_USEDEFAULT,
1115 CW_USEDEFAULT, CW_USEDEFAULT,
1116 mdi_client, 0, GetModuleHandle(0),
1117 (LPVOID)mdi_lParam_test_message);
1118 ok(mdi_child != 0, "MDI child creation failed\n");
1119 DestroyWindow(mdi_child);
1122 /**********************************************************************
1123 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1125 * Note: The rule here is that client rect of the maximized MDI child
1126 * is equal to the client rect of the MDI client window.
1128 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1132 GetClientRect( client, &rect );
1133 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1134 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1136 rect.right -= rect.left;
1137 rect.bottom -= rect.top;
1138 lpMinMax->ptMaxSize.x = rect.right;
1139 lpMinMax->ptMaxSize.y = rect.bottom;
1141 lpMinMax->ptMaxPosition.x = rect.left;
1142 lpMinMax->ptMaxPosition.y = rect.top;
1144 trace("max rect (%ld,%ld - %ld, %ld)\n",
1145 rect.left, rect.top, rect.right, rect.bottom);
1148 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1155 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1156 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1158 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1159 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1161 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1162 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1163 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1164 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1165 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1167 /* MDICREATESTRUCT should have original values */
1168 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1169 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1170 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1171 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1172 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1173 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1175 /* CREATESTRUCT should have fixed values */
1176 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1177 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1179 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1180 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1181 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1183 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1185 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1187 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1188 ok(cs->style == style,
1189 "cs->style does not match (%08lx)\n", cs->style);
1193 LONG style = mdi_cs->style;
1195 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1196 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1197 ok(cs->style == style,
1198 "cs->style does not match (%08lx)\n", cs->style);
1203 case WM_GETMINMAXINFO:
1205 HWND client = GetParent(hwnd);
1207 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1208 MINMAXINFO my_minmax;
1209 LONG style, exstyle;
1211 style = GetWindowLongA(hwnd, GWL_STYLE);
1212 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1214 GetWindowRect(client, &rc);
1215 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1216 GetClientRect(client, &rc);
1217 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1218 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1219 GetSystemMetrics(SM_CYSCREEN));
1221 GetClientRect(client, &rc);
1222 if ((style & WS_CAPTION) == WS_CAPTION)
1223 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1224 AdjustWindowRectEx(&rc, style, 0, exstyle);
1225 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1227 trace("ptReserved = (%ld,%ld)\n"
1228 "ptMaxSize = (%ld,%ld)\n"
1229 "ptMaxPosition = (%ld,%ld)\n"
1230 "ptMinTrackSize = (%ld,%ld)\n"
1231 "ptMaxTrackSize = (%ld,%ld)\n",
1232 minmax->ptReserved.x, minmax->ptReserved.y,
1233 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1234 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1235 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1236 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1238 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1239 minmax->ptMaxSize.x, rc.right - rc.left);
1240 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1241 minmax->ptMaxSize.y, rc.bottom - rc.top);
1243 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1245 trace("DefMDIChildProc returned:\n"
1246 "ptReserved = (%ld,%ld)\n"
1247 "ptMaxSize = (%ld,%ld)\n"
1248 "ptMaxPosition = (%ld,%ld)\n"
1249 "ptMinTrackSize = (%ld,%ld)\n"
1250 "ptMaxTrackSize = (%ld,%ld)\n",
1251 minmax->ptReserved.x, minmax->ptReserved.y,
1252 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1253 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1254 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1255 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1257 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1258 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1259 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1260 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1261 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1266 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1269 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1276 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1278 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1279 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1281 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1282 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1284 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1285 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1287 /* CREATESTRUCT should have fixed values */
1288 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1290 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1291 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1293 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1294 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1295 while Win95, Win2k, WinXP do. */
1296 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1297 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1301 case WM_GETMINMAXINFO:
1303 HWND parent = GetParent(hwnd);
1305 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1306 LONG style, exstyle;
1308 trace("WM_GETMINMAXINFO\n");
1310 style = GetWindowLongA(hwnd, GWL_STYLE);
1311 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1313 GetClientRect(parent, &rc);
1314 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1316 GetClientRect(parent, &rc);
1317 if ((style & WS_CAPTION) == WS_CAPTION)
1318 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1319 AdjustWindowRectEx(&rc, style, 0, exstyle);
1320 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1322 trace("ptReserved = (%ld,%ld)\n"
1323 "ptMaxSize = (%ld,%ld)\n"
1324 "ptMaxPosition = (%ld,%ld)\n"
1325 "ptMinTrackSize = (%ld,%ld)\n"
1326 "ptMaxTrackSize = (%ld,%ld)\n",
1327 minmax->ptReserved.x, minmax->ptReserved.y,
1328 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1329 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1330 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1331 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1333 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1334 minmax->ptMaxSize.x, rc.right - rc.left);
1335 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1336 minmax->ptMaxSize.y, rc.bottom - rc.top);
1340 case WM_WINDOWPOSCHANGED:
1342 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1345 GetWindowRect(hwnd, &rc1);
1346 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1347 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1348 /* note: winpos coordinates are relative to parent */
1349 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1350 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1351 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1353 GetWindowRect(hwnd, &rc1);
1354 GetClientRect(hwnd, &rc2);
1355 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1356 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1357 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1360 case WM_WINDOWPOSCHANGING:
1362 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1363 WINDOWPOS my_winpos = *winpos;
1365 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1366 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1367 winpos->hwnd, winpos->hwndInsertAfter,
1368 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1370 DefWindowProcA(hwnd, msg, wparam, lparam);
1372 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1373 winpos->hwnd, winpos->hwndInsertAfter,
1374 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1376 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1377 "DefWindowProc should not change WINDOWPOS values\n");
1382 return DefWindowProcA(hwnd, msg, wparam, lparam);
1385 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1387 static HWND mdi_client;
1393 CLIENTCREATESTRUCT client_cs;
1396 GetClientRect(hwnd, &rc);
1398 client_cs.hWindowMenu = 0;
1399 client_cs.idFirstChild = 1;
1401 /* MDIClient without MDIS_ALLCHILDSTYLES */
1402 mdi_client = CreateWindowExA(0, "mdiclient",
1404 WS_CHILD /*| WS_VISIBLE*/,
1405 /* tests depend on a not zero MDIClient size */
1406 0, 0, rc.right, rc.bottom,
1407 hwnd, 0, GetModuleHandle(0),
1408 (LPVOID)&client_cs);
1410 test_MDI_create(hwnd, mdi_client);
1411 DestroyWindow(mdi_client);
1413 /* MDIClient with MDIS_ALLCHILDSTYLES */
1414 mdi_client = CreateWindowExA(0, "mdiclient",
1416 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1417 /* tests depend on a not zero MDIClient size */
1418 0, 0, rc.right, rc.bottom,
1419 hwnd, 0, GetModuleHandle(0),
1420 (LPVOID)&client_cs);
1422 test_MDI_create(hwnd, mdi_client);
1423 DestroyWindow(mdi_client);
1427 case WM_WINDOWPOSCHANGED:
1429 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1432 GetWindowRect(hwnd, &rc1);
1433 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1434 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1435 /* note: winpos coordinates are relative to parent */
1436 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1437 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1438 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1440 GetWindowRect(hwnd, &rc1);
1441 GetClientRect(hwnd, &rc2);
1442 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1443 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1444 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1447 case WM_WINDOWPOSCHANGING:
1449 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1450 WINDOWPOS my_winpos = *winpos;
1452 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1453 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1454 winpos->hwnd, winpos->hwndInsertAfter,
1455 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1457 DefWindowProcA(hwnd, msg, wparam, lparam);
1459 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1460 winpos->hwnd, winpos->hwndInsertAfter,
1461 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1463 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1464 "DefWindowProc should not change WINDOWPOS values\n");
1473 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1476 static BOOL mdi_RegisterWindowClasses(void)
1481 cls.lpfnWndProc = mdi_main_wnd_procA;
1484 cls.hInstance = GetModuleHandleA(0);
1486 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1487 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1488 cls.lpszMenuName = NULL;
1489 cls.lpszClassName = "MDI_parent_Class";
1490 if(!RegisterClassA(&cls)) return FALSE;
1492 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1493 cls.lpszClassName = "MDI_child_Class_1";
1494 if(!RegisterClassA(&cls)) return FALSE;
1496 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1497 cls.lpszClassName = "MDI_child_Class_2";
1498 if(!RegisterClassA(&cls)) return FALSE;
1503 static void test_mdi(void)
1508 if (!mdi_RegisterWindowClasses()) assert(0);
1510 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1511 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1512 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1513 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1514 GetDesktopWindow(), 0,
1515 GetModuleHandle(0), NULL);
1516 assert(mdi_hwndMain);
1518 while(GetMessage(&msg, 0, 0, 0))
1520 TranslateMessage(&msg);
1521 DispatchMessage(&msg);
1526 static void test_icons(void)
1530 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1531 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1532 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1533 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1536 cls.cbSize = sizeof(cls);
1538 cls.lpfnWndProc = DefWindowProcA;
1542 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1543 cls.hIconSm = small_icon;
1544 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1545 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1546 cls.lpszMenuName = NULL;
1547 cls.lpszClassName = "IconWindowClass";
1549 RegisterClassExA(&cls);
1551 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1552 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1555 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1556 ok( res == 0, "wrong big icon %p/0\n", res );
1557 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1558 ok( res == 0, "wrong previous big icon %p/0\n", res );
1559 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1560 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1561 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1562 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1563 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1564 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1566 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1567 ok( res == 0, "wrong small icon %p/0\n", res );
1568 /* this test is XP specific */
1569 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1570 ok( res != 0, "wrong small icon %p\n", res );*/
1571 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1572 ok( res == 0, "wrong previous small icon %p/0\n", res );
1573 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1574 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1575 /* this test is XP specific */
1576 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1577 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1578 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1579 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1580 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1581 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1582 /* this test is XP specific */
1583 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1584 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1586 /* make sure the big icon hasn't changed */
1587 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1588 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1591 static void test_SetWindowPos(HWND hwnd)
1593 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
1595 /* Win9x truncates coordinates to 16-bit irrespectively */
1596 if (is_win9x) return;
1598 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1599 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1601 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1602 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1605 static void test_SetMenu(HWND parent)
1609 BOOL is_win9x = GetWindowLongW(parent, GWL_WNDPROC) == 0;
1611 hMenu = CreateMenu();
1614 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1615 test_nonclient_area(parent);
1616 ret = GetMenu(parent);
1617 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1618 /* test whether we can destroy a menu assigned to a window */
1619 ok(DestroyMenu(hMenu), "DestroyMenu error %ld\n", GetLastError());
1620 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1621 ret = GetMenu(parent);
1622 /* This test fails on Win9x */
1624 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1625 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1626 test_nonclient_area(parent);
1628 hMenu = CreateMenu();
1632 ret = GetMenu(parent);
1633 ok(ret == 0, "unexpected menu id %p\n", ret);
1635 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1636 test_nonclient_area(parent);
1637 ret = GetMenu(parent);
1638 ok(ret == 0, "unexpected menu id %p\n", ret);
1640 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1641 test_nonclient_area(parent);
1642 ret = GetMenu(parent);
1643 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1645 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1646 test_nonclient_area(parent);
1647 ret = GetMenu(parent);
1648 ok(ret == 0, "unexpected menu id %p\n", ret);
1651 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1654 ret = GetMenu(child);
1655 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1657 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1658 test_nonclient_area(child);
1659 ret = GetMenu(child);
1660 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1662 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1663 test_nonclient_area(child);
1664 ret = GetMenu(child);
1665 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1667 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1668 test_nonclient_area(child);
1669 ret = GetMenu(child);
1670 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1672 DestroyWindow(child);
1676 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1678 HWND child[5], hwnd;
1683 hwnd = GetWindow(parent, GW_CHILD);
1684 ok(!hwnd, "have to start without children to perform the test\n");
1686 for (i = 0; i < total; i++)
1688 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1689 parent, 0, 0, NULL);
1690 trace("child[%d] = %p\n", i, child[i]);
1691 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1694 hwnd = GetWindow(parent, GW_CHILD);
1695 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1696 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1697 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1699 for (i = 0; i < total; i++)
1701 trace("hwnd[%d] = %p\n", i, hwnd);
1702 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1704 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1707 for (i = 0; i < total; i++)
1708 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1711 static void test_children_zorder(HWND parent)
1713 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1715 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1717 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1718 WS_CHILD | WS_VISIBLE, WS_CHILD,
1719 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1720 const int complex_order_1[1] = { 0 };
1721 const int complex_order_2[2] = { 1, 0 };
1722 const int complex_order_3[3] = { 1, 0, 2 };
1723 const int complex_order_4[4] = { 1, 0, 2, 3 };
1724 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1726 /* simple WS_CHILD */
1727 test_window_tree(parent, simple_style, simple_order, 5);
1729 /* complex children styles */
1730 test_window_tree(parent, complex_style, complex_order_1, 1);
1731 test_window_tree(parent, complex_style, complex_order_2, 2);
1732 test_window_tree(parent, complex_style, complex_order_3, 3);
1733 test_window_tree(parent, complex_style, complex_order_4, 4);
1734 test_window_tree(parent, complex_style, complex_order_5, 5);
1737 static void test_SetFocus(HWND hwnd)
1741 /* check if we can set focus to non-visible windows */
1743 ShowWindow(hwnd, SW_SHOW);
1746 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1747 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1748 ShowWindow(hwnd, SW_HIDE);
1751 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1752 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1753 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1756 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1757 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1758 ShowWindow(child, SW_SHOW);
1759 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1760 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1761 ShowWindow(child, SW_HIDE);
1762 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1763 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1764 ShowWindow(child, SW_SHOW);
1766 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1767 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1768 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1770 ShowWindow(child, SW_HIDE);
1772 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1773 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1774 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1775 ShowWindow(child, SW_HIDE);
1776 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1778 ShowWindow(hwnd, SW_SHOW);
1779 ShowWindow(child, SW_SHOW);
1781 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1782 EnableWindow(hwnd, FALSE);
1783 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1784 EnableWindow(hwnd, TRUE);
1786 DestroyWindow( child );
1789 static void test_SetActiveWindow(HWND hwnd)
1793 ShowWindow(hwnd, SW_SHOW);
1795 SetActiveWindow(hwnd);
1796 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1797 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1798 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1799 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1800 ShowWindow(hwnd, SW_HIDE);
1801 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1802 ShowWindow(hwnd, SW_SHOW);
1804 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1805 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1806 DestroyWindow(hwnd2);
1807 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1809 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1810 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1811 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1812 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1813 DestroyWindow(hwnd2);
1814 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1817 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
1819 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1821 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1822 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
1823 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
1826 static WNDPROC old_button_proc;
1828 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
1833 key_state = GetKeyState(VK_LBUTTON);
1834 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
1836 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
1838 if (msg == WM_LBUTTONDOWN)
1842 check_wnd_state(button, button, button, button);
1844 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1846 trace("hwnd %p\n", hwnd);
1848 check_wnd_state(button, button, button, button);
1850 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1852 check_wnd_state(button, button, button, button);
1854 DestroyWindow(hwnd);
1856 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1858 trace("hwnd %p\n", hwnd);
1860 check_wnd_state(button, button, button, button);
1862 /* button wnd proc should release capture on WM_KILLFOCUS if it does
1863 * match internal button state.
1865 SendMessage(button, WM_KILLFOCUS, 0, 0);
1866 check_wnd_state(button, button, button, 0);
1868 ShowWindow(hwnd, SW_SHOW);
1869 check_wnd_state(hwnd, hwnd, hwnd, 0);
1871 capture = SetCapture(hwnd);
1872 ok(capture == 0, "SetCapture() = %p\n", capture);
1874 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1876 DestroyWindow(hwnd);
1878 check_wnd_state(button, 0, button, 0);
1884 static void test_capture_1(void)
1886 HWND button, capture;
1888 capture = GetCapture();
1889 ok(capture == 0, "GetCapture() = %p\n", capture);
1891 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1893 trace("button %p\n", button);
1895 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
1897 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
1899 DestroyWindow(button);
1902 static void test_capture_2(void)
1904 HWND button, hwnd, capture;
1906 check_wnd_state(0, 0, 0, 0);
1908 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1910 trace("button %p\n", button);
1912 check_wnd_state(button, button, button, 0);
1914 capture = SetCapture(button);
1915 ok(capture == 0, "SetCapture() = %p\n", capture);
1917 check_wnd_state(button, button, button, button);
1919 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
1920 * internal button state.
1922 SendMessage(button, WM_KILLFOCUS, 0, 0);
1923 check_wnd_state(button, button, button, button);
1925 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1927 trace("hwnd %p\n", hwnd);
1929 check_wnd_state(button, button, button, button);
1931 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1933 check_wnd_state(button, button, button, button);
1935 DestroyWindow(hwnd);
1937 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1939 trace("hwnd %p\n", hwnd);
1941 check_wnd_state(button, button, button, button);
1943 ShowWindow(hwnd, SW_SHOW);
1945 check_wnd_state(hwnd, hwnd, hwnd, button);
1947 capture = SetCapture(hwnd);
1948 ok(capture == button, "SetCapture() = %p\n", capture);
1950 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1952 DestroyWindow(hwnd);
1953 check_wnd_state(button, button, button, 0);
1955 DestroyWindow(button);
1956 check_wnd_state(0, 0, 0, 0);
1959 static void test_capture_3(HWND hwnd1, HWND hwnd2)
1961 ShowWindow(hwnd1, SW_HIDE);
1962 ShowWindow(hwnd2, SW_HIDE);
1964 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
1965 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
1968 check_wnd_state(0, 0, 0, hwnd1);
1971 check_wnd_state(0, 0, 0, hwnd2);
1973 ShowWindow(hwnd1, SW_SHOW);
1974 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
1979 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
1980 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
1982 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
1985 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
1988 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
1989 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
1990 trace("hwndMessage %p\n", hwndMessage);
1992 DestroyWindow(hwndMain);
1995 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
1997 if (!RegisterWindowClasses()) assert(0);
1999 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
2002 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2003 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2004 WS_MAXIMIZEBOX | WS_POPUP,
2007 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2008 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2009 WS_MAXIMIZEBOX | WS_POPUP,
2013 assert( hwndMain2 );
2017 test_capture_3(hwndMain, hwndMain2);
2019 test_parent_owner();
2020 test_shell_window();
2024 test_SetWindowPos(hwndMain);
2025 test_SetMenu(hwndMain);
2026 test_SetFocus(hwndMain);
2027 test_SetActiveWindow(hwndMain);
2029 test_children_zorder(hwndMain);
2031 UnhookWindowsHookEx(hhook);