Add a test case which confirms that SetMenu implementation in Wine is
[wine/hacks.git] / dlls / user / tests / win.c
blobf519e97ec08cd98f0c272769557eef3fabaa1990
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 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
47 static HWND hwndMain, hwndMain2;
48 static HHOOK hhook;
50 /* check the values returned by the various parent/owner functions on a given window */
51 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
52 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
54 HWND res;
56 if (pGetAncestor)
58 res = pGetAncestor( hwnd, GA_PARENT );
59 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
61 res = (HWND)GetWindowLongA( hwnd, GWL_HWNDPARENT );
62 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
63 res = GetParent( hwnd );
64 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
65 res = GetWindow( hwnd, GW_OWNER );
66 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
67 if (pGetAncestor)
69 res = pGetAncestor( hwnd, GA_ROOT );
70 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
71 res = pGetAncestor( hwnd, GA_ROOTOWNER );
72 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
77 static HWND create_tool_window( LONG style, HWND parent )
79 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
80 0, 0, 100, 100, parent, 0, 0, NULL );
81 ok( ret != 0, "Creation failed\n" );
82 return ret;
85 /* test parent and owner values for various combinations */
86 static void test_parent_owner(void)
88 LONG style;
89 HWND test, owner, ret;
90 HWND desktop = GetDesktopWindow();
91 HWND child = create_tool_window( WS_CHILD, hwndMain );
93 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
95 /* child without parent, should fail */
96 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
97 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
98 ok( !test, "WS_CHILD without parent created\n" );
100 /* desktop window */
101 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
102 style = GetWindowLongA( desktop, GWL_STYLE );
103 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
104 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
105 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
107 /* normal child window */
108 test = create_tool_window( WS_CHILD, hwndMain );
109 trace( "created child %p\n", test );
110 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
111 SetWindowLongA( test, GWL_STYLE, 0 );
112 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
113 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
114 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
115 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
116 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
117 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
118 DestroyWindow( test );
120 /* normal child window with WS_MAXIMIZE */
121 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
122 DestroyWindow( test );
124 /* normal child window with WS_THICKFRAME */
125 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
126 DestroyWindow( test );
128 /* popup window with WS_THICKFRAME */
129 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
130 DestroyWindow( test );
132 /* child of desktop */
133 test = create_tool_window( WS_CHILD, desktop );
134 trace( "created child of desktop %p\n", test );
135 check_parents( test, desktop, 0, desktop, 0, test, desktop );
136 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
137 check_parents( test, desktop, 0, 0, 0, test, test );
138 SetWindowLongA( test, GWL_STYLE, 0 );
139 check_parents( test, desktop, 0, 0, 0, test, test );
140 DestroyWindow( test );
142 /* child of desktop with WS_MAXIMIZE */
143 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
144 DestroyWindow( test );
146 /* child of desktop with WS_MINIMIZE */
147 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
148 DestroyWindow( test );
150 /* child of child */
151 test = create_tool_window( WS_CHILD, child );
152 trace( "created child of child %p\n", test );
153 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
154 SetWindowLongA( test, GWL_STYLE, 0 );
155 check_parents( test, child, child, 0, 0, hwndMain, test );
156 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
157 check_parents( test, child, child, 0, 0, hwndMain, test );
158 DestroyWindow( test );
160 /* child of child with WS_MAXIMIZE */
161 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
162 DestroyWindow( test );
164 /* child of child with WS_MINIMIZE */
165 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
166 DestroyWindow( test );
168 /* not owned top-level window */
169 test = create_tool_window( 0, 0 );
170 trace( "created top-level %p\n", test );
171 check_parents( test, desktop, 0, 0, 0, test, test );
172 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
173 check_parents( test, desktop, 0, 0, 0, test, test );
174 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
175 check_parents( test, desktop, 0, desktop, 0, test, desktop );
176 DestroyWindow( test );
178 /* not owned top-level window with WS_MAXIMIZE */
179 test = create_tool_window( WS_MAXIMIZE, 0 );
180 DestroyWindow( test );
182 /* owned top-level window */
183 test = create_tool_window( 0, hwndMain );
184 trace( "created owned top-level %p\n", test );
185 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
186 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
187 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
188 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
189 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
190 DestroyWindow( test );
192 /* owned top-level window with WS_MAXIMIZE */
193 test = create_tool_window( WS_MAXIMIZE, hwndMain );
194 DestroyWindow( test );
196 /* not owned popup */
197 test = create_tool_window( WS_POPUP, 0 );
198 trace( "created popup %p\n", test );
199 check_parents( test, desktop, 0, 0, 0, test, test );
200 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
201 check_parents( test, desktop, 0, desktop, 0, test, desktop );
202 SetWindowLongA( test, GWL_STYLE, 0 );
203 check_parents( test, desktop, 0, 0, 0, test, test );
204 DestroyWindow( test );
206 /* not owned popup with WS_MAXIMIZE */
207 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
208 DestroyWindow( test );
210 /* owned popup */
211 test = create_tool_window( WS_POPUP, hwndMain );
212 trace( "created owned popup %p\n", test );
213 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
214 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
215 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
216 SetWindowLongA( test, GWL_STYLE, 0 );
217 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
218 DestroyWindow( test );
220 /* owned popup with WS_MAXIMIZE */
221 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
222 DestroyWindow( test );
224 /* top-level window owned by child (same as owned by top-level) */
225 test = create_tool_window( 0, child );
226 trace( "created top-level owned by child %p\n", test );
227 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
228 DestroyWindow( test );
230 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
231 test = create_tool_window( WS_MAXIMIZE, child );
232 DestroyWindow( test );
234 /* popup owned by desktop (same as not owned) */
235 test = create_tool_window( WS_POPUP, desktop );
236 trace( "created popup owned by desktop %p\n", test );
237 check_parents( test, desktop, 0, 0, 0, test, test );
238 DestroyWindow( test );
240 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
241 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
242 DestroyWindow( test );
244 /* popup owned by child (same as owned by top-level) */
245 test = create_tool_window( WS_POPUP, child );
246 trace( "created popup owned by child %p\n", test );
247 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
248 DestroyWindow( test );
250 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
251 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
252 DestroyWindow( test );
254 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
255 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
256 trace( "created WS_CHILD popup %p\n", test );
257 check_parents( test, desktop, 0, 0, 0, test, test );
258 DestroyWindow( test );
260 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
261 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
262 DestroyWindow( test );
264 /* owned popup with WS_CHILD (same as WS_POPUP only) */
265 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
266 trace( "created owned WS_CHILD popup %p\n", test );
267 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
268 DestroyWindow( test );
270 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
271 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
272 DestroyWindow( test );
274 /******************** parent changes *************************/
275 trace( "testing parent changes\n" );
277 /* desktop window */
278 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
279 #if 0 /* this test succeeds on NT but crashes on win9x systems */
280 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
281 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
282 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
283 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
284 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
285 #endif
286 /* normal child window */
287 test = create_tool_window( WS_CHILD, hwndMain );
288 trace( "created child %p\n", test );
290 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
291 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
292 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
294 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
295 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
296 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
298 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)desktop );
299 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
300 check_parents( test, desktop, 0, desktop, 0, test, desktop );
302 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
303 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
304 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
305 check_parents( test, desktop, child, desktop, child, test, desktop );
307 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
308 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
309 check_parents( test, desktop, 0, desktop, 0, test, desktop );
310 DestroyWindow( test );
312 /* not owned top-level window */
313 test = create_tool_window( 0, 0 );
314 trace( "created top-level %p\n", test );
316 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
317 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
318 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
320 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
321 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
322 check_parents( test, desktop, child, 0, child, test, test );
324 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
325 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
326 check_parents( test, desktop, 0, 0, 0, test, test );
327 DestroyWindow( test );
329 /* not owned popup */
330 test = create_tool_window( WS_POPUP, 0 );
331 trace( "created popup %p\n", test );
333 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
334 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
335 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
337 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child );
338 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
339 check_parents( test, desktop, child, child, child, test, hwndMain );
341 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 );
342 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
343 check_parents( test, desktop, 0, 0, 0, test, test );
344 DestroyWindow( test );
346 /* normal child window */
347 test = create_tool_window( WS_CHILD, hwndMain );
348 trace( "created child %p\n", test );
350 ret = SetParent( test, desktop );
351 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
352 check_parents( test, desktop, 0, desktop, 0, test, desktop );
354 ret = SetParent( test, child );
355 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
356 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
358 ret = SetParent( test, hwndMain2 );
359 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
360 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
361 DestroyWindow( test );
363 /* not owned top-level window */
364 test = create_tool_window( 0, 0 );
365 trace( "created top-level %p\n", test );
367 ret = SetParent( test, child );
368 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
369 check_parents( test, child, child, 0, 0, hwndMain, test );
370 DestroyWindow( test );
372 /* owned popup */
373 test = create_tool_window( WS_POPUP, hwndMain2 );
374 trace( "created owned popup %p\n", test );
376 ret = SetParent( test, child );
377 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
378 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
380 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain );
381 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
382 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
383 DestroyWindow( test );
385 /**************** test owner destruction *******************/
387 /* owned child popup */
388 owner = create_tool_window( 0, 0 );
389 test = create_tool_window( WS_POPUP, owner );
390 trace( "created owner %p and popup %p\n", owner, test );
391 ret = SetParent( test, child );
392 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
393 check_parents( test, child, child, owner, owner, hwndMain, owner );
394 /* window is now child of 'child' but owned by 'owner' */
395 DestroyWindow( owner );
396 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
397 check_parents( test, child, child, owner, owner, hwndMain, owner );
398 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
399 DestroyWindow(test);
401 /* owned top-level popup */
402 owner = create_tool_window( 0, 0 );
403 test = create_tool_window( WS_POPUP, owner );
404 trace( "created owner %p and popup %p\n", owner, test );
405 check_parents( test, desktop, owner, owner, owner, test, owner );
406 DestroyWindow( owner );
407 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
409 /* top-level popup owned by child */
410 owner = create_tool_window( WS_CHILD, hwndMain2 );
411 test = create_tool_window( WS_POPUP, 0 );
412 trace( "created owner %p and popup %p\n", owner, test );
413 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner );
414 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
415 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
416 DestroyWindow( owner );
417 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
418 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
419 check_parents( test, desktop, owner, owner, owner, test, owner );
420 DestroyWindow(test);
422 /* final cleanup */
423 DestroyWindow(child);
427 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
429 switch (msg)
431 case WM_GETMINMAXINFO:
433 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
435 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
436 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
437 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
438 minmax->ptReserved.x, minmax->ptReserved.y,
439 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
440 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
441 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
442 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
443 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
444 break;
446 case WM_WINDOWPOSCHANGING:
448 BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
449 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
450 trace("main: WM_WINDOWPOSCHANGING\n");
451 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
452 winpos->hwnd, winpos->hwndInsertAfter,
453 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
454 if (!(winpos->flags & SWP_NOMOVE))
456 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
457 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
459 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
460 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
462 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
463 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
465 break;
467 case WM_WINDOWPOSCHANGED:
469 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
470 trace("main: WM_WINDOWPOSCHANGED\n");
471 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
472 winpos->hwnd, winpos->hwndInsertAfter,
473 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
474 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
475 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
477 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
478 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
479 break;
481 case WM_NCCREATE:
483 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
484 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
486 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
487 if (got_getminmaxinfo)
488 trace("%p got WM_GETMINMAXINFO\n", hwnd);
490 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
491 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
492 else
493 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
494 break;
498 return DefWindowProcA(hwnd, msg, wparam, lparam);
501 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
503 switch (msg)
505 case WM_GETMINMAXINFO:
507 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
509 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
510 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
511 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
512 minmax->ptReserved.x, minmax->ptReserved.y,
513 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
514 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
515 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
516 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
517 SetWindowLongA(hwnd, GWL_USERDATA, 0x20031021);
518 break;
520 case WM_NCCREATE:
522 BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
523 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
525 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
526 if (got_getminmaxinfo)
527 trace("%p got WM_GETMINMAXINFO\n", hwnd);
529 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
530 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
531 else
532 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
533 break;
537 return DefWindowProcA(hwnd, msg, wparam, lparam);
540 static BOOL RegisterWindowClasses(void)
542 WNDCLASSA cls;
544 cls.style = 0;
545 cls.lpfnWndProc = main_window_procA;
546 cls.cbClsExtra = 0;
547 cls.cbWndExtra = 0;
548 cls.hInstance = GetModuleHandleA(0);
549 cls.hIcon = 0;
550 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
551 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
552 cls.lpszMenuName = NULL;
553 cls.lpszClassName = "MainWindowClass";
555 if(!RegisterClassA(&cls)) return FALSE;
557 cls.style = 0;
558 cls.lpfnWndProc = tool_window_procA;
559 cls.cbClsExtra = 0;
560 cls.cbWndExtra = 0;
561 cls.hInstance = GetModuleHandleA(0);
562 cls.hIcon = 0;
563 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
564 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
565 cls.lpszMenuName = NULL;
566 cls.lpszClassName = "ToolWindowClass";
568 if(!RegisterClassA(&cls)) return FALSE;
570 return TRUE;
573 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
575 static const char *CBT_code_name[10] = {
576 "HCBT_MOVESIZE",
577 "HCBT_MINMAX",
578 "HCBT_QS",
579 "HCBT_CREATEWND",
580 "HCBT_DESTROYWND",
581 "HCBT_ACTIVATE",
582 "HCBT_CLICKSKIPPED",
583 "HCBT_KEYSKIPPED",
584 "HCBT_SYSCOMMAND",
585 "HCBT_SETFOCUS" };
586 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
588 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
590 switch (nCode)
592 case HCBT_CREATEWND:
594 DWORD style;
595 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
596 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
597 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
598 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
600 /* WS_VISIBLE should be turned off yet */
601 style = createwnd->lpcs->style & ~WS_VISIBLE;
602 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
603 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
604 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
605 break;
609 return CallNextHookEx(hhook, nCode, wParam, lParam);
612 static void test_shell_window()
614 BOOL ret;
615 DWORD error;
616 HMODULE hinst, hUser32;
617 BOOL (WINAPI*SetShellWindow)(HWND);
618 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
619 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
620 HWND shellWindow, nextWnd;
622 shellWindow = GetShellWindow();
623 hinst = GetModuleHandle(0);
624 hUser32 = GetModuleHandleA("user32");
626 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
627 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
629 trace("previous shell window: %p\n", shellWindow);
631 if (shellWindow) {
632 DWORD pid;
633 HANDLE hProcess;
635 ret = DestroyWindow(shellWindow);
636 error = GetLastError();
638 ok(!ret, "DestroyWindow(shellWindow)\n");
639 /* passes on Win XP, but not on Win98
640 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n"); */
642 /* close old shell instance */
643 GetWindowThreadProcessId(shellWindow, &pid);
644 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
645 ret = TerminateProcess(hProcess, 0);
646 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
647 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
648 CloseHandle(hProcess);
651 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
652 trace("created window 1: %p\n", hwnd1);
654 ret = SetShellWindow(hwnd1);
655 ok(ret, "first call to SetShellWindow(hwnd1)\n");
656 shellWindow = GetShellWindow();
657 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
659 ret = SetShellWindow(hwnd1);
660 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
662 ret = SetShellWindow(0);
663 error = GetLastError();
664 /* passes on Win XP, but not on Win98
665 ok(!ret, "reset shell window by SetShellWindow(0)\n");
666 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
668 ret = SetShellWindow(hwnd1);
669 /* passes on Win XP, but not on Win98
670 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
672 todo_wine
674 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
675 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
676 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
679 ret = DestroyWindow(hwnd1);
680 ok(ret, "DestroyWindow(hwnd1)\n");
682 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
683 trace("created window 2: %p\n", hwnd2);
684 ret = SetShellWindow(hwnd2);
685 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
687 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
688 trace("created window 3: %p\n", hwnd3);
690 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
691 trace("created window 4: %p\n", hwnd4);
693 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
694 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
696 ret = SetShellWindow(hwnd4);
697 ok(ret, "SetShellWindow(hwnd4)\n");
698 shellWindow = GetShellWindow();
699 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
701 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
702 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
704 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
705 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
707 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
708 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
710 ret = SetShellWindow(hwnd3);
711 ok(!ret, "SetShellWindow(hwnd3)\n");
712 shellWindow = GetShellWindow();
713 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
715 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
716 trace("created window 5: %p\n", hwnd5);
717 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
718 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
720 todo_wine
722 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
723 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
726 /* destroy test windows */
727 DestroyWindow(hwnd2);
728 DestroyWindow(hwnd3);
729 DestroyWindow(hwnd4);
730 DestroyWindow(hwnd5);
733 /************** MDI test ****************/
735 static const char mdi_lParam_test_message[] = "just a test string";
737 static void test_MDI_create(HWND parent, HWND mdi_client)
739 MDICREATESTRUCTA mdi_cs;
740 HWND mdi_child;
741 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
742 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
743 BOOL isWin9x = FALSE;
745 mdi_cs.szClass = "MDI_child_Class_1";
746 mdi_cs.szTitle = "MDI child";
747 mdi_cs.hOwner = GetModuleHandle(0);
748 mdi_cs.x = CW_USEDEFAULT;
749 mdi_cs.y = CW_USEDEFAULT;
750 mdi_cs.cx = CW_USEDEFAULT;
751 mdi_cs.cy = CW_USEDEFAULT;
752 mdi_cs.style = 0;
753 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
754 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
755 ok(mdi_child != 0, "MDI child creation failed\n");
756 DestroyWindow(mdi_child);
758 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
759 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
760 ok(mdi_child != 0, "MDI child creation failed\n");
761 DestroyWindow(mdi_child);
763 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
764 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
765 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
767 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
768 DestroyWindow(mdi_child);
770 else
771 ok(mdi_child != 0, "MDI child creation failed\n");
773 /* test MDICREATESTRUCT A<->W mapping */
774 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
775 mdi_cs.style = 0;
776 mdi_cs.szClass = (LPCSTR)classW;
777 mdi_cs.szTitle = (LPCSTR)titleW;
778 SetLastError(0xdeadbeef);
779 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
780 if (!mdi_child)
782 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
783 isWin9x = TRUE;
784 else
785 ok(mdi_child != 0, "MDI child creation failed\n");
787 DestroyWindow(mdi_child);
789 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
791 CW_USEDEFAULT, CW_USEDEFAULT,
792 CW_USEDEFAULT, CW_USEDEFAULT,
793 mdi_client, GetModuleHandle(0),
794 (LPARAM)mdi_lParam_test_message);
795 ok(mdi_child != 0, "MDI child creation failed\n");
796 DestroyWindow(mdi_child);
798 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
799 0x7fffffff, /* without WS_POPUP */
800 CW_USEDEFAULT, CW_USEDEFAULT,
801 CW_USEDEFAULT, CW_USEDEFAULT,
802 mdi_client, GetModuleHandle(0),
803 (LPARAM)mdi_lParam_test_message);
804 ok(mdi_child != 0, "MDI child creation failed\n");
805 DestroyWindow(mdi_child);
807 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
808 0xffffffff, /* with WS_POPUP */
809 CW_USEDEFAULT, CW_USEDEFAULT,
810 CW_USEDEFAULT, CW_USEDEFAULT,
811 mdi_client, GetModuleHandle(0),
812 (LPARAM)mdi_lParam_test_message);
813 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
815 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
816 DestroyWindow(mdi_child);
818 else
819 ok(mdi_child != 0, "MDI child creation failed\n");
821 /* test MDICREATESTRUCT A<->W mapping */
822 SetLastError(0xdeadbeef);
823 mdi_child = CreateMDIWindowW(classW, titleW,
825 CW_USEDEFAULT, CW_USEDEFAULT,
826 CW_USEDEFAULT, CW_USEDEFAULT,
827 mdi_client, GetModuleHandle(0),
828 (LPARAM)mdi_lParam_test_message);
829 if (!mdi_child)
831 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
832 isWin9x = TRUE;
833 else
834 ok(mdi_child != 0, "MDI child creation failed\n");
836 DestroyWindow(mdi_child);
838 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
840 CW_USEDEFAULT, CW_USEDEFAULT,
841 CW_USEDEFAULT, CW_USEDEFAULT,
842 mdi_client, 0, GetModuleHandle(0),
843 (LPVOID)mdi_lParam_test_message);
844 ok(mdi_child != 0, "MDI child creation failed\n");
845 DestroyWindow(mdi_child);
847 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
848 0x7fffffff, /* without WS_POPUP */
849 CW_USEDEFAULT, CW_USEDEFAULT,
850 CW_USEDEFAULT, CW_USEDEFAULT,
851 mdi_client, 0, GetModuleHandle(0),
852 (LPVOID)mdi_lParam_test_message);
853 ok(mdi_child != 0, "MDI child creation failed\n");
854 DestroyWindow(mdi_child);
856 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
857 0xffffffff, /* with WS_POPUP */
858 CW_USEDEFAULT, CW_USEDEFAULT,
859 CW_USEDEFAULT, CW_USEDEFAULT,
860 mdi_client, 0, GetModuleHandle(0),
861 (LPVOID)mdi_lParam_test_message);
862 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
864 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
865 DestroyWindow(mdi_child);
867 else
868 ok(mdi_child != 0, "MDI child creation failed\n");
870 /* test MDICREATESTRUCT A<->W mapping */
871 SetLastError(0xdeadbeef);
872 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
874 CW_USEDEFAULT, CW_USEDEFAULT,
875 CW_USEDEFAULT, CW_USEDEFAULT,
876 mdi_client, 0, GetModuleHandle(0),
877 (LPVOID)mdi_lParam_test_message);
878 if (!mdi_child)
880 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
881 isWin9x = TRUE;
882 else
883 ok(mdi_child != 0, "MDI child creation failed\n");
885 DestroyWindow(mdi_child);
887 /* This test fails on Win9x */
888 if (!isWin9x)
890 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
891 WS_CHILD,
892 CW_USEDEFAULT, CW_USEDEFAULT,
893 CW_USEDEFAULT, CW_USEDEFAULT,
894 parent, 0, GetModuleHandle(0),
895 (LPVOID)mdi_lParam_test_message);
896 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
899 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
900 WS_CHILD, /* without WS_POPUP */
901 CW_USEDEFAULT, CW_USEDEFAULT,
902 CW_USEDEFAULT, CW_USEDEFAULT,
903 mdi_client, 0, GetModuleHandle(0),
904 (LPVOID)mdi_lParam_test_message);
905 ok(mdi_child != 0, "MDI child creation failed\n");
906 DestroyWindow(mdi_child);
908 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
909 WS_CHILD | WS_POPUP, /* with WS_POPUP */
910 CW_USEDEFAULT, CW_USEDEFAULT,
911 CW_USEDEFAULT, CW_USEDEFAULT,
912 mdi_client, 0, GetModuleHandle(0),
913 (LPVOID)mdi_lParam_test_message);
914 ok(mdi_child != 0, "MDI child creation failed\n");
915 DestroyWindow(mdi_child);
918 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
920 switch (msg)
922 case WM_NCCREATE:
923 case WM_CREATE:
925 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
926 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
928 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
929 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
931 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
932 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
933 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
934 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
935 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
937 /* MDICREATESTRUCT should have original values */
938 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
939 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
940 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
941 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
942 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
943 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
945 /* CREATESTRUCT should have fixed values */
946 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
947 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
949 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
950 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
951 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
953 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
955 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
957 ok(cs->style == (mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS),
958 "cs->style does not match (%08lx)\n", cs->style);
960 else
962 DWORD style = mdi_cs->style;
963 style &= ~WS_POPUP;
964 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
965 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
966 ok(cs->style == style,
967 "cs->style does not match (%08lx)\n", cs->style);
969 break;
972 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
975 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
977 switch (msg)
979 case WM_NCCREATE:
980 case WM_CREATE:
982 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
984 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
985 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
987 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
988 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
990 /* CREATESTRUCT should have fixed values */
991 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
992 while NT does. */
993 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
994 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
996 /* cx/cy == CW_USEDEFAULT are translated to 0 */
997 ok(cs->cx == 0, "%d != 0\n", cs->cx);
998 ok(cs->cy == 0, "%d != 0\n", cs->cy);
999 break;
1002 return DefWindowProcA(hwnd, msg, wparam, lparam);
1005 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1007 static HWND mdi_client;
1009 switch (msg)
1011 case WM_CREATE:
1013 CLIENTCREATESTRUCT client_cs;
1014 RECT rc;
1016 GetClientRect(hwnd, &rc);
1018 client_cs.hWindowMenu = 0;
1019 client_cs.idFirstChild = 1;
1021 /* MDIClient without MDIS_ALLCHILDSTYLES */
1022 mdi_client = CreateWindowExA(0, "mdiclient",
1023 NULL,
1024 WS_CHILD /*| WS_VISIBLE*/,
1025 /* tests depend on a not zero MDIClient size */
1026 0, 0, rc.right, rc.bottom,
1027 hwnd, 0, GetModuleHandle(0),
1028 (LPVOID)&client_cs);
1029 assert(mdi_client);
1030 test_MDI_create(hwnd, mdi_client);
1031 DestroyWindow(mdi_client);
1033 /* MDIClient with MDIS_ALLCHILDSTYLES */
1034 mdi_client = CreateWindowExA(0, "mdiclient",
1035 NULL,
1036 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1037 /* tests depend on a not zero MDIClient size */
1038 0, 0, rc.right, rc.bottom,
1039 hwnd, 0, GetModuleHandle(0),
1040 (LPVOID)&client_cs);
1041 assert(mdi_client);
1042 test_MDI_create(hwnd, mdi_client);
1043 DestroyWindow(mdi_client);
1044 break;
1047 case WM_CLOSE:
1048 PostQuitMessage(0);
1049 break;
1051 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1054 static BOOL mdi_RegisterWindowClasses(void)
1056 WNDCLASSA cls;
1058 cls.style = 0;
1059 cls.lpfnWndProc = mdi_main_wnd_procA;
1060 cls.cbClsExtra = 0;
1061 cls.cbWndExtra = 0;
1062 cls.hInstance = GetModuleHandleA(0);
1063 cls.hIcon = 0;
1064 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1065 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1066 cls.lpszMenuName = NULL;
1067 cls.lpszClassName = "MDI_parent_Class";
1068 if(!RegisterClassA(&cls)) return FALSE;
1070 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1071 cls.lpszClassName = "MDI_child_Class_1";
1072 if(!RegisterClassA(&cls)) return FALSE;
1074 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1075 cls.lpszClassName = "MDI_child_Class_2";
1076 if(!RegisterClassA(&cls)) return FALSE;
1078 return TRUE;
1081 static void test_mdi(void)
1083 HWND mdi_hwndMain;
1084 /*MSG msg;*/
1086 if (!mdi_RegisterWindowClasses()) assert(0);
1088 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1089 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1090 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1091 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1092 GetDesktopWindow(), 0,
1093 GetModuleHandle(0), NULL);
1094 assert(mdi_hwndMain);
1096 while(GetMessage(&msg, 0, 0, 0))
1098 TranslateMessage(&msg);
1099 DispatchMessage(&msg);
1104 static void test_icons(void)
1106 WNDCLASSEXA cls;
1107 HWND hwnd;
1108 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1109 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1110 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1111 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1112 HICON res;
1114 cls.cbSize = sizeof(cls);
1115 cls.style = 0;
1116 cls.lpfnWndProc = DefWindowProcA;
1117 cls.cbClsExtra = 0;
1118 cls.cbWndExtra = 0;
1119 cls.hInstance = 0;
1120 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1121 cls.hIconSm = small_icon;
1122 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1123 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1124 cls.lpszMenuName = NULL;
1125 cls.lpszClassName = "IconWindowClass";
1127 RegisterClassExA(&cls);
1129 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1130 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1131 assert( hwnd );
1133 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1134 ok( res == 0, "wrong big icon %p/0\n", res );
1135 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1136 ok( res == 0, "wrong previous big icon %p/0\n", res );
1137 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1138 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1139 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1140 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1141 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1142 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1144 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1145 ok( res == 0, "wrong small icon %p/0\n", res );
1146 /* this test is XP specific */
1147 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1148 ok( res != 0, "wrong small icon %p\n", res );*/
1149 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1150 ok( res == 0, "wrong previous small icon %p/0\n", res );
1151 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1152 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1153 /* this test is XP specific */
1154 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1155 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1156 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1157 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1158 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1159 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1160 /* this test is XP specific */
1161 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1162 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1164 /* make sure the big icon hasn't changed */
1165 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1166 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1169 static void test_SetWindowPos(HWND hwnd)
1171 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1172 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1174 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1175 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1178 static void test_SetMenu(HWND parent)
1180 HWND child;
1181 HMENU hMenu, ret;
1183 hMenu = CreateMenu();
1184 assert(hMenu);
1186 /* parent */
1187 ret = GetMenu(parent);
1188 ok(ret == 0, "unexpected menu id %p\n", ret);
1190 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1191 ret = GetMenu(parent);
1192 ok(ret == 0, "unexpected menu id %p\n", ret);
1194 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1195 ret = GetMenu(parent);
1196 ok(ret == (HMENU)hMenu, "unexpected menu id %p\n", ret);
1198 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1199 ret = GetMenu(parent);
1200 ok(ret == 0, "unexpected menu id %p\n", ret);
1202 /* child */
1203 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1204 assert(child);
1206 ret = GetMenu(child);
1207 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1209 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1210 ret = GetMenu(child);
1211 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1213 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1214 ret = GetMenu(child);
1215 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1217 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1218 ret = GetMenu(child);
1219 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1221 DestroyWindow(child);
1222 DestroyMenu(hMenu);
1225 START_TEST(win)
1227 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
1229 if (!RegisterWindowClasses()) assert(0);
1231 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
1232 assert(hhook);
1234 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
1235 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1236 WS_MAXIMIZEBOX | WS_POPUP,
1237 100, 100, 200, 200,
1238 0, 0, 0, NULL);
1239 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
1240 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1241 WS_MAXIMIZEBOX | WS_POPUP,
1242 100, 100, 200, 200,
1243 0, 0, 0, NULL);
1244 assert( hwndMain );
1245 assert( hwndMain2 );
1247 test_parent_owner();
1248 test_shell_window();
1250 test_mdi();
1251 test_icons();
1252 test_SetWindowPos(hwndMain);
1253 test_SetMenu(hwndMain);
1255 UnhookWindowsHookEx(hhook);