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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
49 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
51 static HWND hwndMessage;
52 static HWND hwndMain, hwndMain2;
55 /* check the values returned by the various parent/owner functions on a given window */
56 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
57 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
63 res = pGetAncestor( hwnd, GA_PARENT );
64 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
66 res = (HWND)GetWindowLongA( hwnd, GWL_HWNDPARENT );
67 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
68 res = GetParent( hwnd );
69 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
70 res = GetWindow( hwnd, GW_OWNER );
71 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
74 res = pGetAncestor( hwnd, GA_ROOT );
75 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
76 res = pGetAncestor( hwnd, GA_ROOTOWNER );
77 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
82 static HWND create_tool_window( LONG style, HWND parent )
84 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
85 0, 0, 100, 100, parent, 0, 0, NULL );
86 ok( ret != 0, "Creation failed\n" );
90 /* test parent and owner values for various combinations */
91 static void test_parent_owner(void)
94 HWND test, owner, ret;
95 HWND desktop = GetDesktopWindow();
96 HWND child = create_tool_window( WS_CHILD, hwndMain );
98 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
100 /* child without parent, should fail */
101 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
102 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
103 ok( !test, "WS_CHILD without parent created\n" );
106 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
107 style = GetWindowLongA( desktop, GWL_STYLE );
108 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
109 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
110 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
112 /* normal child window */
113 test = create_tool_window( WS_CHILD, hwndMain );
114 trace( "created child %p\n", test );
115 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
116 SetWindowLongA( test, GWL_STYLE, 0 );
117 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
118 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
119 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
120 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
121 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
122 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
123 DestroyWindow( test );
125 /* normal child window with WS_MAXIMIZE */
126 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
127 DestroyWindow( test );
129 /* normal child window with WS_THICKFRAME */
130 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
131 DestroyWindow( test );
133 /* popup window with WS_THICKFRAME */
134 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
135 DestroyWindow( test );
137 /* child of desktop */
138 test = create_tool_window( WS_CHILD, desktop );
139 trace( "created child of desktop %p\n", test );
140 check_parents( test, desktop, 0, desktop, 0, test, desktop );
141 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
142 check_parents( test, desktop, 0, 0, 0, test, test );
143 SetWindowLongA( test, GWL_STYLE, 0 );
144 check_parents( test, desktop, 0, 0, 0, test, test );
145 DestroyWindow( test );
147 /* child of desktop with WS_MAXIMIZE */
148 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
149 DestroyWindow( test );
151 /* child of desktop with WS_MINIMIZE */
152 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
153 DestroyWindow( test );
156 test = create_tool_window( WS_CHILD, child );
157 trace( "created child of child %p\n", test );
158 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
159 SetWindowLongA( test, GWL_STYLE, 0 );
160 check_parents( test, child, child, 0, 0, hwndMain, test );
161 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
162 check_parents( test, child, child, 0, 0, hwndMain, test );
163 DestroyWindow( test );
165 /* child of child with WS_MAXIMIZE */
166 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
167 DestroyWindow( test );
169 /* child of child with WS_MINIMIZE */
170 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
171 DestroyWindow( test );
173 /* not owned top-level window */
174 test = create_tool_window( 0, 0 );
175 trace( "created top-level %p\n", test );
176 check_parents( test, desktop, 0, 0, 0, test, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
178 check_parents( test, desktop, 0, 0, 0, test, test );
179 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
180 check_parents( test, desktop, 0, desktop, 0, test, desktop );
181 DestroyWindow( test );
183 /* not owned top-level window with WS_MAXIMIZE */
184 test = create_tool_window( WS_MAXIMIZE, 0 );
185 DestroyWindow( test );
187 /* owned top-level window */
188 test = create_tool_window( 0, hwndMain );
189 trace( "created owned top-level %p\n", test );
190 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
191 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
192 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
193 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
194 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
195 DestroyWindow( test );
197 /* owned top-level window with WS_MAXIMIZE */
198 test = create_tool_window( WS_MAXIMIZE, hwndMain );
199 DestroyWindow( test );
201 /* not owned popup */
202 test = create_tool_window( WS_POPUP, 0 );
203 trace( "created popup %p\n", test );
204 check_parents( test, desktop, 0, 0, 0, test, test );
205 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
206 check_parents( test, desktop, 0, desktop, 0, test, desktop );
207 SetWindowLongA( test, GWL_STYLE, 0 );
208 check_parents( test, desktop, 0, 0, 0, test, test );
209 DestroyWindow( test );
211 /* not owned popup with WS_MAXIMIZE */
212 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
213 DestroyWindow( test );
216 test = create_tool_window( WS_POPUP, hwndMain );
217 trace( "created owned popup %p\n", test );
218 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
219 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
220 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
221 SetWindowLongA( test, GWL_STYLE, 0 );
222 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
223 DestroyWindow( test );
225 /* owned popup with WS_MAXIMIZE */
226 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
227 DestroyWindow( test );
229 /* top-level window owned by child (same as owned by top-level) */
230 test = create_tool_window( 0, child );
231 trace( "created top-level owned by child %p\n", test );
232 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
233 DestroyWindow( test );
235 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
236 test = create_tool_window( WS_MAXIMIZE, child );
237 DestroyWindow( test );
239 /* popup owned by desktop (same as not owned) */
240 test = create_tool_window( WS_POPUP, desktop );
241 trace( "created popup owned by desktop %p\n", test );
242 check_parents( test, desktop, 0, 0, 0, test, test );
243 DestroyWindow( test );
245 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
246 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
247 DestroyWindow( test );
249 /* popup owned by child (same as owned by top-level) */
250 test = create_tool_window( WS_POPUP, child );
251 trace( "created popup owned by child %p\n", test );
252 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
253 DestroyWindow( test );
255 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
256 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
257 DestroyWindow( test );
259 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
260 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
261 trace( "created WS_CHILD popup %p\n", test );
262 check_parents( test, desktop, 0, 0, 0, test, test );
263 DestroyWindow( test );
265 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
266 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
267 DestroyWindow( test );
269 /* owned popup with WS_CHILD (same as WS_POPUP only) */
270 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
271 trace( "created owned WS_CHILD popup %p\n", test );
272 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
273 DestroyWindow( test );
275 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
276 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
277 DestroyWindow( test );
279 /******************** parent changes *************************/
280 trace( "testing parent changes\n" );
283 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
284 #if 0 /* this test succeeds on NT but crashes on win9x systems */
285 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
286 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
287 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
288 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
289 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
291 /* normal child window */
292 test = create_tool_window( WS_CHILD, hwndMain );
293 trace( "created child %p\n", test );
295 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
296 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
297 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
299 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
300 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
301 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
303 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
304 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
305 check_parents( test, desktop, 0, desktop, 0, test, desktop );
307 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
308 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
309 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
310 check_parents( test, desktop, child, desktop, child, test, desktop );
312 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
313 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
314 check_parents( test, desktop, 0, desktop, 0, test, desktop );
315 DestroyWindow( test );
317 /* not owned top-level window */
318 test = create_tool_window( 0, 0 );
319 trace( "created top-level %p\n", test );
321 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
322 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
323 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
325 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
326 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
327 check_parents( test, desktop, child, 0, child, test, test );
329 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
330 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
331 check_parents( test, desktop, 0, 0, 0, test, test );
332 DestroyWindow( test );
334 /* not owned popup */
335 test = create_tool_window( WS_POPUP, 0 );
336 trace( "created popup %p\n", test );
338 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
339 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
340 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
342 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
343 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
344 check_parents( test, desktop, child, child, child, test, hwndMain );
346 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
347 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
348 check_parents( test, desktop, 0, 0, 0, test, test );
349 DestroyWindow( test );
351 /* normal child window */
352 test = create_tool_window( WS_CHILD, hwndMain );
353 trace( "created child %p\n", test );
355 ret = SetParent( test, desktop );
356 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
357 check_parents( test, desktop, 0, desktop, 0, test, desktop );
359 ret = SetParent( test, child );
360 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
361 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
363 ret = SetParent( test, hwndMain2 );
364 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
365 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
366 DestroyWindow( test );
368 /* not owned top-level window */
369 test = create_tool_window( 0, 0 );
370 trace( "created top-level %p\n", test );
372 ret = SetParent( test, child );
373 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
374 check_parents( test, child, child, 0, 0, hwndMain, test );
375 DestroyWindow( test );
378 test = create_tool_window( WS_POPUP, hwndMain2 );
379 trace( "created owned popup %p\n", test );
381 ret = SetParent( test, child );
382 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
383 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
385 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
386 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
387 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
388 DestroyWindow( test );
390 /**************** test owner destruction *******************/
392 /* owned child popup */
393 owner = create_tool_window( 0, 0 );
394 test = create_tool_window( WS_POPUP, owner );
395 trace( "created owner %p and popup %p\n", owner, test );
396 ret = SetParent( test, child );
397 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
398 check_parents( test, child, child, owner, owner, hwndMain, owner );
399 /* window is now child of 'child' but owned by 'owner' */
400 DestroyWindow( owner );
401 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
402 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
403 * while Win95, Win2k, WinXP do.
405 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
406 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
409 /* owned top-level popup */
410 owner = create_tool_window( 0, 0 );
411 test = create_tool_window( WS_POPUP, owner );
412 trace( "created owner %p and popup %p\n", owner, test );
413 check_parents( test, desktop, owner, owner, owner, test, owner );
414 DestroyWindow( owner );
415 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
417 /* top-level popup owned by child */
418 owner = create_tool_window( WS_CHILD, hwndMain2 );
419 test = create_tool_window( WS_POPUP, 0 );
420 trace( "created owner %p and popup %p\n", owner, test );
421 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
422 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
423 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
424 DestroyWindow( owner );
425 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
426 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
427 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
428 * while Win95, Win2k, WinXP do.
430 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
434 DestroyWindow(child);
438 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
442 case WM_GETMINMAXINFO:
444 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
446 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
447 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
448 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
449 minmax->ptReserved.x, minmax->ptReserved.y,
450 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
451 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
452 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
453 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
454 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
457 case WM_WINDOWPOSCHANGING:
459 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
460 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
461 trace("main: WM_WINDOWPOSCHANGING\n");
462 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
463 winpos->hwnd, winpos->hwndInsertAfter,
464 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
465 if (!(winpos->flags & SWP_NOMOVE))
467 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
468 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
470 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
471 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
473 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
474 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
478 case WM_WINDOWPOSCHANGED:
481 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
482 trace("main: WM_WINDOWPOSCHANGED\n");
483 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
484 winpos->hwnd, winpos->hwndInsertAfter,
485 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
486 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
487 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
489 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
490 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
492 GetWindowRect(hwnd, &rc1);
493 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
494 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
495 /* note: winpos coordinates are relative to parent */
496 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
497 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
498 #if 0 /* Uncomment this once the test succeeds in all cases */
499 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
502 GetClientRect(hwnd, &rc2);
503 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
504 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
505 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
510 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
511 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
513 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
514 if (got_getminmaxinfo)
515 trace("%p got WM_GETMINMAXINFO\n", hwnd);
517 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
518 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
520 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
525 return DefWindowProcA(hwnd, msg, wparam, lparam);
528 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
532 case WM_GETMINMAXINFO:
534 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
536 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
537 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
538 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
539 minmax->ptReserved.x, minmax->ptReserved.y,
540 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
541 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
542 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
543 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
544 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
549 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
550 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
552 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
553 if (got_getminmaxinfo)
554 trace("%p got WM_GETMINMAXINFO\n", hwnd);
556 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
557 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
559 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
564 return DefWindowProcA(hwnd, msg, wparam, lparam);
567 static BOOL RegisterWindowClasses(void)
572 cls.lpfnWndProc = main_window_procA;
575 cls.hInstance = GetModuleHandleA(0);
577 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
578 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
579 cls.lpszMenuName = NULL;
580 cls.lpszClassName = "MainWindowClass";
582 if(!RegisterClassA(&cls)) return FALSE;
585 cls.lpfnWndProc = tool_window_procA;
588 cls.hInstance = GetModuleHandleA(0);
590 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
591 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
592 cls.lpszMenuName = NULL;
593 cls.lpszClassName = "ToolWindowClass";
595 if(!RegisterClassA(&cls)) return FALSE;
600 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
602 RECT rcWindow, rcClient;
606 ok(IsWindow(hwnd), "bad window handle\n");
608 GetWindowRect(hwnd, &rcWindow);
609 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
611 GetClientRect(hwnd, &rcClient);
612 /* translate to screen coordinates */
613 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
614 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
616 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE), "wrong dwStyle\n");
617 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE), "wrong dwExStyle\n");
618 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
619 ok(info->dwWindowStatus == status, "wrong dwWindowStatus\n");
621 if (test_borders && !IsRectEmpty(&rcWindow))
623 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
624 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
626 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
627 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
628 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
629 ok(info->cyWindowBorders == border,
630 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
633 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
634 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
637 static void test_nonclient_area(HWND hwnd)
639 DWORD style, exstyle;
640 RECT rc_window, rc_client, rc;
643 style = GetWindowLongA(hwnd, GWL_STYLE);
644 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
645 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
647 GetWindowRect(hwnd, &rc_window);
648 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
649 GetClientRect(hwnd, &rc_client);
650 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
652 /* avoid some cases when things go wrong */
653 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
654 rc_window.right > 32768 || rc_window.bottom > 32768) return;
656 CopyRect(&rc, &rc_client);
657 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
658 AdjustWindowRectEx(&rc, style, menu, exstyle);
659 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
660 #if 0 /* Uncomment this once the test succeeds in all cases */
661 ok(EqualRect(&rc, &rc_window), "window rect does not match\n");
664 CopyRect(&rc, &rc_window);
665 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
666 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
667 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
668 #if 0 /* Uncomment this once the test succeeds in all cases */
669 ok(EqualRect(&rc, &rc_client), "client rect does not match\n");
672 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
673 SetRect(&rc_client, 0, 0, 250, 150);
674 CopyRect(&rc_window, &rc_client);
675 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
676 AdjustWindowRectEx(&rc_window, style, menu, exstyle);
677 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
678 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
680 CopyRect(&rc, &rc_window);
681 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
682 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
683 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
684 #if 0 /* Uncomment this once the test succeeds in all cases */
685 ok(EqualRect(&rc, &rc_client), "client rect does not match\n");
689 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
691 static const char *CBT_code_name[10] = {
702 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
704 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
706 /* on HCBT_DESTROYWND window state is undefined */
707 if (nCode != HCBT_DESTROYWND && wParam)
709 BOOL is_win9x = GetWindowLongW((HWND)wParam, GWL_WNDPROC) == 0;
710 if (is_win9x && nCode == HCBT_CREATEWND)
711 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
713 test_nonclient_area((HWND)wParam);
719 /* Win98 actually does check the info.cbSize and doesn't allow
720 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
721 * WinXP do not check it at all.
723 info.cbSize = sizeof(WINDOWINFO);
724 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
725 /* win2k SP4 returns broken border info if GetWindowInfo
726 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
728 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
736 #if 0 /* Uncomment this once the test succeeds in all cases */
737 static const RECT rc_null;
741 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
742 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
743 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
744 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
746 /* WS_VISIBLE should be turned off yet */
747 style = createwnd->lpcs->style & ~WS_VISIBLE;
748 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
749 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
750 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
752 #if 0 /* Uncomment this once the test succeeds in all cases */
753 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
755 ok(GetParent((HWND)wParam) == hwndMessage,
756 "wrong result from GetParent %p: message window %p\n",
757 GetParent((HWND)wParam), hwndMessage);
760 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
762 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
764 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
765 * Win9x still has them set to 0.
767 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
768 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
770 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
771 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
773 #if 0 /* Uncomment this once the test succeeds in all cases */
776 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
777 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
778 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
780 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
781 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
782 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
784 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
785 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
788 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
789 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
790 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
791 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
797 return CallNextHookEx(hhook, nCode, wParam, lParam);
800 static void test_shell_window(void)
804 HMODULE hinst, hUser32;
805 BOOL (WINAPI*SetShellWindow)(HWND);
806 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
807 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
808 HWND shellWindow, nextWnd;
810 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
812 trace("Skipping shell window test on Win9x\n");
816 shellWindow = GetShellWindow();
817 hinst = GetModuleHandle(0);
818 hUser32 = GetModuleHandleA("user32");
820 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
821 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
823 trace("previous shell window: %p\n", shellWindow);
829 ret = DestroyWindow(shellWindow);
830 error = GetLastError();
832 ok(!ret, "DestroyWindow(shellWindow)\n");
833 /* passes on Win XP, but not on Win98 */
834 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
836 /* close old shell instance */
837 GetWindowThreadProcessId(shellWindow, &pid);
838 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
839 ret = TerminateProcess(hProcess, 0);
840 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
841 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
842 CloseHandle(hProcess);
845 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
846 trace("created window 1: %p\n", hwnd1);
848 ret = SetShellWindow(hwnd1);
849 ok(ret, "first call to SetShellWindow(hwnd1)\n");
850 shellWindow = GetShellWindow();
851 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
853 ret = SetShellWindow(hwnd1);
854 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
856 ret = SetShellWindow(0);
857 error = GetLastError();
858 /* passes on Win XP, but not on Win98
859 ok(!ret, "reset shell window by SetShellWindow(0)\n");
860 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
862 ret = SetShellWindow(hwnd1);
863 /* passes on Win XP, but not on Win98
864 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
868 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
869 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
870 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
873 ret = DestroyWindow(hwnd1);
874 ok(ret, "DestroyWindow(hwnd1)\n");
876 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
877 trace("created window 2: %p\n", hwnd2);
878 ret = SetShellWindow(hwnd2);
879 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
881 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
882 trace("created window 3: %p\n", hwnd3);
884 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
885 trace("created window 4: %p\n", hwnd4);
887 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
888 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
890 ret = SetShellWindow(hwnd4);
891 ok(ret, "SetShellWindow(hwnd4)\n");
892 shellWindow = GetShellWindow();
893 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
895 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
896 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
898 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
899 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
901 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
902 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
904 ret = SetShellWindow(hwnd3);
905 ok(!ret, "SetShellWindow(hwnd3)\n");
906 shellWindow = GetShellWindow();
907 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
909 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
910 trace("created window 5: %p\n", hwnd5);
911 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
912 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
916 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
917 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
920 /* destroy test windows */
921 DestroyWindow(hwnd2);
922 DestroyWindow(hwnd3);
923 DestroyWindow(hwnd4);
924 DestroyWindow(hwnd5);
927 /************** MDI test ****************/
929 static const char mdi_lParam_test_message[] = "just a test string";
931 static void test_MDI_create(HWND parent, HWND mdi_client)
933 MDICREATESTRUCTA mdi_cs;
935 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
936 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
937 BOOL isWin9x = FALSE;
939 mdi_cs.szClass = "MDI_child_Class_1";
940 mdi_cs.szTitle = "MDI child";
941 mdi_cs.hOwner = GetModuleHandle(0);
942 mdi_cs.x = CW_USEDEFAULT;
943 mdi_cs.y = CW_USEDEFAULT;
944 mdi_cs.cx = CW_USEDEFAULT;
945 mdi_cs.cy = CW_USEDEFAULT;
947 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
948 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
949 ok(mdi_child != 0, "MDI child creation failed\n");
950 DestroyWindow(mdi_child);
952 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
953 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
954 ok(mdi_child != 0, "MDI child creation failed\n");
955 DestroyWindow(mdi_child);
957 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
958 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
959 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
961 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
962 DestroyWindow(mdi_child);
965 ok(mdi_child != 0, "MDI child creation failed\n");
967 /* test MDICREATESTRUCT A<->W mapping */
968 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
970 mdi_cs.szClass = (LPCSTR)classW;
971 mdi_cs.szTitle = (LPCSTR)titleW;
972 SetLastError(0xdeadbeef);
973 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
976 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
979 ok(mdi_child != 0, "MDI child creation failed\n");
981 DestroyWindow(mdi_child);
983 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
985 CW_USEDEFAULT, CW_USEDEFAULT,
986 CW_USEDEFAULT, CW_USEDEFAULT,
987 mdi_client, GetModuleHandle(0),
988 (LPARAM)mdi_lParam_test_message);
989 ok(mdi_child != 0, "MDI child creation failed\n");
990 DestroyWindow(mdi_child);
992 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
993 0x7fffffff, /* without WS_POPUP */
994 CW_USEDEFAULT, CW_USEDEFAULT,
995 CW_USEDEFAULT, CW_USEDEFAULT,
996 mdi_client, GetModuleHandle(0),
997 (LPARAM)mdi_lParam_test_message);
998 ok(mdi_child != 0, "MDI child creation failed\n");
999 DestroyWindow(mdi_child);
1001 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1002 0xffffffff, /* with WS_POPUP */
1003 CW_USEDEFAULT, CW_USEDEFAULT,
1004 CW_USEDEFAULT, CW_USEDEFAULT,
1005 mdi_client, GetModuleHandle(0),
1006 (LPARAM)mdi_lParam_test_message);
1007 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1009 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1010 DestroyWindow(mdi_child);
1013 ok(mdi_child != 0, "MDI child creation failed\n");
1015 /* test MDICREATESTRUCT A<->W mapping */
1016 SetLastError(0xdeadbeef);
1017 mdi_child = CreateMDIWindowW(classW, titleW,
1019 CW_USEDEFAULT, CW_USEDEFAULT,
1020 CW_USEDEFAULT, CW_USEDEFAULT,
1021 mdi_client, GetModuleHandle(0),
1022 (LPARAM)mdi_lParam_test_message);
1025 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1028 ok(mdi_child != 0, "MDI child creation failed\n");
1030 DestroyWindow(mdi_child);
1032 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
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 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1042 0x7fffffff, /* without WS_POPUP */
1043 CW_USEDEFAULT, CW_USEDEFAULT,
1044 CW_USEDEFAULT, CW_USEDEFAULT,
1045 mdi_client, 0, GetModuleHandle(0),
1046 (LPVOID)mdi_lParam_test_message);
1047 ok(mdi_child != 0, "MDI child creation failed\n");
1048 DestroyWindow(mdi_child);
1050 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1051 0xffffffff, /* with WS_POPUP */
1052 CW_USEDEFAULT, CW_USEDEFAULT,
1053 CW_USEDEFAULT, CW_USEDEFAULT,
1054 mdi_client, 0, GetModuleHandle(0),
1055 (LPVOID)mdi_lParam_test_message);
1056 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1058 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1059 DestroyWindow(mdi_child);
1062 ok(mdi_child != 0, "MDI child creation failed\n");
1064 /* test MDICREATESTRUCT A<->W mapping */
1065 SetLastError(0xdeadbeef);
1066 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1068 CW_USEDEFAULT, CW_USEDEFAULT,
1069 CW_USEDEFAULT, CW_USEDEFAULT,
1070 mdi_client, 0, GetModuleHandle(0),
1071 (LPVOID)mdi_lParam_test_message);
1074 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1077 ok(mdi_child != 0, "MDI child creation failed\n");
1079 DestroyWindow(mdi_child);
1081 /* This test fails on Win9x */
1084 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1086 CW_USEDEFAULT, CW_USEDEFAULT,
1087 CW_USEDEFAULT, CW_USEDEFAULT,
1088 parent, 0, GetModuleHandle(0),
1089 (LPVOID)mdi_lParam_test_message);
1090 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1093 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1094 WS_CHILD, /* without WS_POPUP */
1095 CW_USEDEFAULT, CW_USEDEFAULT,
1096 CW_USEDEFAULT, CW_USEDEFAULT,
1097 mdi_client, 0, GetModuleHandle(0),
1098 (LPVOID)mdi_lParam_test_message);
1099 ok(mdi_child != 0, "MDI child creation failed\n");
1100 DestroyWindow(mdi_child);
1102 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1103 WS_CHILD | WS_POPUP, /* with WS_POPUP */
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 /* maximized child */
1112 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1113 WS_CHILD | WS_MAXIMIZE,
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);
1121 trace("Creating maximized child with a caption\n");
1122 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1123 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1124 CW_USEDEFAULT, CW_USEDEFAULT,
1125 CW_USEDEFAULT, CW_USEDEFAULT,
1126 mdi_client, 0, GetModuleHandle(0),
1127 (LPVOID)mdi_lParam_test_message);
1128 ok(mdi_child != 0, "MDI child creation failed\n");
1129 DestroyWindow(mdi_child);
1131 trace("Creating maximized child with a caption and a thick frame\n");
1132 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1133 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1134 CW_USEDEFAULT, CW_USEDEFAULT,
1135 CW_USEDEFAULT, CW_USEDEFAULT,
1136 mdi_client, 0, GetModuleHandle(0),
1137 (LPVOID)mdi_lParam_test_message);
1138 ok(mdi_child != 0, "MDI child creation failed\n");
1139 DestroyWindow(mdi_child);
1142 /**********************************************************************
1143 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1145 * Note: The rule here is that client rect of the maximized MDI child
1146 * is equal to the client rect of the MDI client window.
1148 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1152 GetClientRect( client, &rect );
1153 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1154 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1156 rect.right -= rect.left;
1157 rect.bottom -= rect.top;
1158 lpMinMax->ptMaxSize.x = rect.right;
1159 lpMinMax->ptMaxSize.y = rect.bottom;
1161 lpMinMax->ptMaxPosition.x = rect.left;
1162 lpMinMax->ptMaxPosition.y = rect.top;
1164 trace("max rect (%ld,%ld - %ld, %ld)\n",
1165 rect.left, rect.top, rect.right, rect.bottom);
1168 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1175 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1176 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1178 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1179 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1181 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1182 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1183 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1184 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1185 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1187 /* MDICREATESTRUCT should have original values */
1188 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1189 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1190 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1191 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1192 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1193 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1195 /* CREATESTRUCT should have fixed values */
1196 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1197 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1199 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1200 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1201 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1203 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1205 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1207 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1208 ok(cs->style == style,
1209 "cs->style does not match (%08lx)\n", cs->style);
1213 LONG style = mdi_cs->style;
1215 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1216 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1217 ok(cs->style == style,
1218 "cs->style does not match (%08lx)\n", cs->style);
1223 case WM_GETMINMAXINFO:
1225 HWND client = GetParent(hwnd);
1227 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1228 MINMAXINFO my_minmax;
1229 LONG style, exstyle;
1231 style = GetWindowLongA(hwnd, GWL_STYLE);
1232 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1234 GetWindowRect(client, &rc);
1235 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1236 GetClientRect(client, &rc);
1237 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1238 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1239 GetSystemMetrics(SM_CYSCREEN));
1241 GetClientRect(client, &rc);
1242 if ((style & WS_CAPTION) == WS_CAPTION)
1243 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1244 AdjustWindowRectEx(&rc, style, 0, exstyle);
1245 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1247 trace("ptReserved = (%ld,%ld)\n"
1248 "ptMaxSize = (%ld,%ld)\n"
1249 "ptMaxPosition = (%ld,%ld)\n"
1250 "ptMinTrackSize = (%ld,%ld)\n"
1251 "ptMaxTrackSize = (%ld,%ld)\n",
1252 minmax->ptReserved.x, minmax->ptReserved.y,
1253 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1254 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1255 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1256 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1258 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1259 minmax->ptMaxSize.x, rc.right - rc.left);
1260 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1261 minmax->ptMaxSize.y, rc.bottom - rc.top);
1263 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1265 trace("DefMDIChildProc returned:\n"
1266 "ptReserved = (%ld,%ld)\n"
1267 "ptMaxSize = (%ld,%ld)\n"
1268 "ptMaxPosition = (%ld,%ld)\n"
1269 "ptMinTrackSize = (%ld,%ld)\n"
1270 "ptMaxTrackSize = (%ld,%ld)\n",
1271 minmax->ptReserved.x, minmax->ptReserved.y,
1272 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1273 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1274 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1275 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1277 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1278 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1279 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1280 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1281 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1286 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1289 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1296 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1298 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1299 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1301 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1302 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1304 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1305 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1307 /* CREATESTRUCT should have fixed values */
1308 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1310 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1311 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1313 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1314 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1315 while Win95, Win2k, WinXP do. */
1316 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1317 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1321 case WM_GETMINMAXINFO:
1323 HWND parent = GetParent(hwnd);
1325 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1326 LONG style, exstyle;
1328 trace("WM_GETMINMAXINFO\n");
1330 style = GetWindowLongA(hwnd, GWL_STYLE);
1331 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1333 GetClientRect(parent, &rc);
1334 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1336 GetClientRect(parent, &rc);
1337 if ((style & WS_CAPTION) == WS_CAPTION)
1338 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1339 AdjustWindowRectEx(&rc, style, 0, exstyle);
1340 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1342 trace("ptReserved = (%ld,%ld)\n"
1343 "ptMaxSize = (%ld,%ld)\n"
1344 "ptMaxPosition = (%ld,%ld)\n"
1345 "ptMinTrackSize = (%ld,%ld)\n"
1346 "ptMaxTrackSize = (%ld,%ld)\n",
1347 minmax->ptReserved.x, minmax->ptReserved.y,
1348 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1349 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1350 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1351 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1353 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1354 minmax->ptMaxSize.x, rc.right - rc.left);
1355 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1356 minmax->ptMaxSize.y, rc.bottom - rc.top);
1360 case WM_WINDOWPOSCHANGED:
1362 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1365 GetWindowRect(hwnd, &rc1);
1366 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1367 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1368 /* note: winpos coordinates are relative to parent */
1369 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1370 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1371 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1373 GetWindowRect(hwnd, &rc1);
1374 GetClientRect(hwnd, &rc2);
1375 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1376 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1377 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1380 case WM_WINDOWPOSCHANGING:
1382 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1383 WINDOWPOS my_winpos = *winpos;
1385 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1386 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1387 winpos->hwnd, winpos->hwndInsertAfter,
1388 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1390 DefWindowProcA(hwnd, msg, wparam, lparam);
1392 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1393 winpos->hwnd, winpos->hwndInsertAfter,
1394 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1396 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1397 "DefWindowProc should not change WINDOWPOS values\n");
1402 return DefWindowProcA(hwnd, msg, wparam, lparam);
1405 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1407 static HWND mdi_client;
1413 CLIENTCREATESTRUCT client_cs;
1416 GetClientRect(hwnd, &rc);
1418 client_cs.hWindowMenu = 0;
1419 client_cs.idFirstChild = 1;
1421 /* MDIClient without MDIS_ALLCHILDSTYLES */
1422 mdi_client = CreateWindowExA(0, "mdiclient",
1424 WS_CHILD /*| WS_VISIBLE*/,
1425 /* tests depend on a not zero MDIClient size */
1426 0, 0, rc.right, rc.bottom,
1427 hwnd, 0, GetModuleHandle(0),
1428 (LPVOID)&client_cs);
1430 test_MDI_create(hwnd, mdi_client);
1431 DestroyWindow(mdi_client);
1433 /* MDIClient with MDIS_ALLCHILDSTYLES */
1434 mdi_client = CreateWindowExA(0, "mdiclient",
1436 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1437 /* tests depend on a not zero MDIClient size */
1438 0, 0, rc.right, rc.bottom,
1439 hwnd, 0, GetModuleHandle(0),
1440 (LPVOID)&client_cs);
1442 test_MDI_create(hwnd, mdi_client);
1443 DestroyWindow(mdi_client);
1447 case WM_WINDOWPOSCHANGED:
1449 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1452 GetWindowRect(hwnd, &rc1);
1453 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1454 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1455 /* note: winpos coordinates are relative to parent */
1456 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1457 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1458 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1460 GetWindowRect(hwnd, &rc1);
1461 GetClientRect(hwnd, &rc2);
1462 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1463 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1464 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1467 case WM_WINDOWPOSCHANGING:
1469 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1470 WINDOWPOS my_winpos = *winpos;
1472 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1473 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1474 winpos->hwnd, winpos->hwndInsertAfter,
1475 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1477 DefWindowProcA(hwnd, msg, wparam, lparam);
1479 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1480 winpos->hwnd, winpos->hwndInsertAfter,
1481 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1483 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1484 "DefWindowProc should not change WINDOWPOS values\n");
1493 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1496 static BOOL mdi_RegisterWindowClasses(void)
1501 cls.lpfnWndProc = mdi_main_wnd_procA;
1504 cls.hInstance = GetModuleHandleA(0);
1506 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1507 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1508 cls.lpszMenuName = NULL;
1509 cls.lpszClassName = "MDI_parent_Class";
1510 if(!RegisterClassA(&cls)) return FALSE;
1512 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1513 cls.lpszClassName = "MDI_child_Class_1";
1514 if(!RegisterClassA(&cls)) return FALSE;
1516 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1517 cls.lpszClassName = "MDI_child_Class_2";
1518 if(!RegisterClassA(&cls)) return FALSE;
1523 static void test_mdi(void)
1528 if (!mdi_RegisterWindowClasses()) assert(0);
1530 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1531 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1532 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1533 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1534 GetDesktopWindow(), 0,
1535 GetModuleHandle(0), NULL);
1536 assert(mdi_hwndMain);
1538 while(GetMessage(&msg, 0, 0, 0))
1540 TranslateMessage(&msg);
1541 DispatchMessage(&msg);
1546 static void test_icons(void)
1550 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1551 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1552 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1553 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1556 cls.cbSize = sizeof(cls);
1558 cls.lpfnWndProc = DefWindowProcA;
1562 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1563 cls.hIconSm = small_icon;
1564 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1565 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1566 cls.lpszMenuName = NULL;
1567 cls.lpszClassName = "IconWindowClass";
1569 RegisterClassExA(&cls);
1571 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1572 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1575 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1576 ok( res == 0, "wrong big icon %p/0\n", res );
1577 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1578 ok( res == 0, "wrong previous big icon %p/0\n", res );
1579 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1580 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1581 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1582 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1583 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1584 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1586 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1587 ok( res == 0, "wrong small icon %p/0\n", res );
1588 /* this test is XP specific */
1589 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1590 ok( res != 0, "wrong small icon %p\n", res );*/
1591 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1592 ok( res == 0, "wrong previous small icon %p/0\n", res );
1593 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1594 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1595 /* this test is XP specific */
1596 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1597 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1598 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1599 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1600 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1601 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1602 /* this test is XP specific */
1603 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1604 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1606 /* make sure the big icon hasn't changed */
1607 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1608 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1611 static void test_SetWindowPos(HWND hwnd)
1614 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
1616 /* Win9x truncates coordinates to 16-bit irrespectively */
1617 if (is_win9x) return;
1619 GetWindowRect(hwnd, &orig_win_rc);
1621 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1622 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1624 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1625 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1627 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1628 orig_win_rc.right, orig_win_rc.bottom, 0);
1631 static void test_SetMenu(HWND parent)
1635 BOOL is_win9x = GetWindowLongW(parent, GWL_WNDPROC) == 0;
1637 hMenu = CreateMenu();
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);
1644 /* test whether we can destroy a menu assigned to a window */
1645 ok(DestroyMenu(hMenu), "DestroyMenu error %ld\n", GetLastError());
1646 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1647 ret = GetMenu(parent);
1648 /* This test fails on Win9x */
1650 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1651 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1652 test_nonclient_area(parent);
1654 hMenu = CreateMenu();
1658 ret = GetMenu(parent);
1659 ok(ret == 0, "unexpected menu id %p\n", ret);
1661 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1662 test_nonclient_area(parent);
1663 ret = GetMenu(parent);
1664 ok(ret == 0, "unexpected menu id %p\n", ret);
1666 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1667 test_nonclient_area(parent);
1668 ret = GetMenu(parent);
1669 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1671 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1672 test_nonclient_area(parent);
1673 ret = GetMenu(parent);
1674 ok(ret == 0, "unexpected menu id %p\n", ret);
1677 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1680 ret = GetMenu(child);
1681 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1683 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1684 test_nonclient_area(child);
1685 ret = GetMenu(child);
1686 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1688 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1689 test_nonclient_area(child);
1690 ret = GetMenu(child);
1691 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1693 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1694 test_nonclient_area(child);
1695 ret = GetMenu(child);
1696 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1698 DestroyWindow(child);
1702 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1704 HWND child[5], hwnd;
1709 hwnd = GetWindow(parent, GW_CHILD);
1710 ok(!hwnd, "have to start without children to perform the test\n");
1712 for (i = 0; i < total; i++)
1714 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1715 parent, 0, 0, NULL);
1716 trace("child[%d] = %p\n", i, child[i]);
1717 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1720 hwnd = GetWindow(parent, GW_CHILD);
1721 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1722 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1723 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1725 for (i = 0; i < total; i++)
1727 trace("hwnd[%d] = %p\n", i, hwnd);
1728 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1730 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1733 for (i = 0; i < total; i++)
1734 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1737 static void test_children_zorder(HWND parent)
1739 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1741 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1743 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1744 WS_CHILD | WS_VISIBLE, WS_CHILD,
1745 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1746 const int complex_order_1[1] = { 0 };
1747 const int complex_order_2[2] = { 1, 0 };
1748 const int complex_order_3[3] = { 1, 0, 2 };
1749 const int complex_order_4[4] = { 1, 0, 2, 3 };
1750 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1752 /* simple WS_CHILD */
1753 test_window_tree(parent, simple_style, simple_order, 5);
1755 /* complex children styles */
1756 test_window_tree(parent, complex_style, complex_order_1, 1);
1757 test_window_tree(parent, complex_style, complex_order_2, 2);
1758 test_window_tree(parent, complex_style, complex_order_3, 3);
1759 test_window_tree(parent, complex_style, complex_order_4, 4);
1760 test_window_tree(parent, complex_style, complex_order_5, 5);
1763 static void test_SetFocus(HWND hwnd)
1767 /* check if we can set focus to non-visible windows */
1769 ShowWindow(hwnd, SW_SHOW);
1772 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1773 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1774 ShowWindow(hwnd, SW_HIDE);
1777 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1778 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1779 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1782 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1783 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1784 ShowWindow(child, SW_SHOW);
1785 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1786 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1787 ShowWindow(child, SW_HIDE);
1788 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1789 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1790 ShowWindow(child, SW_SHOW);
1792 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1793 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1794 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1796 ShowWindow(child, SW_HIDE);
1798 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1799 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1800 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1801 ShowWindow(child, SW_HIDE);
1802 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1804 ShowWindow(hwnd, SW_SHOW);
1805 ShowWindow(child, SW_SHOW);
1807 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1808 EnableWindow(hwnd, FALSE);
1809 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1810 EnableWindow(hwnd, TRUE);
1812 DestroyWindow( child );
1815 static void test_SetActiveWindow(HWND hwnd)
1819 ShowWindow(hwnd, SW_SHOW);
1821 SetActiveWindow(hwnd);
1822 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1823 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1824 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1825 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1826 ShowWindow(hwnd, SW_HIDE);
1827 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1828 ShowWindow(hwnd, SW_SHOW);
1830 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1831 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1832 DestroyWindow(hwnd2);
1833 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1835 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1836 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1837 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1838 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1839 DestroyWindow(hwnd2);
1840 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1843 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
1845 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1847 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1848 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
1849 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
1852 static WNDPROC old_button_proc;
1854 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
1859 key_state = GetKeyState(VK_LBUTTON);
1860 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
1862 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
1864 if (msg == WM_LBUTTONDOWN)
1868 check_wnd_state(button, button, button, button);
1870 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1872 trace("hwnd %p\n", hwnd);
1874 check_wnd_state(button, button, button, button);
1876 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1878 check_wnd_state(button, button, button, button);
1880 DestroyWindow(hwnd);
1882 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1884 trace("hwnd %p\n", hwnd);
1886 check_wnd_state(button, button, button, button);
1888 /* button wnd proc should release capture on WM_KILLFOCUS if it does
1889 * match internal button state.
1891 SendMessage(button, WM_KILLFOCUS, 0, 0);
1892 check_wnd_state(button, button, button, 0);
1894 ShowWindow(hwnd, SW_SHOW);
1895 check_wnd_state(hwnd, hwnd, hwnd, 0);
1897 capture = SetCapture(hwnd);
1898 ok(capture == 0, "SetCapture() = %p\n", capture);
1900 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1902 DestroyWindow(hwnd);
1904 check_wnd_state(button, 0, button, 0);
1910 static void test_capture_1(void)
1912 HWND button, capture;
1914 capture = GetCapture();
1915 ok(capture == 0, "GetCapture() = %p\n", capture);
1917 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1919 trace("button %p\n", button);
1921 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
1923 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
1925 DestroyWindow(button);
1928 static void test_capture_2(void)
1930 HWND button, hwnd, capture;
1932 check_wnd_state(0, 0, 0, 0);
1934 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1936 trace("button %p\n", button);
1938 check_wnd_state(button, button, button, 0);
1940 capture = SetCapture(button);
1941 ok(capture == 0, "SetCapture() = %p\n", capture);
1943 check_wnd_state(button, button, button, button);
1945 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
1946 * internal button state.
1948 SendMessage(button, WM_KILLFOCUS, 0, 0);
1949 check_wnd_state(button, button, button, button);
1951 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1953 trace("hwnd %p\n", hwnd);
1955 check_wnd_state(button, button, button, button);
1957 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1959 check_wnd_state(button, button, button, button);
1961 DestroyWindow(hwnd);
1963 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1965 trace("hwnd %p\n", hwnd);
1967 check_wnd_state(button, button, button, button);
1969 ShowWindow(hwnd, SW_SHOW);
1971 check_wnd_state(hwnd, hwnd, hwnd, button);
1973 capture = SetCapture(hwnd);
1974 ok(capture == button, "SetCapture() = %p\n", capture);
1976 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1978 DestroyWindow(hwnd);
1979 check_wnd_state(button, button, button, 0);
1981 DestroyWindow(button);
1982 check_wnd_state(0, 0, 0, 0);
1985 static void test_capture_3(HWND hwnd1, HWND hwnd2)
1987 ShowWindow(hwnd1, SW_HIDE);
1988 ShowWindow(hwnd2, SW_HIDE);
1990 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
1991 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
1994 check_wnd_state(0, 0, 0, hwnd1);
1997 check_wnd_state(0, 0, 0, hwnd2);
1999 ShowWindow(hwnd1, SW_SHOW);
2000 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2005 static void test_keyboard_input(HWND hwnd)
2009 ShowWindow(hwnd, SW_SHOW);
2012 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2015 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2017 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2019 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2020 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2021 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2022 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2024 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2026 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2027 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2028 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2029 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2031 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2033 keybd_event(VK_SPACE, 0, 0, 0);
2034 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2035 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2036 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2039 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2041 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2043 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2044 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2045 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2046 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2048 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2050 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2051 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2052 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2053 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2055 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2057 keybd_event(VK_SPACE, 0, 0, 0);
2058 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2059 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2060 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2065 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2066 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2068 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
2071 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
2074 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
2075 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2076 trace("hwndMessage %p\n", hwndMessage);
2078 DestroyWindow(hwndMain);
2081 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2083 if (!RegisterWindowClasses()) assert(0);
2085 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
2088 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2089 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2090 WS_MAXIMIZEBOX | WS_POPUP,
2093 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2094 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2095 WS_MAXIMIZEBOX | WS_POPUP,
2099 assert( hwndMain2 );
2103 test_capture_3(hwndMain, hwndMain2);
2105 test_parent_owner();
2106 test_shell_window();
2110 test_SetWindowPos(hwndMain);
2111 test_SetMenu(hwndMain);
2112 test_SetFocus(hwndMain);
2113 test_SetActiveWindow(hwndMain);
2115 test_children_zorder(hwndMain);
2116 test_keyboard_input(hwndMain);
2118 UnhookWindowsHookEx(hhook);