Add a test case for WM_KEY* to WM_SYSKEY* message conversion.
[wine/dcerpc.git] / dlls / user / tests / win.c
blob90477c54c6dbf44448438e229b402b8a077ba7d6
1 /*
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
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stdio.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
43 #endif
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;
53 static HHOOK hhook;
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 )
59 HWND res;
61 if (pGetAncestor)
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 );
72 if (pGetAncestor)
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" );
87 return ret;
90 /* test parent and owner values for various combinations */
91 static void test_parent_owner(void)
93 LONG style;
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" );
105 /* desktop window */
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 );
155 /* child of child */
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 );
215 /* owned popup */
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" );
282 /* desktop window */
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 );
290 #endif
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 );
377 /* owned popup */
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 );
407 DestroyWindow(test);
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 );*/
431 DestroyWindow(test);
433 /* final cleanup */
434 DestroyWindow(child);
438 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
440 switch (msg)
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);
455 break;
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);
476 break;
478 case WM_WINDOWPOSCHANGED:
480 RECT rc1, rc2;
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");
500 #endif
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");
506 break;
508 case WM_NCCREATE:
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");
519 else
520 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
521 break;
525 return DefWindowProcA(hwnd, msg, wparam, lparam);
528 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
530 switch (msg)
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);
545 break;
547 case WM_NCCREATE:
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");
558 else
559 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
560 break;
564 return DefWindowProcA(hwnd, msg, wparam, lparam);
567 static BOOL RegisterWindowClasses(void)
569 WNDCLASSA cls;
571 cls.style = 0;
572 cls.lpfnWndProc = main_window_procA;
573 cls.cbClsExtra = 0;
574 cls.cbWndExtra = 0;
575 cls.hInstance = GetModuleHandleA(0);
576 cls.hIcon = 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;
584 cls.style = 0;
585 cls.lpfnWndProc = tool_window_procA;
586 cls.cbClsExtra = 0;
587 cls.cbWndExtra = 0;
588 cls.hInstance = GetModuleHandleA(0);
589 cls.hIcon = 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;
597 return TRUE;
600 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
602 RECT rcWindow, rcClient;
603 UINT border;
604 DWORD status;
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;
641 BOOL menu;
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");
662 #endif
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");
670 #endif
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");
686 #endif
689 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
691 static const char *CBT_code_name[10] = {
692 "HCBT_MOVESIZE",
693 "HCBT_MINMAX",
694 "HCBT_QS",
695 "HCBT_CREATEWND",
696 "HCBT_DESTROYWND",
697 "HCBT_ACTIVATE",
698 "HCBT_CLICKSKIPPED",
699 "HCBT_KEYSKIPPED",
700 "HCBT_SYSCOMMAND",
701 "HCBT_SETFOCUS" };
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 */;
712 else
713 test_nonclient_area((HWND)wParam);
715 if (pGetWindowInfo)
717 WINDOWINFO info;
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);
732 switch (nCode)
734 case HCBT_CREATEWND:
736 #if 0 /* Uncomment this once the test succeeds in all cases */
737 static const RECT rc_null;
738 RECT rc;
739 #endif
740 LONG style;
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);
759 else
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");
763 #endif
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");
769 #endif
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 */
774 if (pGetAncestor)
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");
783 else
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");
792 #endif
793 break;
797 return CallNextHookEx(hhook, nCode, wParam, lParam);
800 static void test_shell_window()
802 BOOL ret;
803 DWORD error;
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 shellWindow = GetShellWindow();
811 hinst = GetModuleHandle(0);
812 hUser32 = GetModuleHandleA("user32");
814 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
815 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
817 trace("previous shell window: %p\n", shellWindow);
819 if (shellWindow) {
820 ret = DestroyWindow(shellWindow);
821 error = GetLastError();
823 ok(!ret, "DestroyWindow(shellWindow)\n");
824 /* passes on Win XP, but not on Win98
825 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n"); */
828 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
829 trace("created window 1: %p\n", hwnd1);
831 ret = SetShellWindow(hwnd1);
832 ok(ret, "first call to SetShellWindow(hwnd1)\n");
833 shellWindow = GetShellWindow();
834 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
836 ret = SetShellWindow(hwnd1);
837 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
839 ret = SetShellWindow(0);
840 error = GetLastError();
841 /* passes on Win XP, but not on Win98
842 ok(!ret, "reset shell window by SetShellWindow(0)\n");
843 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
845 ret = SetShellWindow(hwnd1);
846 /* passes on Win XP, but not on Win98
847 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
849 todo_wine
851 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
852 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
853 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
856 ret = DestroyWindow(hwnd1);
857 ok(ret, "DestroyWindow(hwnd1)\n");
859 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
860 trace("created window 2: %p\n", hwnd2);
861 ret = SetShellWindow(hwnd2);
862 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
864 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
865 trace("created window 3: %p\n", hwnd3);
867 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
868 trace("created window 4: %p\n", hwnd4);
870 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
871 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
873 ret = SetShellWindow(hwnd4);
874 ok(ret, "SetShellWindow(hwnd4)\n");
875 shellWindow = GetShellWindow();
876 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
878 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
879 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
881 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
882 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
884 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
885 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
887 ret = SetShellWindow(hwnd3);
888 ok(!ret, "SetShellWindow(hwnd3)\n");
889 shellWindow = GetShellWindow();
890 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
892 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
893 trace("created window 5: %p\n", hwnd5);
894 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
895 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
897 todo_wine
899 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
900 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
903 /* destroy test windows */
904 DestroyWindow(hwnd2);
905 DestroyWindow(hwnd3);
906 DestroyWindow(hwnd4);
907 DestroyWindow(hwnd5);
910 /************** MDI test ****************/
912 static const char mdi_lParam_test_message[] = "just a test string";
914 static void test_MDI_create(HWND parent, HWND mdi_client)
916 MDICREATESTRUCTA mdi_cs;
917 HWND mdi_child;
918 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
919 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
920 BOOL isWin9x = FALSE;
922 mdi_cs.szClass = "MDI_child_Class_1";
923 mdi_cs.szTitle = "MDI child";
924 mdi_cs.hOwner = GetModuleHandle(0);
925 mdi_cs.x = CW_USEDEFAULT;
926 mdi_cs.y = CW_USEDEFAULT;
927 mdi_cs.cx = CW_USEDEFAULT;
928 mdi_cs.cy = CW_USEDEFAULT;
929 mdi_cs.style = 0;
930 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
931 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
932 ok(mdi_child != 0, "MDI child creation failed\n");
933 DestroyWindow(mdi_child);
935 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
936 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
937 ok(mdi_child != 0, "MDI child creation failed\n");
938 DestroyWindow(mdi_child);
940 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
941 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
942 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
944 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
945 DestroyWindow(mdi_child);
947 else
948 ok(mdi_child != 0, "MDI child creation failed\n");
950 /* test MDICREATESTRUCT A<->W mapping */
951 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
952 mdi_cs.style = 0;
953 mdi_cs.szClass = (LPCSTR)classW;
954 mdi_cs.szTitle = (LPCSTR)titleW;
955 SetLastError(0xdeadbeef);
956 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
957 if (!mdi_child)
959 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
960 isWin9x = TRUE;
961 else
962 ok(mdi_child != 0, "MDI child creation failed\n");
964 DestroyWindow(mdi_child);
966 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
968 CW_USEDEFAULT, CW_USEDEFAULT,
969 CW_USEDEFAULT, CW_USEDEFAULT,
970 mdi_client, GetModuleHandle(0),
971 (LPARAM)mdi_lParam_test_message);
972 ok(mdi_child != 0, "MDI child creation failed\n");
973 DestroyWindow(mdi_child);
975 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
976 0x7fffffff, /* without WS_POPUP */
977 CW_USEDEFAULT, CW_USEDEFAULT,
978 CW_USEDEFAULT, CW_USEDEFAULT,
979 mdi_client, GetModuleHandle(0),
980 (LPARAM)mdi_lParam_test_message);
981 ok(mdi_child != 0, "MDI child creation failed\n");
982 DestroyWindow(mdi_child);
984 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
985 0xffffffff, /* with WS_POPUP */
986 CW_USEDEFAULT, CW_USEDEFAULT,
987 CW_USEDEFAULT, CW_USEDEFAULT,
988 mdi_client, GetModuleHandle(0),
989 (LPARAM)mdi_lParam_test_message);
990 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
992 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
993 DestroyWindow(mdi_child);
995 else
996 ok(mdi_child != 0, "MDI child creation failed\n");
998 /* test MDICREATESTRUCT A<->W mapping */
999 SetLastError(0xdeadbeef);
1000 mdi_child = CreateMDIWindowW(classW, titleW,
1002 CW_USEDEFAULT, CW_USEDEFAULT,
1003 CW_USEDEFAULT, CW_USEDEFAULT,
1004 mdi_client, GetModuleHandle(0),
1005 (LPARAM)mdi_lParam_test_message);
1006 if (!mdi_child)
1008 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1009 isWin9x = TRUE;
1010 else
1011 ok(mdi_child != 0, "MDI child creation failed\n");
1013 DestroyWindow(mdi_child);
1015 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1017 CW_USEDEFAULT, CW_USEDEFAULT,
1018 CW_USEDEFAULT, CW_USEDEFAULT,
1019 mdi_client, 0, GetModuleHandle(0),
1020 (LPVOID)mdi_lParam_test_message);
1021 ok(mdi_child != 0, "MDI child creation failed\n");
1022 DestroyWindow(mdi_child);
1024 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1025 0x7fffffff, /* without WS_POPUP */
1026 CW_USEDEFAULT, CW_USEDEFAULT,
1027 CW_USEDEFAULT, CW_USEDEFAULT,
1028 mdi_client, 0, GetModuleHandle(0),
1029 (LPVOID)mdi_lParam_test_message);
1030 ok(mdi_child != 0, "MDI child creation failed\n");
1031 DestroyWindow(mdi_child);
1033 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1034 0xffffffff, /* with WS_POPUP */
1035 CW_USEDEFAULT, CW_USEDEFAULT,
1036 CW_USEDEFAULT, CW_USEDEFAULT,
1037 mdi_client, 0, GetModuleHandle(0),
1038 (LPVOID)mdi_lParam_test_message);
1039 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1041 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1042 DestroyWindow(mdi_child);
1044 else
1045 ok(mdi_child != 0, "MDI child creation failed\n");
1047 /* test MDICREATESTRUCT A<->W mapping */
1048 SetLastError(0xdeadbeef);
1049 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1051 CW_USEDEFAULT, CW_USEDEFAULT,
1052 CW_USEDEFAULT, CW_USEDEFAULT,
1053 mdi_client, 0, GetModuleHandle(0),
1054 (LPVOID)mdi_lParam_test_message);
1055 if (!mdi_child)
1057 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1058 isWin9x = TRUE;
1059 else
1060 ok(mdi_child != 0, "MDI child creation failed\n");
1062 DestroyWindow(mdi_child);
1064 /* This test fails on Win9x */
1065 if (!isWin9x)
1067 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1068 WS_CHILD,
1069 CW_USEDEFAULT, CW_USEDEFAULT,
1070 CW_USEDEFAULT, CW_USEDEFAULT,
1071 parent, 0, GetModuleHandle(0),
1072 (LPVOID)mdi_lParam_test_message);
1073 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1076 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1077 WS_CHILD, /* without WS_POPUP */
1078 CW_USEDEFAULT, CW_USEDEFAULT,
1079 CW_USEDEFAULT, CW_USEDEFAULT,
1080 mdi_client, 0, GetModuleHandle(0),
1081 (LPVOID)mdi_lParam_test_message);
1082 ok(mdi_child != 0, "MDI child creation failed\n");
1083 DestroyWindow(mdi_child);
1085 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1086 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1087 CW_USEDEFAULT, CW_USEDEFAULT,
1088 CW_USEDEFAULT, CW_USEDEFAULT,
1089 mdi_client, 0, GetModuleHandle(0),
1090 (LPVOID)mdi_lParam_test_message);
1091 ok(mdi_child != 0, "MDI child creation failed\n");
1092 DestroyWindow(mdi_child);
1094 /* maximized child */
1095 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1096 WS_CHILD | WS_MAXIMIZE,
1097 CW_USEDEFAULT, CW_USEDEFAULT,
1098 CW_USEDEFAULT, CW_USEDEFAULT,
1099 mdi_client, 0, GetModuleHandle(0),
1100 (LPVOID)mdi_lParam_test_message);
1101 ok(mdi_child != 0, "MDI child creation failed\n");
1102 DestroyWindow(mdi_child);
1104 trace("Creating maximized child with a caption\n");
1105 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1106 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1107 CW_USEDEFAULT, CW_USEDEFAULT,
1108 CW_USEDEFAULT, CW_USEDEFAULT,
1109 mdi_client, 0, GetModuleHandle(0),
1110 (LPVOID)mdi_lParam_test_message);
1111 ok(mdi_child != 0, "MDI child creation failed\n");
1112 DestroyWindow(mdi_child);
1114 trace("Creating maximized child with a caption and a thick frame\n");
1115 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1116 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1117 CW_USEDEFAULT, CW_USEDEFAULT,
1118 CW_USEDEFAULT, CW_USEDEFAULT,
1119 mdi_client, 0, GetModuleHandle(0),
1120 (LPVOID)mdi_lParam_test_message);
1121 ok(mdi_child != 0, "MDI child creation failed\n");
1122 DestroyWindow(mdi_child);
1125 /**********************************************************************
1126 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1128 * Note: The rule here is that client rect of the maximized MDI child
1129 * is equal to the client rect of the MDI client window.
1131 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1133 RECT rect;
1135 GetClientRect( client, &rect );
1136 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1137 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1139 rect.right -= rect.left;
1140 rect.bottom -= rect.top;
1141 lpMinMax->ptMaxSize.x = rect.right;
1142 lpMinMax->ptMaxSize.y = rect.bottom;
1144 lpMinMax->ptMaxPosition.x = rect.left;
1145 lpMinMax->ptMaxPosition.y = rect.top;
1147 trace("max rect (%ld,%ld - %ld, %ld)\n",
1148 rect.left, rect.top, rect.right, rect.bottom);
1151 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1153 switch (msg)
1155 case WM_NCCREATE:
1156 case WM_CREATE:
1158 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1159 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1161 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1162 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1164 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1165 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1166 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1167 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1168 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1170 /* MDICREATESTRUCT should have original values */
1171 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1172 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1173 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1174 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1175 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1176 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1178 /* CREATESTRUCT should have fixed values */
1179 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1180 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1182 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1183 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1184 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1186 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1188 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1190 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1191 ok(cs->style == style,
1192 "cs->style does not match (%08lx)\n", cs->style);
1194 else
1196 LONG style = mdi_cs->style;
1197 style &= ~WS_POPUP;
1198 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1199 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1200 ok(cs->style == style,
1201 "cs->style does not match (%08lx)\n", cs->style);
1203 break;
1206 case WM_GETMINMAXINFO:
1208 HWND client = GetParent(hwnd);
1209 RECT rc;
1210 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1211 MINMAXINFO my_minmax;
1212 LONG style, exstyle;
1214 style = GetWindowLongA(hwnd, GWL_STYLE);
1215 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1217 GetWindowRect(client, &rc);
1218 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1219 GetClientRect(client, &rc);
1220 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1221 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1222 GetSystemMetrics(SM_CYSCREEN));
1224 GetClientRect(client, &rc);
1225 if ((style & WS_CAPTION) == WS_CAPTION)
1226 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1227 AdjustWindowRectEx(&rc, style, 0, exstyle);
1228 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1230 trace("ptReserved = (%ld,%ld)\n"
1231 "ptMaxSize = (%ld,%ld)\n"
1232 "ptMaxPosition = (%ld,%ld)\n"
1233 "ptMinTrackSize = (%ld,%ld)\n"
1234 "ptMaxTrackSize = (%ld,%ld)\n",
1235 minmax->ptReserved.x, minmax->ptReserved.y,
1236 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1237 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1238 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1239 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1241 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1242 minmax->ptMaxSize.x, rc.right - rc.left);
1243 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1244 minmax->ptMaxSize.y, rc.bottom - rc.top);
1246 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1248 trace("DefMDIChildProc returned:\n"
1249 "ptReserved = (%ld,%ld)\n"
1250 "ptMaxSize = (%ld,%ld)\n"
1251 "ptMaxPosition = (%ld,%ld)\n"
1252 "ptMinTrackSize = (%ld,%ld)\n"
1253 "ptMaxTrackSize = (%ld,%ld)\n",
1254 minmax->ptReserved.x, minmax->ptReserved.y,
1255 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1256 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1257 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1258 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1260 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1261 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1262 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1263 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1264 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1266 return 1;
1269 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1272 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1274 switch (msg)
1276 case WM_NCCREATE:
1277 case WM_CREATE:
1279 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1281 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1282 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1284 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1285 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1287 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1288 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1290 /* CREATESTRUCT should have fixed values */
1291 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1292 while NT does. */
1293 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1294 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1296 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1297 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1298 while Win95, Win2k, WinXP do. */
1299 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1300 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1301 break;
1304 case WM_GETMINMAXINFO:
1306 HWND parent = GetParent(hwnd);
1307 RECT rc;
1308 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1309 LONG style, exstyle;
1311 trace("WM_GETMINMAXINFO\n");
1313 style = GetWindowLongA(hwnd, GWL_STYLE);
1314 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1316 GetClientRect(parent, &rc);
1317 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1319 GetClientRect(parent, &rc);
1320 if ((style & WS_CAPTION) == WS_CAPTION)
1321 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1322 AdjustWindowRectEx(&rc, style, 0, exstyle);
1323 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1325 trace("ptReserved = (%ld,%ld)\n"
1326 "ptMaxSize = (%ld,%ld)\n"
1327 "ptMaxPosition = (%ld,%ld)\n"
1328 "ptMinTrackSize = (%ld,%ld)\n"
1329 "ptMaxTrackSize = (%ld,%ld)\n",
1330 minmax->ptReserved.x, minmax->ptReserved.y,
1331 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1332 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1333 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1334 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1336 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1337 minmax->ptMaxSize.x, rc.right - rc.left);
1338 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1339 minmax->ptMaxSize.y, rc.bottom - rc.top);
1340 break;
1343 case WM_WINDOWPOSCHANGED:
1345 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1346 RECT rc1, rc2;
1348 GetWindowRect(hwnd, &rc1);
1349 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1350 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1351 /* note: winpos coordinates are relative to parent */
1352 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1353 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1354 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1356 GetWindowRect(hwnd, &rc1);
1357 GetClientRect(hwnd, &rc2);
1358 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1359 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1360 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1362 /* fall through */
1363 case WM_WINDOWPOSCHANGING:
1365 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1366 WINDOWPOS my_winpos = *winpos;
1368 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1369 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1370 winpos->hwnd, winpos->hwndInsertAfter,
1371 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1373 DefWindowProcA(hwnd, msg, wparam, lparam);
1375 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1376 winpos->hwnd, winpos->hwndInsertAfter,
1377 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1379 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1380 "DefWindowProc should not change WINDOWPOS values\n");
1382 return 1;
1385 return DefWindowProcA(hwnd, msg, wparam, lparam);
1388 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1390 static HWND mdi_client;
1392 switch (msg)
1394 case WM_CREATE:
1396 CLIENTCREATESTRUCT client_cs;
1397 RECT rc;
1399 GetClientRect(hwnd, &rc);
1401 client_cs.hWindowMenu = 0;
1402 client_cs.idFirstChild = 1;
1404 /* MDIClient without MDIS_ALLCHILDSTYLES */
1405 mdi_client = CreateWindowExA(0, "mdiclient",
1406 NULL,
1407 WS_CHILD /*| WS_VISIBLE*/,
1408 /* tests depend on a not zero MDIClient size */
1409 0, 0, rc.right, rc.bottom,
1410 hwnd, 0, GetModuleHandle(0),
1411 (LPVOID)&client_cs);
1412 assert(mdi_client);
1413 test_MDI_create(hwnd, mdi_client);
1414 DestroyWindow(mdi_client);
1416 /* MDIClient with MDIS_ALLCHILDSTYLES */
1417 mdi_client = CreateWindowExA(0, "mdiclient",
1418 NULL,
1419 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1420 /* tests depend on a not zero MDIClient size */
1421 0, 0, rc.right, rc.bottom,
1422 hwnd, 0, GetModuleHandle(0),
1423 (LPVOID)&client_cs);
1424 assert(mdi_client);
1425 test_MDI_create(hwnd, mdi_client);
1426 DestroyWindow(mdi_client);
1427 break;
1430 case WM_WINDOWPOSCHANGED:
1432 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1433 RECT rc1, rc2;
1435 GetWindowRect(hwnd, &rc1);
1436 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1437 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1438 /* note: winpos coordinates are relative to parent */
1439 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1440 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1441 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1443 GetWindowRect(hwnd, &rc1);
1444 GetClientRect(hwnd, &rc2);
1445 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1446 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1447 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1449 /* fall through */
1450 case WM_WINDOWPOSCHANGING:
1452 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1453 WINDOWPOS my_winpos = *winpos;
1455 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1456 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1457 winpos->hwnd, winpos->hwndInsertAfter,
1458 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1460 DefWindowProcA(hwnd, msg, wparam, lparam);
1462 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1463 winpos->hwnd, winpos->hwndInsertAfter,
1464 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1466 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1467 "DefWindowProc should not change WINDOWPOS values\n");
1469 return 1;
1472 case WM_CLOSE:
1473 PostQuitMessage(0);
1474 break;
1476 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1479 static BOOL mdi_RegisterWindowClasses(void)
1481 WNDCLASSA cls;
1483 cls.style = 0;
1484 cls.lpfnWndProc = mdi_main_wnd_procA;
1485 cls.cbClsExtra = 0;
1486 cls.cbWndExtra = 0;
1487 cls.hInstance = GetModuleHandleA(0);
1488 cls.hIcon = 0;
1489 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1490 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1491 cls.lpszMenuName = NULL;
1492 cls.lpszClassName = "MDI_parent_Class";
1493 if(!RegisterClassA(&cls)) return FALSE;
1495 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1496 cls.lpszClassName = "MDI_child_Class_1";
1497 if(!RegisterClassA(&cls)) return FALSE;
1499 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1500 cls.lpszClassName = "MDI_child_Class_2";
1501 if(!RegisterClassA(&cls)) return FALSE;
1503 return TRUE;
1506 static void test_mdi(void)
1508 HWND mdi_hwndMain;
1509 /*MSG msg;*/
1511 if (!mdi_RegisterWindowClasses()) assert(0);
1513 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1514 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1515 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1516 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1517 GetDesktopWindow(), 0,
1518 GetModuleHandle(0), NULL);
1519 assert(mdi_hwndMain);
1521 while(GetMessage(&msg, 0, 0, 0))
1523 TranslateMessage(&msg);
1524 DispatchMessage(&msg);
1529 static void test_icons(void)
1531 WNDCLASSEXA cls;
1532 HWND hwnd;
1533 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1534 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1535 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1536 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1537 HICON res;
1539 cls.cbSize = sizeof(cls);
1540 cls.style = 0;
1541 cls.lpfnWndProc = DefWindowProcA;
1542 cls.cbClsExtra = 0;
1543 cls.cbWndExtra = 0;
1544 cls.hInstance = 0;
1545 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1546 cls.hIconSm = small_icon;
1547 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1548 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1549 cls.lpszMenuName = NULL;
1550 cls.lpszClassName = "IconWindowClass";
1552 RegisterClassExA(&cls);
1554 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1555 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1556 assert( hwnd );
1558 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1559 ok( res == 0, "wrong big icon %p/0\n", res );
1560 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1561 ok( res == 0, "wrong previous big icon %p/0\n", res );
1562 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1563 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1564 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1565 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1566 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1567 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1569 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1570 ok( res == 0, "wrong small icon %p/0\n", res );
1571 /* this test is XP specific */
1572 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1573 ok( res != 0, "wrong small icon %p\n", res );*/
1574 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1575 ok( res == 0, "wrong previous small icon %p/0\n", res );
1576 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1577 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1578 /* this test is XP specific */
1579 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1580 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1581 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1582 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1583 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1584 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1585 /* this test is XP specific */
1586 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1587 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1589 /* make sure the big icon hasn't changed */
1590 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1591 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1594 static void test_SetWindowPos(HWND hwnd)
1596 RECT orig_win_rc;
1597 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
1599 /* Win9x truncates coordinates to 16-bit irrespectively */
1600 if (is_win9x) return;
1602 GetWindowRect(hwnd, &orig_win_rc);
1604 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1605 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1607 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1608 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1610 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1611 orig_win_rc.right, orig_win_rc.bottom, 0);
1614 static void test_SetMenu(HWND parent)
1616 HWND child;
1617 HMENU hMenu, ret;
1618 BOOL is_win9x = GetWindowLongW(parent, GWL_WNDPROC) == 0;
1620 hMenu = CreateMenu();
1621 assert(hMenu);
1623 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1624 test_nonclient_area(parent);
1625 ret = GetMenu(parent);
1626 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1627 /* test whether we can destroy a menu assigned to a window */
1628 ok(DestroyMenu(hMenu), "DestroyMenu error %ld\n", GetLastError());
1629 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1630 ret = GetMenu(parent);
1631 /* This test fails on Win9x */
1632 if (!is_win9x)
1633 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1634 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1635 test_nonclient_area(parent);
1637 hMenu = CreateMenu();
1638 assert(hMenu);
1640 /* parent */
1641 ret = GetMenu(parent);
1642 ok(ret == 0, "unexpected menu id %p\n", ret);
1644 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1645 test_nonclient_area(parent);
1646 ret = GetMenu(parent);
1647 ok(ret == 0, "unexpected menu id %p\n", ret);
1649 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1650 test_nonclient_area(parent);
1651 ret = GetMenu(parent);
1652 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1654 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1655 test_nonclient_area(parent);
1656 ret = GetMenu(parent);
1657 ok(ret == 0, "unexpected menu id %p\n", ret);
1659 /* child */
1660 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1661 assert(child);
1663 ret = GetMenu(child);
1664 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1666 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1667 test_nonclient_area(child);
1668 ret = GetMenu(child);
1669 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1671 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1672 test_nonclient_area(child);
1673 ret = GetMenu(child);
1674 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1676 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1677 test_nonclient_area(child);
1678 ret = GetMenu(child);
1679 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1681 DestroyWindow(child);
1682 DestroyMenu(hMenu);
1685 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1687 HWND child[5], hwnd;
1688 int i;
1690 assert(total <= 5);
1692 hwnd = GetWindow(parent, GW_CHILD);
1693 ok(!hwnd, "have to start without children to perform the test\n");
1695 for (i = 0; i < total; i++)
1697 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1698 parent, 0, 0, NULL);
1699 trace("child[%d] = %p\n", i, child[i]);
1700 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1703 hwnd = GetWindow(parent, GW_CHILD);
1704 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1705 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1706 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1708 for (i = 0; i < total; i++)
1710 trace("hwnd[%d] = %p\n", i, hwnd);
1711 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1713 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1716 for (i = 0; i < total; i++)
1717 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1720 static void test_children_zorder(HWND parent)
1722 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1723 WS_CHILD };
1724 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1726 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1727 WS_CHILD | WS_VISIBLE, WS_CHILD,
1728 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1729 const int complex_order_1[1] = { 0 };
1730 const int complex_order_2[2] = { 1, 0 };
1731 const int complex_order_3[3] = { 1, 0, 2 };
1732 const int complex_order_4[4] = { 1, 0, 2, 3 };
1733 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1735 /* simple WS_CHILD */
1736 test_window_tree(parent, simple_style, simple_order, 5);
1738 /* complex children styles */
1739 test_window_tree(parent, complex_style, complex_order_1, 1);
1740 test_window_tree(parent, complex_style, complex_order_2, 2);
1741 test_window_tree(parent, complex_style, complex_order_3, 3);
1742 test_window_tree(parent, complex_style, complex_order_4, 4);
1743 test_window_tree(parent, complex_style, complex_order_5, 5);
1746 static void test_SetFocus(HWND hwnd)
1748 HWND child;
1750 /* check if we can set focus to non-visible windows */
1752 ShowWindow(hwnd, SW_SHOW);
1753 SetFocus(0);
1754 SetFocus(hwnd);
1755 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1756 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1757 ShowWindow(hwnd, SW_HIDE);
1758 SetFocus(0);
1759 SetFocus(hwnd);
1760 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1761 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1762 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1763 assert(child);
1764 SetFocus(child);
1765 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1766 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1767 ShowWindow(child, SW_SHOW);
1768 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1769 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1770 ShowWindow(child, SW_HIDE);
1771 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1772 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1773 ShowWindow(child, SW_SHOW);
1774 SetFocus(child);
1775 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1776 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1777 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1779 ShowWindow(child, SW_HIDE);
1780 SetFocus(hwnd);
1781 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1782 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1783 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1784 ShowWindow(child, SW_HIDE);
1785 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1787 ShowWindow(hwnd, SW_SHOW);
1788 ShowWindow(child, SW_SHOW);
1789 SetFocus(child);
1790 ok( GetFocus() == child, "Focus should be on child %p\n", child );
1791 EnableWindow(hwnd, FALSE);
1792 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1793 EnableWindow(hwnd, TRUE);
1795 DestroyWindow( child );
1798 static void test_SetActiveWindow(HWND hwnd)
1800 HWND hwnd2;
1802 ShowWindow(hwnd, SW_SHOW);
1803 SetActiveWindow(0);
1804 SetActiveWindow(hwnd);
1805 ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1806 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1807 ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1808 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1809 ShowWindow(hwnd, SW_HIDE);
1810 ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1811 ShowWindow(hwnd, SW_SHOW);
1813 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1814 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1815 DestroyWindow(hwnd2);
1816 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1818 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1819 ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1820 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1821 ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1822 DestroyWindow(hwnd2);
1823 ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1826 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
1828 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1829 if (foreground)
1830 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1831 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
1832 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
1835 static WNDPROC old_button_proc;
1837 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
1839 LRESULT ret;
1840 USHORT key_state;
1842 key_state = GetKeyState(VK_LBUTTON);
1843 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
1845 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
1847 if (msg == WM_LBUTTONDOWN)
1849 HWND hwnd, capture;
1851 check_wnd_state(button, button, button, button);
1853 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1854 assert(hwnd);
1855 trace("hwnd %p\n", hwnd);
1857 check_wnd_state(button, button, button, button);
1859 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1861 check_wnd_state(button, button, button, button);
1863 DestroyWindow(hwnd);
1865 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1866 assert(hwnd);
1867 trace("hwnd %p\n", hwnd);
1869 check_wnd_state(button, button, button, button);
1871 /* button wnd proc should release capture on WM_KILLFOCUS if it does
1872 * match internal button state.
1874 SendMessage(button, WM_KILLFOCUS, 0, 0);
1875 check_wnd_state(button, button, button, 0);
1877 ShowWindow(hwnd, SW_SHOW);
1878 check_wnd_state(hwnd, hwnd, hwnd, 0);
1880 capture = SetCapture(hwnd);
1881 ok(capture == 0, "SetCapture() = %p\n", capture);
1883 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1885 DestroyWindow(hwnd);
1887 check_wnd_state(button, 0, button, 0);
1890 return ret;
1893 static void test_capture_1(void)
1895 HWND button, capture;
1897 capture = GetCapture();
1898 ok(capture == 0, "GetCapture() = %p\n", capture);
1900 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1901 assert(button);
1902 trace("button %p\n", button);
1904 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
1906 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
1908 DestroyWindow(button);
1911 static void test_capture_2(void)
1913 HWND button, hwnd, capture;
1915 check_wnd_state(0, 0, 0, 0);
1917 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1918 assert(button);
1919 trace("button %p\n", button);
1921 check_wnd_state(button, button, button, 0);
1923 capture = SetCapture(button);
1924 ok(capture == 0, "SetCapture() = %p\n", capture);
1926 check_wnd_state(button, button, button, button);
1928 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
1929 * internal button state.
1931 SendMessage(button, WM_KILLFOCUS, 0, 0);
1932 check_wnd_state(button, button, button, button);
1934 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
1935 assert(hwnd);
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);
1947 assert(hwnd);
1948 trace("hwnd %p\n", hwnd);
1950 check_wnd_state(button, button, button, button);
1952 ShowWindow(hwnd, SW_SHOW);
1954 check_wnd_state(hwnd, hwnd, hwnd, button);
1956 capture = SetCapture(hwnd);
1957 ok(capture == button, "SetCapture() = %p\n", capture);
1959 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1961 DestroyWindow(hwnd);
1962 check_wnd_state(button, button, button, 0);
1964 DestroyWindow(button);
1965 check_wnd_state(0, 0, 0, 0);
1968 static void test_capture_3(HWND hwnd1, HWND hwnd2)
1970 ShowWindow(hwnd1, SW_HIDE);
1971 ShowWindow(hwnd2, SW_HIDE);
1973 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
1974 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
1976 SetCapture(hwnd1);
1977 check_wnd_state(0, 0, 0, hwnd1);
1979 SetCapture(hwnd2);
1980 check_wnd_state(0, 0, 0, hwnd2);
1982 ShowWindow(hwnd1, SW_SHOW);
1983 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
1985 ReleaseCapture();
1988 static void test_keyboard_input(HWND hwnd)
1990 MSG msg;
1991 INPUT input;
1992 FARPROC pSendInput = GetProcAddress(GetModuleHandleA("user32.dll"), "SendInput");
1994 input.type = INPUT_KEYBOARD;
1995 input.u.ki.wVk = VK_SPACE;
1996 input.u.ki.wScan = 0;
1997 input.u.ki.dwFlags = 0;
1998 input.u.ki.time = 0;
1999 input.u.ki.dwExtraInfo = 0;
2001 ShowWindow(hwnd, SW_SHOW);
2002 UpdateWindow(hwnd);
2004 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2006 SetFocus(hwnd);
2007 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2009 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2011 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2012 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2013 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2014 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2016 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2018 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2019 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2020 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2021 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2023 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2025 if (pSendInput)
2027 ok(pSendInput(1, &input, sizeof(input)) == 1, "SendInput failed\n");
2028 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2029 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2030 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2033 SetFocus(0);
2034 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2036 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2038 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2039 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2040 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2041 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2043 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2045 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2046 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2047 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2048 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2050 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2052 if (pSendInput)
2054 ok(pSendInput(1, &input, sizeof(input)) == 1, "SendInput failed\n");
2055 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2056 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2057 ok(!PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "message %04x available\n", msg.message);
2061 START_TEST(win)
2063 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2064 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2066 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
2067 if (hwndMain)
2069 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
2070 if (pGetAncestor)
2072 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
2073 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2074 trace("hwndMessage %p\n", hwndMessage);
2076 DestroyWindow(hwndMain);
2078 else
2079 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2081 if (!RegisterWindowClasses()) assert(0);
2083 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
2084 assert(hhook);
2086 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2087 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2088 WS_MAXIMIZEBOX | WS_POPUP,
2089 100, 100, 200, 200,
2090 0, 0, 0, NULL);
2091 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2092 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2093 WS_MAXIMIZEBOX | WS_POPUP,
2094 100, 100, 200, 200,
2095 0, 0, 0, NULL);
2096 assert( hwndMain );
2097 assert( hwndMain2 );
2099 test_capture_1();
2100 test_capture_2();
2101 test_capture_3(hwndMain, hwndMain2);
2103 test_parent_owner();
2104 test_shell_window();
2106 test_mdi();
2107 test_icons();
2108 test_SetWindowPos(hwndMain);
2109 test_SetMenu(hwndMain);
2110 test_SetFocus(hwndMain);
2111 test_SetActiveWindow(hwndMain);
2113 test_children_zorder(hwndMain);
2114 test_keyboard_input(hwndMain);
2116 UnhookWindowsHookEx(hhook);