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 check_parents( test, child, child, owner, owner, hwndMain, owner );
400 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
403 /* owned top-level popup */
404 owner = create_tool_window( 0, 0 );
405 test = create_tool_window( WS_POPUP, owner );
406 trace( "created owner %p and popup %p\n", owner, test );
407 check_parents( test, desktop, owner, owner, owner, test, owner );
408 DestroyWindow( owner );
409 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
411 /* top-level popup owned by child */
412 owner = create_tool_window( WS_CHILD, hwndMain2 );
413 test = create_tool_window( WS_POPUP, 0 );
414 trace( "created owner %p and popup %p\n", owner, test );
415 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
416 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
417 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
418 DestroyWindow( owner );
419 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
420 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
421 check_parents( test, desktop, owner, owner, owner, test, owner );
425 DestroyWindow(child);
429 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
433 case WM_GETMINMAXINFO:
435 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
437 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
438 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
439 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
440 minmax->ptReserved.x, minmax->ptReserved.y,
441 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
442 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
443 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
444 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
445 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
448 case WM_WINDOWPOSCHANGING:
450 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
451 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
452 trace("main: WM_WINDOWPOSCHANGING\n");
453 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
454 winpos->hwnd, winpos->hwndInsertAfter,
455 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
456 if (!(winpos->flags & SWP_NOMOVE))
458 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
459 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
461 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
462 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
464 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
465 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
469 case WM_WINDOWPOSCHANGED:
471 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
472 trace("main: WM_WINDOWPOSCHANGED\n");
473 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
474 winpos->hwnd, winpos->hwndInsertAfter,
475 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
476 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
477 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
479 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
480 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
485 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
486 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
488 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
489 if (got_getminmaxinfo)
490 trace("%p got WM_GETMINMAXINFO\n", hwnd);
492 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
493 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
495 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
500 return DefWindowProcA(hwnd, msg, wparam, lparam);
503 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
507 case WM_GETMINMAXINFO:
509 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
511 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
512 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
513 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
514 minmax->ptReserved.x, minmax->ptReserved.y,
515 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
516 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
517 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
518 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
519 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
524 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
525 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
527 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
528 if (got_getminmaxinfo)
529 trace("%p got WM_GETMINMAXINFO\n", hwnd);
531 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
532 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
534 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
539 return DefWindowProcA(hwnd, msg, wparam, lparam);
542 static BOOL RegisterWindowClasses(void)
547 cls.lpfnWndProc = main_window_procA;
550 cls.hInstance = GetModuleHandleA(0);
552 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
553 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
554 cls.lpszMenuName = NULL;
555 cls.lpszClassName = "MainWindowClass";
557 if(!RegisterClassA(&cls)) return FALSE;
560 cls.lpfnWndProc = tool_window_procA;
563 cls.hInstance = GetModuleHandleA(0);
565 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
566 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
567 cls.lpszMenuName = NULL;
568 cls.lpszClassName = "ToolWindowClass";
570 if(!RegisterClassA(&cls)) return FALSE;
575 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
577 RECT rcWindow, rcClient;
581 ok(IsWindow(hwnd), "bad window handle\n");
583 GetWindowRect(hwnd, &rcWindow);
584 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
586 GetClientRect(hwnd, &rcClient);
587 /* translate to screen coordinates */
588 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
589 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
591 ok(info->dwStyle == GetWindowLongA(hwnd, GWL_STYLE), "wrong dwStyle\n");
592 ok(info->dwExStyle == GetWindowLongA(hwnd, GWL_EXSTYLE), "wrong dwExStyle\n");
593 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
594 ok(info->dwWindowStatus == status, "wrong dwWindowStatus\n");
596 if (test_borders && !IsRectEmpty(&rcWindow))
598 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
599 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
601 ok(info->cxWindowBorders == rcClient.left - rcWindow.left,
602 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
603 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
604 ok(info->cyWindowBorders == border,
605 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
608 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
609 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
612 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
614 static const char *CBT_code_name[10] = {
625 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
627 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
633 #if 0 /* Uncomment this once the test succeeds in all cases */
634 static const RECT rc_null;
638 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
639 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
640 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
641 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
643 /* WS_VISIBLE should be turned off yet */
644 style = createwnd->lpcs->style & ~WS_VISIBLE;
645 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
646 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
647 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
649 #if 0 /* Uncomment this once the test succeeds in all cases */
650 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
652 ok(GetParent((HWND)wParam) == hwndMessage,
653 "wrong result from GetParent %p: message window %p\n",
654 GetParent((HWND)wParam), hwndMessage);
657 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
659 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
661 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
662 * Win9x still has them set to 0.
664 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
665 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
667 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
668 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
670 #if 0 /* Uncomment this once the test succeeds in all cases */
673 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
674 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
675 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
677 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
678 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
679 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
681 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
682 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
685 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
686 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
687 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
688 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
693 case HCBT_DESTROYWND:
695 if (wParam && pGetWindowInfo)
700 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
701 /* win2k SP4 returns broken border info if GetWindowInfo
702 * is being called from HCBT_DESTROYWND hook proc.
704 verify_window_info((HWND)wParam, &info, nCode != HCBT_DESTROYWND);
706 info.cbSize = sizeof(WINDOWINFO) + 1;
707 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
708 verify_window_info((HWND)wParam, &info, nCode != HCBT_DESTROYWND);
713 return CallNextHookEx(hhook, nCode, wParam, lParam);
716 static void test_shell_window()
720 HMODULE hinst, hUser32;
721 BOOL (WINAPI*SetShellWindow)(HWND);
722 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
723 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
724 HWND shellWindow, nextWnd;
726 shellWindow = GetShellWindow();
727 hinst = GetModuleHandle(0);
728 hUser32 = GetModuleHandleA("user32");
730 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
731 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
733 trace("previous shell window: %p\n", shellWindow);
739 ret = DestroyWindow(shellWindow);
740 error = GetLastError();
742 ok(!ret, "DestroyWindow(shellWindow)\n");
743 /* passes on Win XP, but not on Win98
744 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n"); */
746 /* close old shell instance */
747 GetWindowThreadProcessId(shellWindow, &pid);
748 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
749 ret = TerminateProcess(hProcess, 0);
750 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
751 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
752 CloseHandle(hProcess);
755 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
756 trace("created window 1: %p\n", hwnd1);
758 ret = SetShellWindow(hwnd1);
759 ok(ret, "first call to SetShellWindow(hwnd1)\n");
760 shellWindow = GetShellWindow();
761 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
763 ret = SetShellWindow(hwnd1);
764 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
766 ret = SetShellWindow(0);
767 error = GetLastError();
768 /* passes on Win XP, but not on Win98
769 ok(!ret, "reset shell window by SetShellWindow(0)\n");
770 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
772 ret = SetShellWindow(hwnd1);
773 /* passes on Win XP, but not on Win98
774 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
778 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
779 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
780 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
783 ret = DestroyWindow(hwnd1);
784 ok(ret, "DestroyWindow(hwnd1)\n");
786 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
787 trace("created window 2: %p\n", hwnd2);
788 ret = SetShellWindow(hwnd2);
789 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
791 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
792 trace("created window 3: %p\n", hwnd3);
794 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
795 trace("created window 4: %p\n", hwnd4);
797 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
798 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
800 ret = SetShellWindow(hwnd4);
801 ok(ret, "SetShellWindow(hwnd4)\n");
802 shellWindow = GetShellWindow();
803 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
805 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
806 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
808 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
809 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
811 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
812 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
814 ret = SetShellWindow(hwnd3);
815 ok(!ret, "SetShellWindow(hwnd3)\n");
816 shellWindow = GetShellWindow();
817 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
819 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
820 trace("created window 5: %p\n", hwnd5);
821 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
822 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
826 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
827 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
830 /* destroy test windows */
831 DestroyWindow(hwnd2);
832 DestroyWindow(hwnd3);
833 DestroyWindow(hwnd4);
834 DestroyWindow(hwnd5);
837 /************** MDI test ****************/
839 static const char mdi_lParam_test_message[] = "just a test string";
841 static void test_MDI_create(HWND parent, HWND mdi_client)
843 MDICREATESTRUCTA mdi_cs;
845 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
846 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
847 BOOL isWin9x = FALSE;
849 mdi_cs.szClass = "MDI_child_Class_1";
850 mdi_cs.szTitle = "MDI child";
851 mdi_cs.hOwner = GetModuleHandle(0);
852 mdi_cs.x = CW_USEDEFAULT;
853 mdi_cs.y = CW_USEDEFAULT;
854 mdi_cs.cx = CW_USEDEFAULT;
855 mdi_cs.cy = CW_USEDEFAULT;
857 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
858 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
859 ok(mdi_child != 0, "MDI child creation failed\n");
860 DestroyWindow(mdi_child);
862 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
863 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
864 ok(mdi_child != 0, "MDI child creation failed\n");
865 DestroyWindow(mdi_child);
867 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
868 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
869 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
871 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
872 DestroyWindow(mdi_child);
875 ok(mdi_child != 0, "MDI child creation failed\n");
877 /* test MDICREATESTRUCT A<->W mapping */
878 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
880 mdi_cs.szClass = (LPCSTR)classW;
881 mdi_cs.szTitle = (LPCSTR)titleW;
882 SetLastError(0xdeadbeef);
883 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
886 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
889 ok(mdi_child != 0, "MDI child creation failed\n");
891 DestroyWindow(mdi_child);
893 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
895 CW_USEDEFAULT, CW_USEDEFAULT,
896 CW_USEDEFAULT, CW_USEDEFAULT,
897 mdi_client, GetModuleHandle(0),
898 (LPARAM)mdi_lParam_test_message);
899 ok(mdi_child != 0, "MDI child creation failed\n");
900 DestroyWindow(mdi_child);
902 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
903 0x7fffffff, /* without WS_POPUP */
904 CW_USEDEFAULT, CW_USEDEFAULT,
905 CW_USEDEFAULT, CW_USEDEFAULT,
906 mdi_client, GetModuleHandle(0),
907 (LPARAM)mdi_lParam_test_message);
908 ok(mdi_child != 0, "MDI child creation failed\n");
909 DestroyWindow(mdi_child);
911 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
912 0xffffffff, /* with WS_POPUP */
913 CW_USEDEFAULT, CW_USEDEFAULT,
914 CW_USEDEFAULT, CW_USEDEFAULT,
915 mdi_client, GetModuleHandle(0),
916 (LPARAM)mdi_lParam_test_message);
917 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
919 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
920 DestroyWindow(mdi_child);
923 ok(mdi_child != 0, "MDI child creation failed\n");
925 /* test MDICREATESTRUCT A<->W mapping */
926 SetLastError(0xdeadbeef);
927 mdi_child = CreateMDIWindowW(classW, titleW,
929 CW_USEDEFAULT, CW_USEDEFAULT,
930 CW_USEDEFAULT, CW_USEDEFAULT,
931 mdi_client, GetModuleHandle(0),
932 (LPARAM)mdi_lParam_test_message);
935 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
938 ok(mdi_child != 0, "MDI child creation failed\n");
940 DestroyWindow(mdi_child);
942 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
944 CW_USEDEFAULT, CW_USEDEFAULT,
945 CW_USEDEFAULT, CW_USEDEFAULT,
946 mdi_client, 0, GetModuleHandle(0),
947 (LPVOID)mdi_lParam_test_message);
948 ok(mdi_child != 0, "MDI child creation failed\n");
949 DestroyWindow(mdi_child);
951 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
952 0x7fffffff, /* without WS_POPUP */
953 CW_USEDEFAULT, CW_USEDEFAULT,
954 CW_USEDEFAULT, CW_USEDEFAULT,
955 mdi_client, 0, GetModuleHandle(0),
956 (LPVOID)mdi_lParam_test_message);
957 ok(mdi_child != 0, "MDI child creation failed\n");
958 DestroyWindow(mdi_child);
960 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
961 0xffffffff, /* with WS_POPUP */
962 CW_USEDEFAULT, CW_USEDEFAULT,
963 CW_USEDEFAULT, CW_USEDEFAULT,
964 mdi_client, 0, GetModuleHandle(0),
965 (LPVOID)mdi_lParam_test_message);
966 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
968 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
969 DestroyWindow(mdi_child);
972 ok(mdi_child != 0, "MDI child creation failed\n");
974 /* test MDICREATESTRUCT A<->W mapping */
975 SetLastError(0xdeadbeef);
976 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
978 CW_USEDEFAULT, CW_USEDEFAULT,
979 CW_USEDEFAULT, CW_USEDEFAULT,
980 mdi_client, 0, GetModuleHandle(0),
981 (LPVOID)mdi_lParam_test_message);
984 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
987 ok(mdi_child != 0, "MDI child creation failed\n");
989 DestroyWindow(mdi_child);
991 /* This test fails on Win9x */
994 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
996 CW_USEDEFAULT, CW_USEDEFAULT,
997 CW_USEDEFAULT, CW_USEDEFAULT,
998 parent, 0, GetModuleHandle(0),
999 (LPVOID)mdi_lParam_test_message);
1000 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1003 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1004 WS_CHILD, /* without WS_POPUP */
1005 CW_USEDEFAULT, CW_USEDEFAULT,
1006 CW_USEDEFAULT, CW_USEDEFAULT,
1007 mdi_client, 0, GetModuleHandle(0),
1008 (LPVOID)mdi_lParam_test_message);
1009 ok(mdi_child != 0, "MDI child creation failed\n");
1010 DestroyWindow(mdi_child);
1012 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1013 WS_CHILD | WS_POPUP, /* with WS_POPUP */
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 /* maximized child */
1022 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1023 WS_CHILD | WS_MAXIMIZE,
1024 CW_USEDEFAULT, CW_USEDEFAULT,
1025 CW_USEDEFAULT, CW_USEDEFAULT,
1026 mdi_client, 0, GetModuleHandle(0),
1027 (LPVOID)mdi_lParam_test_message);
1028 ok(mdi_child != 0, "MDI child creation failed\n");
1029 DestroyWindow(mdi_child);
1031 trace("Creating maximized child with a caption\n");
1032 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1033 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1034 CW_USEDEFAULT, CW_USEDEFAULT,
1035 CW_USEDEFAULT, CW_USEDEFAULT,
1036 mdi_client, 0, GetModuleHandle(0),
1037 (LPVOID)mdi_lParam_test_message);
1038 ok(mdi_child != 0, "MDI child creation failed\n");
1039 DestroyWindow(mdi_child);
1041 trace("Creating maximized child with a caption and a thick frame\n");
1042 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1043 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1044 CW_USEDEFAULT, CW_USEDEFAULT,
1045 CW_USEDEFAULT, CW_USEDEFAULT,
1046 mdi_client, 0, GetModuleHandle(0),
1047 (LPVOID)mdi_lParam_test_message);
1048 ok(mdi_child != 0, "MDI child creation failed\n");
1049 DestroyWindow(mdi_child);
1052 /**********************************************************************
1053 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1055 * Note: The rule here is that client rect of the maximized MDI child
1056 * is equal to the client rect of the MDI client window.
1058 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1062 GetClientRect( client, &rect );
1063 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1064 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1066 rect.right -= rect.left;
1067 rect.bottom -= rect.top;
1068 lpMinMax->ptMaxSize.x = rect.right;
1069 lpMinMax->ptMaxSize.y = rect.bottom;
1071 lpMinMax->ptMaxPosition.x = rect.left;
1072 lpMinMax->ptMaxPosition.y = rect.top;
1074 trace("max rect (%ld,%ld - %ld, %ld)\n",
1075 rect.left, rect.top, rect.right, rect.bottom);
1078 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1085 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1086 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1088 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1089 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1091 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1092 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1093 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1094 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1095 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1097 /* MDICREATESTRUCT should have original values */
1098 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1099 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1100 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1101 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1102 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1103 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1105 /* CREATESTRUCT should have fixed values */
1106 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1107 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1109 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1110 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1111 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1113 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1115 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1117 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1118 ok(cs->style == style,
1119 "cs->style does not match (%08lx)\n", cs->style);
1123 LONG style = mdi_cs->style;
1125 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1126 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1127 ok(cs->style == style,
1128 "cs->style does not match (%08lx)\n", cs->style);
1133 case WM_GETMINMAXINFO:
1135 HWND client = GetParent(hwnd);
1137 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1138 MINMAXINFO my_minmax;
1139 LONG style, exstyle;
1141 style = GetWindowLongA(hwnd, GWL_STYLE);
1142 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1144 GetWindowRect(client, &rc);
1145 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1146 GetClientRect(client, &rc);
1147 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1148 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1149 GetSystemMetrics(SM_CYSCREEN));
1151 GetClientRect(client, &rc);
1152 if ((style & WS_CAPTION) == WS_CAPTION)
1153 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1154 AdjustWindowRectEx(&rc, style, 0, exstyle);
1155 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1157 trace("ptReserved = (%ld,%ld)\n"
1158 "ptMaxSize = (%ld,%ld)\n"
1159 "ptMaxPosition = (%ld,%ld)\n"
1160 "ptMinTrackSize = (%ld,%ld)\n"
1161 "ptMaxTrackSize = (%ld,%ld)\n",
1162 minmax->ptReserved.x, minmax->ptReserved.y,
1163 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1164 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1165 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1166 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1168 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1169 minmax->ptMaxSize.x, rc.right - rc.left);
1170 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1171 minmax->ptMaxSize.y, rc.bottom - rc.top);
1173 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1175 trace("DefMDIChildProc returned:\n"
1176 "ptReserved = (%ld,%ld)\n"
1177 "ptMaxSize = (%ld,%ld)\n"
1178 "ptMaxPosition = (%ld,%ld)\n"
1179 "ptMinTrackSize = (%ld,%ld)\n"
1180 "ptMaxTrackSize = (%ld,%ld)\n",
1181 minmax->ptReserved.x, minmax->ptReserved.y,
1182 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1183 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1184 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1185 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1187 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1188 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1189 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1190 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1191 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1196 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1199 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1206 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1208 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1209 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1211 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1212 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1214 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1215 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1217 /* CREATESTRUCT should have fixed values */
1218 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1220 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1221 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1223 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1224 ok(cs->cx == 0, "%d != 0\n", cs->cx);
1225 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1229 case WM_GETMINMAXINFO:
1231 HWND parent = GetParent(hwnd);
1233 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1234 LONG style, exstyle;
1236 trace("WM_GETMINMAXINFO\n");
1238 style = GetWindowLongA(hwnd, GWL_STYLE);
1239 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1241 GetClientRect(parent, &rc);
1242 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1244 GetClientRect(parent, &rc);
1245 if ((style & WS_CAPTION) == WS_CAPTION)
1246 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1247 AdjustWindowRectEx(&rc, style, 0, exstyle);
1248 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1250 trace("ptReserved = (%ld,%ld)\n"
1251 "ptMaxSize = (%ld,%ld)\n"
1252 "ptMaxPosition = (%ld,%ld)\n"
1253 "ptMinTrackSize = (%ld,%ld)\n"
1254 "ptMaxTrackSize = (%ld,%ld)\n",
1255 minmax->ptReserved.x, minmax->ptReserved.y,
1256 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1257 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1258 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1259 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1261 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1262 minmax->ptMaxSize.x, rc.right - rc.left);
1263 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1264 minmax->ptMaxSize.y, rc.bottom - rc.top);
1268 case WM_WINDOWPOSCHANGING:
1269 case WM_WINDOWPOSCHANGED:
1271 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1272 WINDOWPOS my_winpos = *winpos;
1274 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1275 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1276 winpos->hwnd, winpos->hwndInsertAfter,
1277 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1279 DefWindowProcA(hwnd, msg, wparam, lparam);
1281 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1282 winpos->hwnd, winpos->hwndInsertAfter,
1283 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1285 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1286 "DefWindowProc should not change WINDOWPOS values\n");
1291 return DefWindowProcA(hwnd, msg, wparam, lparam);
1294 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1296 static HWND mdi_client;
1302 CLIENTCREATESTRUCT client_cs;
1305 GetClientRect(hwnd, &rc);
1307 client_cs.hWindowMenu = 0;
1308 client_cs.idFirstChild = 1;
1310 /* MDIClient without MDIS_ALLCHILDSTYLES */
1311 mdi_client = CreateWindowExA(0, "mdiclient",
1313 WS_CHILD /*| WS_VISIBLE*/,
1314 /* tests depend on a not zero MDIClient size */
1315 0, 0, rc.right, rc.bottom,
1316 hwnd, 0, GetModuleHandle(0),
1317 (LPVOID)&client_cs);
1319 test_MDI_create(hwnd, mdi_client);
1320 DestroyWindow(mdi_client);
1322 /* MDIClient with MDIS_ALLCHILDSTYLES */
1323 mdi_client = CreateWindowExA(0, "mdiclient",
1325 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1326 /* tests depend on a not zero MDIClient size */
1327 0, 0, rc.right, rc.bottom,
1328 hwnd, 0, GetModuleHandle(0),
1329 (LPVOID)&client_cs);
1331 test_MDI_create(hwnd, mdi_client);
1332 DestroyWindow(mdi_client);
1340 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1343 static BOOL mdi_RegisterWindowClasses(void)
1348 cls.lpfnWndProc = mdi_main_wnd_procA;
1351 cls.hInstance = GetModuleHandleA(0);
1353 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1354 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1355 cls.lpszMenuName = NULL;
1356 cls.lpszClassName = "MDI_parent_Class";
1357 if(!RegisterClassA(&cls)) return FALSE;
1359 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1360 cls.lpszClassName = "MDI_child_Class_1";
1361 if(!RegisterClassA(&cls)) return FALSE;
1363 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1364 cls.lpszClassName = "MDI_child_Class_2";
1365 if(!RegisterClassA(&cls)) return FALSE;
1370 static void test_mdi(void)
1375 if (!mdi_RegisterWindowClasses()) assert(0);
1377 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1378 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1379 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1380 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1381 GetDesktopWindow(), 0,
1382 GetModuleHandle(0), NULL);
1383 assert(mdi_hwndMain);
1385 while(GetMessage(&msg, 0, 0, 0))
1387 TranslateMessage(&msg);
1388 DispatchMessage(&msg);
1393 static void test_icons(void)
1397 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1398 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1399 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1400 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1403 cls.cbSize = sizeof(cls);
1405 cls.lpfnWndProc = DefWindowProcA;
1409 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1410 cls.hIconSm = small_icon;
1411 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1412 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1413 cls.lpszMenuName = NULL;
1414 cls.lpszClassName = "IconWindowClass";
1416 RegisterClassExA(&cls);
1418 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1419 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1422 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1423 ok( res == 0, "wrong big icon %p/0\n", res );
1424 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1425 ok( res == 0, "wrong previous big icon %p/0\n", res );
1426 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1427 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1428 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1429 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1430 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1431 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1433 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1434 ok( res == 0, "wrong small icon %p/0\n", res );
1435 /* this test is XP specific */
1436 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1437 ok( res != 0, "wrong small icon %p\n", res );*/
1438 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1439 ok( res == 0, "wrong previous small icon %p/0\n", res );
1440 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1441 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1442 /* this test is XP specific */
1443 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1444 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1445 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1446 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1447 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1448 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1449 /* this test is XP specific */
1450 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1451 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1453 /* make sure the big icon hasn't changed */
1454 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1455 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1458 static void test_SetWindowPos(HWND hwnd)
1460 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1461 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1463 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1464 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1467 static void test_SetMenu(HWND parent)
1472 hMenu = CreateMenu();
1476 ret = GetMenu(parent);
1477 ok(ret == 0, "unexpected menu id %p\n", ret);
1479 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1480 ret = GetMenu(parent);
1481 ok(ret == 0, "unexpected menu id %p\n", ret);
1483 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1484 ret = GetMenu(parent);
1485 ok(ret == (HMENU)hMenu, "unexpected menu id %p\n", ret);
1487 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1488 ret = GetMenu(parent);
1489 ok(ret == 0, "unexpected menu id %p\n", ret);
1492 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1495 ret = GetMenu(child);
1496 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1498 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1499 ret = GetMenu(child);
1500 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1502 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1503 ret = GetMenu(child);
1504 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1506 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1507 ret = GetMenu(child);
1508 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1510 DestroyWindow(child);
1514 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1516 HWND child[5], hwnd;
1521 hwnd = GetWindow(parent, GW_CHILD);
1522 ok(!hwnd, "have to start without children to perform the test\n");
1524 for (i = 0; i < total; i++)
1526 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1527 parent, 0, 0, NULL);
1528 trace("child[%d] = %p\n", i, child[i]);
1529 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1532 hwnd = GetWindow(parent, GW_CHILD);
1533 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1534 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1535 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1537 for (i = 0; i < total; i++)
1539 trace("hwnd[%d] = %p\n", i, hwnd);
1540 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1542 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1545 for (i = 0; i < total; i++)
1546 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1549 static void test_children_zorder(HWND parent)
1551 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1553 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1555 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1556 WS_CHILD | WS_VISIBLE, WS_CHILD,
1557 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1558 const int complex_order_1[1] = { 0 };
1559 const int complex_order_2[2] = { 1, 0 };
1560 const int complex_order_3[3] = { 1, 0, 2 };
1561 const int complex_order_4[4] = { 1, 0, 2, 3 };
1562 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1564 /* simple WS_CHILD */
1565 test_window_tree(parent, simple_style, simple_order, 5);
1567 /* complex children styles */
1568 test_window_tree(parent, complex_style, complex_order_1, 1);
1569 test_window_tree(parent, complex_style, complex_order_2, 2);
1570 test_window_tree(parent, complex_style, complex_order_3, 3);
1571 test_window_tree(parent, complex_style, complex_order_4, 4);
1572 test_window_tree(parent, complex_style, complex_order_5, 5);
1575 static void test_SetFocus(HWND hwnd)
1579 /* check if we can set focus to non-visible windows */
1581 ShowWindow(hwnd, SW_SHOW);
1584 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1585 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1586 ShowWindow(hwnd, SW_HIDE);
1589 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1590 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1591 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1594 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1595 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1596 ShowWindow(child, SW_SHOW);
1597 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1598 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1599 ShowWindow(child, SW_HIDE);
1600 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1601 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1602 ShowWindow(child, SW_SHOW);
1604 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1605 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1606 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1607 DestroyWindow( child );
1612 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
1613 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
1615 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
1618 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
1621 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
1622 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
1623 trace("hwndMessage %p\n", hwndMessage);
1625 DestroyWindow(hwndMain);
1628 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
1630 if (!RegisterWindowClasses()) assert(0);
1632 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
1635 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
1636 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1637 WS_MAXIMIZEBOX | WS_POPUP,
1640 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
1641 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1642 WS_MAXIMIZEBOX | WS_POPUP,
1646 assert( hwndMain2 );
1648 test_parent_owner();
1649 test_shell_window();
1653 test_SetWindowPos(hwndMain);
1654 test_SetMenu(hwndMain);
1655 test_SetFocus(hwndMain);
1657 test_children_zorder(hwndMain);
1659 UnhookWindowsHookEx(hhook);