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, INT first_id)
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 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
951 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
952 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
954 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
955 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
956 ok(mdi_child != 0, "MDI child creation failed\n");
957 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
958 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
959 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
961 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
962 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
963 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
965 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
969 ok(mdi_child != 0, "MDI child creation failed\n");
970 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
971 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
972 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
975 /* test MDICREATESTRUCT A<->W mapping */
976 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
978 mdi_cs.szClass = (LPCSTR)classW;
979 mdi_cs.szTitle = (LPCSTR)titleW;
980 SetLastError(0xdeadbeef);
981 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
984 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
987 ok(mdi_child != 0, "MDI child creation failed\n");
991 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
992 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
993 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
996 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
998 CW_USEDEFAULT, CW_USEDEFAULT,
999 CW_USEDEFAULT, CW_USEDEFAULT,
1000 mdi_client, GetModuleHandle(0),
1001 (LPARAM)mdi_lParam_test_message);
1002 ok(mdi_child != 0, "MDI child creation failed\n");
1003 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1004 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1005 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1007 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1008 0x7fffffff, /* without WS_POPUP */
1009 CW_USEDEFAULT, CW_USEDEFAULT,
1010 CW_USEDEFAULT, CW_USEDEFAULT,
1011 mdi_client, GetModuleHandle(0),
1012 (LPARAM)mdi_lParam_test_message);
1013 ok(mdi_child != 0, "MDI child creation failed\n");
1014 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1015 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1016 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1018 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1019 0xffffffff, /* with WS_POPUP */
1020 CW_USEDEFAULT, CW_USEDEFAULT,
1021 CW_USEDEFAULT, CW_USEDEFAULT,
1022 mdi_client, GetModuleHandle(0),
1023 (LPARAM)mdi_lParam_test_message);
1024 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1026 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1030 ok(mdi_child != 0, "MDI child creation failed\n");
1031 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1032 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1033 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1036 /* test MDICREATESTRUCT A<->W mapping */
1037 SetLastError(0xdeadbeef);
1038 mdi_child = CreateMDIWindowW(classW, titleW,
1040 CW_USEDEFAULT, CW_USEDEFAULT,
1041 CW_USEDEFAULT, CW_USEDEFAULT,
1042 mdi_client, GetModuleHandle(0),
1043 (LPARAM)mdi_lParam_test_message);
1046 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1049 ok(mdi_child != 0, "MDI child creation failed\n");
1053 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1054 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1055 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1058 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1060 CW_USEDEFAULT, CW_USEDEFAULT,
1061 CW_USEDEFAULT, CW_USEDEFAULT,
1062 mdi_client, 0, GetModuleHandle(0),
1063 (LPVOID)mdi_lParam_test_message);
1064 ok(mdi_child != 0, "MDI child creation failed\n");
1065 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1066 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1067 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1069 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1070 0x7fffffff, /* without WS_POPUP */
1071 CW_USEDEFAULT, CW_USEDEFAULT,
1072 CW_USEDEFAULT, CW_USEDEFAULT,
1073 mdi_client, 0, GetModuleHandle(0),
1074 (LPVOID)mdi_lParam_test_message);
1075 ok(mdi_child != 0, "MDI child creation failed\n");
1076 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1077 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1078 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1080 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1081 0xffffffff, /* with WS_POPUP */
1082 CW_USEDEFAULT, CW_USEDEFAULT,
1083 CW_USEDEFAULT, CW_USEDEFAULT,
1084 mdi_client, 0, GetModuleHandle(0),
1085 (LPVOID)mdi_lParam_test_message);
1086 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1088 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1092 ok(mdi_child != 0, "MDI child creation failed\n");
1093 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1094 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1095 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1098 /* test MDICREATESTRUCT A<->W mapping */
1099 SetLastError(0xdeadbeef);
1100 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1102 CW_USEDEFAULT, CW_USEDEFAULT,
1103 CW_USEDEFAULT, CW_USEDEFAULT,
1104 mdi_client, 0, GetModuleHandle(0),
1105 (LPVOID)mdi_lParam_test_message);
1108 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1111 ok(mdi_child != 0, "MDI child creation failed\n");
1115 ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1116 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1117 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1120 /* This test fails on Win9x */
1123 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1125 CW_USEDEFAULT, CW_USEDEFAULT,
1126 CW_USEDEFAULT, CW_USEDEFAULT,
1127 parent, 0, GetModuleHandle(0),
1128 (LPVOID)mdi_lParam_test_message);
1129 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1132 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1133 WS_CHILD, /* without WS_POPUP */
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 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1140 DestroyWindow(mdi_child);
1142 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1143 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1144 CW_USEDEFAULT, CW_USEDEFAULT,
1145 CW_USEDEFAULT, CW_USEDEFAULT,
1146 mdi_client, 0, GetModuleHandle(0),
1147 (LPVOID)mdi_lParam_test_message);
1148 ok(mdi_child != 0, "MDI child creation failed\n");
1149 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1150 DestroyWindow(mdi_child);
1152 /* maximized child */
1153 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1154 WS_CHILD | WS_MAXIMIZE,
1155 CW_USEDEFAULT, CW_USEDEFAULT,
1156 CW_USEDEFAULT, CW_USEDEFAULT,
1157 mdi_client, 0, GetModuleHandle(0),
1158 (LPVOID)mdi_lParam_test_message);
1159 ok(mdi_child != 0, "MDI child creation failed\n");
1160 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1161 DestroyWindow(mdi_child);
1163 trace("Creating maximized child with a caption\n");
1164 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1165 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1166 CW_USEDEFAULT, CW_USEDEFAULT,
1167 CW_USEDEFAULT, CW_USEDEFAULT,
1168 mdi_client, 0, GetModuleHandle(0),
1169 (LPVOID)mdi_lParam_test_message);
1170 ok(mdi_child != 0, "MDI child creation failed\n");
1171 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1172 DestroyWindow(mdi_child);
1174 trace("Creating maximized child with a caption and a thick frame\n");
1175 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1176 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1177 CW_USEDEFAULT, CW_USEDEFAULT,
1178 CW_USEDEFAULT, CW_USEDEFAULT,
1179 mdi_client, 0, GetModuleHandle(0),
1180 (LPVOID)mdi_lParam_test_message);
1181 ok(mdi_child != 0, "MDI child creation failed\n");
1182 ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1183 DestroyWindow(mdi_child);
1186 /**********************************************************************
1187 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1189 * Note: The rule here is that client rect of the maximized MDI child
1190 * is equal to the client rect of the MDI client window.
1192 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1196 GetClientRect( client, &rect );
1197 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1198 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1200 rect.right -= rect.left;
1201 rect.bottom -= rect.top;
1202 lpMinMax->ptMaxSize.x = rect.right;
1203 lpMinMax->ptMaxSize.y = rect.bottom;
1205 lpMinMax->ptMaxPosition.x = rect.left;
1206 lpMinMax->ptMaxPosition.y = rect.top;
1208 trace("max rect (%ld,%ld - %ld, %ld)\n",
1209 rect.left, rect.top, rect.right, rect.bottom);
1212 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1219 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1220 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1222 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1223 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1225 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1226 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1227 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1228 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1229 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1231 /* MDICREATESTRUCT should have original values */
1232 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1233 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1234 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1235 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1236 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1237 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1239 /* CREATESTRUCT should have fixed values */
1240 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1241 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1243 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1244 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1245 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1247 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1249 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1251 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1252 ok(cs->style == style,
1253 "cs->style does not match (%08lx)\n", cs->style);
1257 LONG style = mdi_cs->style;
1259 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1260 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1261 ok(cs->style == style,
1262 "cs->style does not match (%08lx)\n", cs->style);
1267 case WM_GETMINMAXINFO:
1269 HWND client = GetParent(hwnd);
1271 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1272 MINMAXINFO my_minmax;
1273 LONG style, exstyle;
1275 style = GetWindowLongA(hwnd, GWL_STYLE);
1276 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1278 GetWindowRect(client, &rc);
1279 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1280 GetClientRect(client, &rc);
1281 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1282 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1283 GetSystemMetrics(SM_CYSCREEN));
1285 GetClientRect(client, &rc);
1286 if ((style & WS_CAPTION) == WS_CAPTION)
1287 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1288 AdjustWindowRectEx(&rc, style, 0, exstyle);
1289 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1291 trace("ptReserved = (%ld,%ld)\n"
1292 "ptMaxSize = (%ld,%ld)\n"
1293 "ptMaxPosition = (%ld,%ld)\n"
1294 "ptMinTrackSize = (%ld,%ld)\n"
1295 "ptMaxTrackSize = (%ld,%ld)\n",
1296 minmax->ptReserved.x, minmax->ptReserved.y,
1297 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1298 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1299 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1300 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1302 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1303 minmax->ptMaxSize.x, rc.right - rc.left);
1304 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1305 minmax->ptMaxSize.y, rc.bottom - rc.top);
1307 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1309 trace("DefMDIChildProc returned:\n"
1310 "ptReserved = (%ld,%ld)\n"
1311 "ptMaxSize = (%ld,%ld)\n"
1312 "ptMaxPosition = (%ld,%ld)\n"
1313 "ptMinTrackSize = (%ld,%ld)\n"
1314 "ptMaxTrackSize = (%ld,%ld)\n",
1315 minmax->ptReserved.x, minmax->ptReserved.y,
1316 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1317 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1318 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1319 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1321 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1322 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1323 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1324 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1325 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1330 case WM_MDIACTIVATE:
1332 HWND active, client = GetParent(hwnd);
1333 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1334 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1335 if (hwnd == (HWND)lparam) /* if we are being activated */
1336 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1338 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1342 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1345 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1352 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1354 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1355 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1357 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1358 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1360 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1361 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1363 /* CREATESTRUCT should have fixed values */
1364 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1366 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1367 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1369 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1370 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1371 while Win95, Win2k, WinXP do. */
1372 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1373 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1377 case WM_GETMINMAXINFO:
1379 HWND parent = GetParent(hwnd);
1381 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1382 LONG style, exstyle;
1384 trace("WM_GETMINMAXINFO\n");
1386 style = GetWindowLongA(hwnd, GWL_STYLE);
1387 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1389 GetClientRect(parent, &rc);
1390 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1392 GetClientRect(parent, &rc);
1393 if ((style & WS_CAPTION) == WS_CAPTION)
1394 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1395 AdjustWindowRectEx(&rc, style, 0, exstyle);
1396 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1398 trace("ptReserved = (%ld,%ld)\n"
1399 "ptMaxSize = (%ld,%ld)\n"
1400 "ptMaxPosition = (%ld,%ld)\n"
1401 "ptMinTrackSize = (%ld,%ld)\n"
1402 "ptMaxTrackSize = (%ld,%ld)\n",
1403 minmax->ptReserved.x, minmax->ptReserved.y,
1404 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1405 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1406 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1407 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1409 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1410 minmax->ptMaxSize.x, rc.right - rc.left);
1411 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1412 minmax->ptMaxSize.y, rc.bottom - rc.top);
1416 case WM_WINDOWPOSCHANGED:
1418 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1421 GetWindowRect(hwnd, &rc1);
1422 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1423 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1424 /* note: winpos coordinates are relative to parent */
1425 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1426 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1427 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1429 GetWindowRect(hwnd, &rc1);
1430 GetClientRect(hwnd, &rc2);
1431 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1432 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1433 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1436 case WM_WINDOWPOSCHANGING:
1438 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1439 WINDOWPOS my_winpos = *winpos;
1441 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1442 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1443 winpos->hwnd, winpos->hwndInsertAfter,
1444 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1446 DefWindowProcA(hwnd, msg, wparam, lparam);
1448 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1449 winpos->hwnd, winpos->hwndInsertAfter,
1450 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1452 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1453 "DefWindowProc should not change WINDOWPOS values\n");
1458 return DefWindowProcA(hwnd, msg, wparam, lparam);
1461 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1463 static HWND mdi_client;
1469 CLIENTCREATESTRUCT client_cs;
1472 GetClientRect(hwnd, &rc);
1474 client_cs.hWindowMenu = 0;
1475 client_cs.idFirstChild = 1;
1477 /* MDIClient without MDIS_ALLCHILDSTYLES */
1478 mdi_client = CreateWindowExA(0, "mdiclient",
1480 WS_CHILD /*| WS_VISIBLE*/,
1481 /* tests depend on a not zero MDIClient size */
1482 0, 0, rc.right, rc.bottom,
1483 hwnd, 0, GetModuleHandle(0),
1484 (LPVOID)&client_cs);
1486 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1487 DestroyWindow(mdi_client);
1489 /* MDIClient with MDIS_ALLCHILDSTYLES */
1490 mdi_client = CreateWindowExA(0, "mdiclient",
1492 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1493 /* tests depend on a not zero MDIClient size */
1494 0, 0, rc.right, rc.bottom,
1495 hwnd, 0, GetModuleHandle(0),
1496 (LPVOID)&client_cs);
1498 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1499 DestroyWindow(mdi_client);
1503 case WM_WINDOWPOSCHANGED:
1505 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1508 GetWindowRect(hwnd, &rc1);
1509 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1510 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1511 /* note: winpos coordinates are relative to parent */
1512 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1513 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1514 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1516 GetWindowRect(hwnd, &rc1);
1517 GetClientRect(hwnd, &rc2);
1518 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1519 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1520 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1523 case WM_WINDOWPOSCHANGING:
1525 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1526 WINDOWPOS my_winpos = *winpos;
1528 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1529 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1530 winpos->hwnd, winpos->hwndInsertAfter,
1531 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1533 DefWindowProcA(hwnd, msg, wparam, lparam);
1535 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1536 winpos->hwnd, winpos->hwndInsertAfter,
1537 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1539 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1540 "DefWindowProc should not change WINDOWPOS values\n");
1549 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1552 static BOOL mdi_RegisterWindowClasses(void)
1557 cls.lpfnWndProc = mdi_main_wnd_procA;
1560 cls.hInstance = GetModuleHandleA(0);
1562 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1563 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1564 cls.lpszMenuName = NULL;
1565 cls.lpszClassName = "MDI_parent_Class";
1566 if(!RegisterClassA(&cls)) return FALSE;
1568 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1569 cls.lpszClassName = "MDI_child_Class_1";
1570 if(!RegisterClassA(&cls)) return FALSE;
1572 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1573 cls.lpszClassName = "MDI_child_Class_2";
1574 if(!RegisterClassA(&cls)) return FALSE;
1579 static void test_mdi(void)
1584 if (!mdi_RegisterWindowClasses()) assert(0);
1586 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1587 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1588 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1589 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1590 GetDesktopWindow(), 0,
1591 GetModuleHandle(0), NULL);
1592 assert(mdi_hwndMain);
1594 while(GetMessage(&msg, 0, 0, 0))
1596 TranslateMessage(&msg);
1597 DispatchMessage(&msg);
1602 static void test_icons(void)
1606 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1607 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1608 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1609 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1612 cls.cbSize = sizeof(cls);
1614 cls.lpfnWndProc = DefWindowProcA;
1618 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1619 cls.hIconSm = small_icon;
1620 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1621 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1622 cls.lpszMenuName = NULL;
1623 cls.lpszClassName = "IconWindowClass";
1625 RegisterClassExA(&cls);
1627 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1628 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1631 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1632 ok( res == 0, "wrong big icon %p/0\n", res );
1633 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1634 ok( res == 0, "wrong previous big icon %p/0\n", res );
1635 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1636 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1637 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1638 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1639 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1640 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1642 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1643 ok( res == 0, "wrong small icon %p/0\n", res );
1644 /* this test is XP specific */
1645 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1646 ok( res != 0, "wrong small icon %p\n", res );*/
1647 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1648 ok( res == 0, "wrong previous small icon %p/0\n", res );
1649 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1650 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1651 /* this test is XP specific */
1652 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1653 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1654 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1655 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1656 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1657 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1658 /* this test is XP specific */
1659 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1660 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1662 /* make sure the big icon hasn't changed */
1663 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1664 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1667 static void test_SetWindowPos(HWND hwnd)
1670 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
1672 /* Win9x truncates coordinates to 16-bit irrespectively */
1673 if (is_win9x) return;
1675 GetWindowRect(hwnd, &orig_win_rc);
1677 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1678 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1680 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1681 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1683 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1684 orig_win_rc.right, orig_win_rc.bottom, 0);
1687 static void test_SetMenu(HWND parent)
1691 BOOL is_win9x = GetWindowLongW(parent, GWL_WNDPROC) == 0;
1694 hMenu = CreateMenu();
1697 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1698 test_nonclient_area(parent);
1699 ret = GetMenu(parent);
1700 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1701 /* test whether we can destroy a menu assigned to a window */
1702 retok = DestroyMenu(hMenu);
1703 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1704 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1705 ret = GetMenu(parent);
1706 /* This test fails on Win9x */
1708 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1709 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1710 test_nonclient_area(parent);
1712 hMenu = CreateMenu();
1716 ret = GetMenu(parent);
1717 ok(ret == 0, "unexpected menu id %p\n", ret);
1719 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1720 test_nonclient_area(parent);
1721 ret = GetMenu(parent);
1722 ok(ret == 0, "unexpected menu id %p\n", ret);
1724 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1725 test_nonclient_area(parent);
1726 ret = GetMenu(parent);
1727 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1729 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1730 test_nonclient_area(parent);
1731 ret = GetMenu(parent);
1732 ok(ret == 0, "unexpected menu id %p\n", ret);
1735 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1738 ret = GetMenu(child);
1739 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1741 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1742 test_nonclient_area(child);
1743 ret = GetMenu(child);
1744 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1746 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1747 test_nonclient_area(child);
1748 ret = GetMenu(child);
1749 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1751 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1752 test_nonclient_area(child);
1753 ret = GetMenu(child);
1754 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1756 DestroyWindow(child);
1760 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1762 HWND child[5], hwnd;
1767 hwnd = GetWindow(parent, GW_CHILD);
1768 ok(!hwnd, "have to start without children to perform the test\n");
1770 for (i = 0; i < total; i++)
1772 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1773 parent, 0, 0, NULL);
1774 trace("child[%d] = %p\n", i, child[i]);
1775 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1778 hwnd = GetWindow(parent, GW_CHILD);
1779 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1780 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1781 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1783 for (i = 0; i < total; i++)
1785 trace("hwnd[%d] = %p\n", i, hwnd);
1786 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1788 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1791 for (i = 0; i < total; i++)
1792 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1795 static void test_children_zorder(HWND parent)
1797 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1799 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1801 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1802 WS_CHILD | WS_VISIBLE, WS_CHILD,
1803 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1804 const int complex_order_1[1] = { 0 };
1805 const int complex_order_2[2] = { 1, 0 };
1806 const int complex_order_3[3] = { 1, 0, 2 };
1807 const int complex_order_4[4] = { 1, 0, 2, 3 };
1808 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1810 /* simple WS_CHILD */
1811 test_window_tree(parent, simple_style, simple_order, 5);
1813 /* complex children styles */
1814 test_window_tree(parent, complex_style, complex_order_1, 1);
1815 test_window_tree(parent, complex_style, complex_order_2, 2);
1816 test_window_tree(parent, complex_style, complex_order_3, 3);
1817 test_window_tree(parent, complex_style, complex_order_4, 4);
1818 test_window_tree(parent, complex_style, complex_order_5, 5);
1821 static void test_SetFocus(HWND hwnd)
1825 /* check if we can set focus to non-visible windows */
1827 ShowWindow(hwnd, SW_SHOW);
1830 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1831 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1832 ShowWindow(hwnd, SW_HIDE);
1835 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1836 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1837 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1840 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1841 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1842 ShowWindow(child, SW_SHOW);
1843 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1844 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1845 ShowWindow(child, SW_HIDE);
1846 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1847 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1848 ShowWindow(child, SW_SHOW);
1850 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1851 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1852 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1854 ShowWindow(child, SW_HIDE);
1856 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1857 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1858 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1859 ShowWindow(child, SW_HIDE);
1860 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1862 ShowWindow(hwnd, SW_SHOW);
1863 ShowWindow(child, SW_SHOW);
1865 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1866 EnableWindow(hwnd, FALSE);
1867 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1868 EnableWindow(hwnd, TRUE);
1870 DestroyWindow( child );
1873 static void test_SetActiveWindow(HWND hwnd)
1877 ShowWindow(hwnd, SW_SHOW);
1879 SetActiveWindow(hwnd);
1880 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1881 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1882 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1883 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1884 ShowWindow(hwnd, SW_HIDE);
1885 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1887 /* trace("**testing an invisible window now\n"); */
1888 SetActiveWindow(hwnd);
1889 ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
1890 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
1892 ShowWindow(hwnd, SW_SHOW);
1894 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1895 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1896 DestroyWindow(hwnd2);
1897 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1899 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1900 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1901 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1902 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1903 DestroyWindow(hwnd2);
1904 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1907 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
1909 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1911 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1912 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
1913 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
1916 static WNDPROC old_button_proc;
1918 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
1923 key_state = GetKeyState(VK_LBUTTON);
1924 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
1926 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
1928 if (msg == WM_LBUTTONDOWN)
1932 check_wnd_state(button, button, button, button);
1934 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1936 trace("hwnd %p\n", hwnd);
1938 check_wnd_state(button, button, button, button);
1940 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1942 check_wnd_state(button, button, button, button);
1944 DestroyWindow(hwnd);
1946 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1948 trace("hwnd %p\n", hwnd);
1950 check_wnd_state(button, button, button, button);
1952 /* button wnd proc should release capture on WM_KILLFOCUS if it does
1953 * match internal button state.
1955 SendMessage(button, WM_KILLFOCUS, 0, 0);
1956 check_wnd_state(button, button, button, 0);
1958 ShowWindow(hwnd, SW_SHOW);
1959 check_wnd_state(hwnd, hwnd, hwnd, 0);
1961 capture = SetCapture(hwnd);
1962 ok(capture == 0, "SetCapture() = %p\n", capture);
1964 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1966 DestroyWindow(hwnd);
1968 check_wnd_state(button, 0, button, 0);
1974 static void test_capture_1(void)
1976 HWND button, capture;
1978 capture = GetCapture();
1979 ok(capture == 0, "GetCapture() = %p\n", capture);
1981 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1983 trace("button %p\n", button);
1985 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
1987 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
1989 DestroyWindow(button);
1992 static void test_capture_2(void)
1994 HWND button, hwnd, capture;
1996 check_wnd_state(0, 0, 0, 0);
1998 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2000 trace("button %p\n", button);
2002 check_wnd_state(button, button, button, 0);
2004 capture = SetCapture(button);
2005 ok(capture == 0, "SetCapture() = %p\n", capture);
2007 check_wnd_state(button, button, button, button);
2009 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2010 * internal button state.
2012 SendMessage(button, WM_KILLFOCUS, 0, 0);
2013 check_wnd_state(button, button, button, button);
2015 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2017 trace("hwnd %p\n", hwnd);
2019 check_wnd_state(button, button, button, button);
2021 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2023 check_wnd_state(button, button, button, button);
2025 DestroyWindow(hwnd);
2027 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2029 trace("hwnd %p\n", hwnd);
2031 check_wnd_state(button, button, button, button);
2033 ShowWindow(hwnd, SW_SHOW);
2035 check_wnd_state(hwnd, hwnd, hwnd, button);
2037 capture = SetCapture(hwnd);
2038 ok(capture == button, "SetCapture() = %p\n", capture);
2040 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2042 DestroyWindow(hwnd);
2043 check_wnd_state(button, button, button, 0);
2045 DestroyWindow(button);
2046 check_wnd_state(0, 0, 0, 0);
2049 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2051 ShowWindow(hwnd1, SW_HIDE);
2052 ShowWindow(hwnd2, SW_HIDE);
2054 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2055 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2058 check_wnd_state(0, 0, 0, hwnd1);
2061 check_wnd_state(0, 0, 0, hwnd2);
2063 ShowWindow(hwnd1, SW_SHOW);
2064 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2069 static void test_keyboard_input(HWND hwnd)
2074 ShowWindow(hwnd, SW_SHOW);
2077 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2080 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2082 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2084 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2085 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2086 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2087 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2088 ok( !ret, "message %04x available\n", msg.message);
2090 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2092 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2093 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2094 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2095 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2096 ok( !ret, "message %04x available\n", msg.message);
2098 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2100 keybd_event(VK_SPACE, 0, 0, 0);
2101 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2102 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2103 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2104 ok( !ret, "message %04x available\n", msg.message);
2107 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2109 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2111 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2112 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2113 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2114 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2115 ok( !ret, "message %04x available\n", msg.message);
2117 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2119 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2120 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2121 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2122 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2123 ok( !ret, "message %04x available\n", msg.message);
2125 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2127 keybd_event(VK_SPACE, 0, 0, 0);
2128 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2129 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2130 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2131 ok( !ret, "message %04x available\n", msg.message);
2134 static void test_mouse_input(HWND hwnd)
2143 ShowWindow(hwnd, SW_SHOW);
2146 GetWindowRect(hwnd, &rc);
2147 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2149 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2150 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2153 ShowWindow(popup, SW_SHOW);
2154 UpdateWindow(popup);
2156 GetWindowRect(popup, &rc);
2157 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2159 x = rc.left + (rc.right - rc.left) / 2;
2160 y = rc.top + (rc.bottom - rc.top) / 2;
2161 trace("setting cursor to (%d,%d)\n", x, y);
2165 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2167 /* force the system to update its internal queue mouse position,
2168 * otherwise it won't generate relative mouse movements below.
2170 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2171 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2174 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2175 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2176 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2177 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2178 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2179 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2180 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2181 ok( !ret, "message %04x available\n", msg.message);
2183 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2184 ShowWindow(popup, SW_HIDE);
2185 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2186 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2187 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2189 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2190 ShowWindow(hwnd, SW_HIDE);
2191 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2192 ok( !ret, "message %04x available\n", msg.message);
2194 DestroyWindow(popup);
2199 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2200 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2202 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
2205 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
2208 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
2209 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2210 trace("hwndMessage %p\n", hwndMessage);
2212 DestroyWindow(hwndMain);
2215 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2217 if (!RegisterWindowClasses()) assert(0);
2219 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
2222 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2223 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2224 WS_MAXIMIZEBOX | WS_POPUP,
2227 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2228 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2229 WS_MAXIMIZEBOX | WS_POPUP,
2233 assert( hwndMain2 );
2237 test_capture_3(hwndMain, hwndMain2);
2239 test_parent_owner();
2240 test_shell_window();
2244 test_SetWindowPos(hwndMain);
2245 test_SetMenu(hwndMain);
2246 test_SetFocus(hwndMain);
2247 test_SetActiveWindow(hwndMain);
2249 test_children_zorder(hwndMain);
2250 test_keyboard_input(hwndMain);
2251 test_mouse_input(hwndMain);
2253 UnhookWindowsHookEx(hhook);