Added parser template and made AVISplitter use it.
[wine] / dlls / user / tests / win.c
1 /*
2  * Unit tests for window handling
3  *
4  * Copyright 2002 Bill Medland
5  * Copyright 2002 Alexandre Julliard
6  * Copyright 2003 Dmitry Timoshkov
7  *
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.
12  *
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.
17  *
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
21  */
22
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
38
39 #include "wine/test.h"
40
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
43 #endif
44
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
47
48 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
49 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
50
51 static HWND hwndMessage;
52 static HWND hwndMain, hwndMain2;
53 static HHOOK hhook;
54
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 )
58 {
59     HWND res;
60
61     if (pGetAncestor)
62     {
63         res = pGetAncestor( hwnd, GA_PARENT );
64         ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
65     }
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)
73     {
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 );
78     }
79 }
80
81
82 static HWND create_tool_window( LONG style, HWND parent )
83 {
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;
88 }
89
90 /* test parent and owner values for various combinations */
91 static void test_parent_owner(void)
92 {
93     LONG style;
94     HWND test, owner, ret;
95     HWND desktop = GetDesktopWindow();
96     HWND child = create_tool_window( WS_CHILD, hwndMain );
97
98     trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
99
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" );
104
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" );
111
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 );
124
125     /* normal child window with WS_MAXIMIZE */
126     test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
127     DestroyWindow( test );
128
129     /* normal child window with WS_THICKFRAME */
130     test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
131     DestroyWindow( test );
132
133     /* popup window with WS_THICKFRAME */
134     test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
135     DestroyWindow( test );
136
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 );
146
147     /* child of desktop with WS_MAXIMIZE */
148     test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
149     DestroyWindow( test );
150
151     /* child of desktop with WS_MINIMIZE */
152     test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
153     DestroyWindow( test );
154
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 );
164
165     /* child of child with WS_MAXIMIZE */
166     test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
167     DestroyWindow( test );
168
169     /* child of child with WS_MINIMIZE */
170     test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
171     DestroyWindow( test );
172
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 );
182
183     /* not owned top-level window with WS_MAXIMIZE */
184     test = create_tool_window( WS_MAXIMIZE, 0 );
185     DestroyWindow( test );
186
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 );
196
197     /* owned top-level window with WS_MAXIMIZE */
198     test = create_tool_window( WS_MAXIMIZE, hwndMain );
199     DestroyWindow( test );
200
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 );
210
211     /* not owned popup with WS_MAXIMIZE */
212     test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
213     DestroyWindow( test );
214
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 );
224
225     /* owned popup with WS_MAXIMIZE */
226     test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
227     DestroyWindow( test );
228
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 );
234
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 );
238
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 );
244
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 );
248
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 );
254
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 );
258
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 );
264
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 );
268
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 );
274
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 );
278
279     /******************** parent changes *************************/
280     trace( "testing parent changes\n" );
281
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 );
294
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 );
298
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 );
302
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 );
306
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 );
311
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 );
316
317     /* not owned top-level window */
318     test = create_tool_window( 0, 0 );
319     trace( "created top-level %p\n", test );
320
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 );
324
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 );
328
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 );
333
334     /* not owned popup */
335     test = create_tool_window( WS_POPUP, 0 );
336     trace( "created popup %p\n", test );
337
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 );
341
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 );
345
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 );
350
351     /* normal child window */
352     test = create_tool_window( WS_CHILD, hwndMain );
353     trace( "created child %p\n", test );
354
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 );
358
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 );
362
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 );
367
368     /* not owned top-level window */
369     test = create_tool_window( 0, 0 );
370     trace( "created top-level %p\n", test );
371
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 );
376
377     /* owned popup */
378     test = create_tool_window( WS_POPUP, hwndMain2 );
379     trace( "created owned popup %p\n", test );
380
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 );
384
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 );
389
390     /**************** test owner destruction *******************/
391
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.
404      */
405     /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
406     ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
407     DestroyWindow(test);
408
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 );
416
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.
429      */
430     /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
431     DestroyWindow(test);
432
433     /* final cleanup */
434     DestroyWindow(child);
435 }
436
437
438 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
439 {
440     switch (msg)
441     {
442         case WM_GETMINMAXINFO:
443         {
444             MINMAXINFO* minmax = (MINMAXINFO *)lparam;
445
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;
456         }
457         case WM_WINDOWPOSCHANGING:
458         {
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))
466             {
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);
469             }
470             /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
471             if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
472             {
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);
475             }
476             break;
477         }
478         case WM_WINDOWPOSCHANGED:
479         {
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);
488
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);
491
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
501
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;
507         }
508         case WM_NCCREATE:
509         {
510             BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
511             CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
512
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);
516
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;
522         }
523     }
524
525     return DefWindowProcA(hwnd, msg, wparam, lparam);
526 }
527
528 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
529 {
530     switch (msg)
531     {
532         case WM_GETMINMAXINFO:
533         {
534             MINMAXINFO* minmax = (MINMAXINFO *)lparam;
535
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;
546         }
547         case WM_NCCREATE:
548         {
549             BOOL got_getminmaxinfo = GetWindowLongA(hwnd, GWL_USERDATA) == 0x20031021;
550             CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
551
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);
555
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;
561         }
562     }
563
564     return DefWindowProcA(hwnd, msg, wparam, lparam);
565 }
566
567 static BOOL RegisterWindowClasses(void)
568 {
569     WNDCLASSA cls;
570
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";
581
582     if(!RegisterClassA(&cls)) return FALSE;
583
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";
594
595     if(!RegisterClassA(&cls)) return FALSE;
596
597     return TRUE;
598 }
599
600 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
601 {
602     RECT rcWindow, rcClient;
603     UINT border;
604     DWORD status;
605
606     ok(IsWindow(hwnd), "bad window handle\n");
607
608     GetWindowRect(hwnd, &rcWindow);
609     ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
610
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");
615
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");
620
621     if (test_borders && !IsRectEmpty(&rcWindow))
622     {
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);
625
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);
631     }
632
633     ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
634     ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
635 }
636
637 static void test_nonclient_area(HWND hwnd)
638 {
639     DWORD style, exstyle;
640     RECT rc_window, rc_client, rc;
641     BOOL menu;
642
643     style = GetWindowLongA(hwnd, GWL_STYLE);
644     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
645     menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
646
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);
651
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;
655
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
663
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
671
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);
679
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
687 }
688
689 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
690
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";
703
704     trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
705
706     /* on HCBT_DESTROYWND window state is undefined */
707     if (nCode != HCBT_DESTROYWND && wParam)
708     {
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);
714
715         if (pGetWindowInfo)
716         {
717             WINDOWINFO info;
718
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.
722              */
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.
727              */
728             verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
729         }
730     }
731
732     switch (nCode)
733     {
734         case HCBT_CREATEWND:
735         {
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");
745
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);
751
752 #if 0 /* Uncomment this once the test succeeds in all cases */
753             if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
754             {
755                 ok(GetParent((HWND)wParam) == hwndMessage,
756                    "wrong result from GetParent %p: message window %p\n",
757                    GetParent((HWND)wParam), hwndMessage);
758             }
759             else
760                 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
761
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.
766              */
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");
772
773 #if 0 /* Uncomment this once the test succeeds in all cases */
774             if (pGetAncestor)
775             {
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);
779
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);
786             }
787
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;
794         }
795     }
796
797     return CallNextHookEx(hhook, nCode, wParam, lParam);
798 }
799
800 static void test_shell_window(void)
801 {
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;
809
810     if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
811     {
812         trace("Skipping shell window test on Win9x\n");
813         return;
814     }
815
816     shellWindow = GetShellWindow();
817     hinst = GetModuleHandle(0);
818     hUser32 = GetModuleHandleA("user32");
819
820     SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
821     SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
822
823     trace("previous shell window: %p\n", shellWindow);
824
825     if (shellWindow) {
826         DWORD pid;
827         HANDLE hProcess;
828
829         ret = DestroyWindow(shellWindow);
830         error = GetLastError();
831
832         ok(!ret, "DestroyWindow(shellWindow)\n");
833         /* passes on Win XP, but not on Win98 */
834         ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
835
836         /* close old shell instance */
837         GetWindowThreadProcessId(shellWindow, &pid);
838         hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
839         ret = TerminateProcess(hProcess, 0);
840         ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
841         WaitForSingleObject(hProcess, INFINITE);    /* wait for termination */
842         CloseHandle(hProcess);
843     }
844
845     hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
846     trace("created window 1: %p\n", hwnd1);
847
848     ret = SetShellWindow(hwnd1);
849     ok(ret, "first call to SetShellWindow(hwnd1)\n");
850     shellWindow = GetShellWindow();
851     ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
852
853     ret = SetShellWindow(hwnd1);
854     ok(!ret, "second call to SetShellWindow(hwnd1)\n");
855
856     ret = SetShellWindow(0);
857     error = GetLastError();
858     /* passes on Win XP, but not on Win98
859     ok(!ret, "reset shell window by SetShellWindow(0)\n");
860     ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
861
862     ret = SetShellWindow(hwnd1);
863     /* passes on Win XP, but not on Win98
864     ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
865
866     todo_wine
867     {
868         SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
869         ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
870         ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
871     }
872
873     ret = DestroyWindow(hwnd1);
874     ok(ret, "DestroyWindow(hwnd1)\n");
875
876     hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
877     trace("created window 2: %p\n", hwnd2);
878     ret = SetShellWindow(hwnd2);
879     ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
880
881     hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
882     trace("created window 3: %p\n", hwnd3);
883
884     hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
885     trace("created window 4: %p\n", hwnd4);
886
887     nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
888     ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
889
890     ret = SetShellWindow(hwnd4);
891     ok(ret, "SetShellWindow(hwnd4)\n");
892     shellWindow = GetShellWindow();
893     ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
894
895     nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
896     ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
897
898     ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
899     ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
900
901     ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
902     ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
903
904     ret = SetShellWindow(hwnd3);
905     ok(!ret, "SetShellWindow(hwnd3)\n");
906     shellWindow = GetShellWindow();
907     ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
908
909     hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
910     trace("created window 5: %p\n", hwnd5);
911     ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
912     ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
913
914     todo_wine
915     {
916         nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
917         ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
918     }
919
920     /* destroy test windows */
921     DestroyWindow(hwnd2);
922     DestroyWindow(hwnd3);
923     DestroyWindow(hwnd4);
924     DestroyWindow(hwnd5);
925 }
926
927 /************** MDI test ****************/
928
929 static const char mdi_lParam_test_message[] = "just a test string";
930
931 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
932 {
933     MDICREATESTRUCTA mdi_cs;
934     HWND mdi_child;
935     static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
936     static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
937     BOOL isWin9x = FALSE;
938
939     mdi_cs.szClass = "MDI_child_Class_1";
940     mdi_cs.szTitle = "MDI child";
941     mdi_cs.hOwner = GetModuleHandle(0);
942     mdi_cs.x = CW_USEDEFAULT;
943     mdi_cs.y = CW_USEDEFAULT;
944     mdi_cs.cx = CW_USEDEFAULT;
945     mdi_cs.cy = CW_USEDEFAULT;
946     mdi_cs.style = 0;
947     mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
948     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
949     ok(mdi_child != 0, "MDI child creation failed\n");
950     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
951     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
952     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
953
954     mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
955     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
956     ok(mdi_child != 0, "MDI child creation failed\n");
957     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
958     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
959     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
960
961     mdi_cs.style = 0xffffffff; /* with WS_POPUP */
962     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
963     if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
964     {
965         ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
966     }
967     else
968     {
969         ok(mdi_child != 0, "MDI child creation failed\n");
970         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
971         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
972         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
973     }
974
975     /* test MDICREATESTRUCT A<->W mapping */
976     /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
977     mdi_cs.style = 0;
978     mdi_cs.szClass = (LPCSTR)classW;
979     mdi_cs.szTitle = (LPCSTR)titleW;
980     SetLastError(0xdeadbeef);
981     mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
982     if (!mdi_child)
983     {
984         if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
985             isWin9x = TRUE;
986         else
987             ok(mdi_child != 0, "MDI child creation failed\n");
988     }
989     else
990     {
991         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
992         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
993         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
994     }
995
996     mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
997                                  0,
998                                  CW_USEDEFAULT, CW_USEDEFAULT,
999                                  CW_USEDEFAULT, CW_USEDEFAULT,
1000                                  mdi_client, GetModuleHandle(0),
1001                                  (LPARAM)mdi_lParam_test_message);
1002     ok(mdi_child != 0, "MDI child creation failed\n");
1003     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1004     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1005     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1006
1007     mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1008                                  0x7fffffff, /* without WS_POPUP */
1009                                  CW_USEDEFAULT, CW_USEDEFAULT,
1010                                  CW_USEDEFAULT, CW_USEDEFAULT,
1011                                  mdi_client, GetModuleHandle(0),
1012                                  (LPARAM)mdi_lParam_test_message);
1013     ok(mdi_child != 0, "MDI child creation failed\n");
1014     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1015     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1016     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1017
1018     mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1019                                  0xffffffff, /* with WS_POPUP */
1020                                  CW_USEDEFAULT, CW_USEDEFAULT,
1021                                  CW_USEDEFAULT, CW_USEDEFAULT,
1022                                  mdi_client, GetModuleHandle(0),
1023                                  (LPARAM)mdi_lParam_test_message);
1024     if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1025     {
1026         ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1027     }
1028     else
1029     {
1030         ok(mdi_child != 0, "MDI child creation failed\n");
1031         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1032         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1033         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1034     }
1035
1036     /* test MDICREATESTRUCT A<->W mapping */
1037     SetLastError(0xdeadbeef);
1038     mdi_child = CreateMDIWindowW(classW, titleW,
1039                                  0,
1040                                  CW_USEDEFAULT, CW_USEDEFAULT,
1041                                  CW_USEDEFAULT, CW_USEDEFAULT,
1042                                  mdi_client, GetModuleHandle(0),
1043                                  (LPARAM)mdi_lParam_test_message);
1044     if (!mdi_child)
1045     {
1046         if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1047             isWin9x = TRUE;
1048         else
1049             ok(mdi_child != 0, "MDI child creation failed\n");
1050     }
1051     else
1052     {
1053         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1054         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1055         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1056     }
1057
1058     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1059                                 0,
1060                                 CW_USEDEFAULT, CW_USEDEFAULT,
1061                                 CW_USEDEFAULT, CW_USEDEFAULT,
1062                                 mdi_client, 0, GetModuleHandle(0),
1063                                 (LPVOID)mdi_lParam_test_message);
1064     ok(mdi_child != 0, "MDI child creation failed\n");
1065     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1066     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1067     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1068
1069     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1070                                 0x7fffffff, /* without WS_POPUP */
1071                                 CW_USEDEFAULT, CW_USEDEFAULT,
1072                                 CW_USEDEFAULT, CW_USEDEFAULT,
1073                                 mdi_client, 0, GetModuleHandle(0),
1074                                 (LPVOID)mdi_lParam_test_message);
1075     ok(mdi_child != 0, "MDI child creation failed\n");
1076     ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1077     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1078     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1079
1080     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1081                                 0xffffffff, /* with WS_POPUP */
1082                                 CW_USEDEFAULT, CW_USEDEFAULT,
1083                                 CW_USEDEFAULT, CW_USEDEFAULT,
1084                                 mdi_client, 0, GetModuleHandle(0),
1085                                 (LPVOID)mdi_lParam_test_message);
1086     if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1087     {
1088         ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1089     }
1090     else
1091     {
1092         ok(mdi_child != 0, "MDI child creation failed\n");
1093         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1094         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1095         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1096     }
1097
1098     /* test MDICREATESTRUCT A<->W mapping */
1099     SetLastError(0xdeadbeef);
1100     mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1101                                 0,
1102                                 CW_USEDEFAULT, CW_USEDEFAULT,
1103                                 CW_USEDEFAULT, CW_USEDEFAULT,
1104                                 mdi_client, 0, GetModuleHandle(0),
1105                                 (LPVOID)mdi_lParam_test_message);
1106     if (!mdi_child)
1107     {
1108         if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1109             isWin9x = TRUE;
1110         else
1111             ok(mdi_child != 0, "MDI child creation failed\n");
1112     }
1113     else
1114     {
1115         ok(GetWindowLongA(mdi_child, GWL_ID) == first_id, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1116         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1117         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1118     }
1119
1120     /* This test fails on Win9x */
1121     if (!isWin9x)
1122     {
1123         mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1124                                 WS_CHILD,
1125                                 CW_USEDEFAULT, CW_USEDEFAULT,
1126                                 CW_USEDEFAULT, CW_USEDEFAULT,
1127                                 parent, 0, GetModuleHandle(0),
1128                                 (LPVOID)mdi_lParam_test_message);
1129         ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1130     }
1131
1132     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1133                                 WS_CHILD, /* without WS_POPUP */
1134                                 CW_USEDEFAULT, CW_USEDEFAULT,
1135                                 CW_USEDEFAULT, CW_USEDEFAULT,
1136                                 mdi_client, 0, GetModuleHandle(0),
1137                                 (LPVOID)mdi_lParam_test_message);
1138     ok(mdi_child != 0, "MDI child creation failed\n");
1139     ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1140     DestroyWindow(mdi_child);
1141
1142     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1143                                 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1144                                 CW_USEDEFAULT, CW_USEDEFAULT,
1145                                 CW_USEDEFAULT, CW_USEDEFAULT,
1146                                 mdi_client, 0, GetModuleHandle(0),
1147                                 (LPVOID)mdi_lParam_test_message);
1148     ok(mdi_child != 0, "MDI child creation failed\n");
1149     ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1150     DestroyWindow(mdi_child);
1151
1152     /* maximized child */
1153     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1154                                 WS_CHILD | WS_MAXIMIZE,
1155                                 CW_USEDEFAULT, CW_USEDEFAULT,
1156                                 CW_USEDEFAULT, CW_USEDEFAULT,
1157                                 mdi_client, 0, GetModuleHandle(0),
1158                                 (LPVOID)mdi_lParam_test_message);
1159     ok(mdi_child != 0, "MDI child creation failed\n");
1160     ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1161     DestroyWindow(mdi_child);
1162
1163     trace("Creating maximized child with a caption\n");
1164     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1165                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1166                                 CW_USEDEFAULT, CW_USEDEFAULT,
1167                                 CW_USEDEFAULT, CW_USEDEFAULT,
1168                                 mdi_client, 0, GetModuleHandle(0),
1169                                 (LPVOID)mdi_lParam_test_message);
1170     ok(mdi_child != 0, "MDI child creation failed\n");
1171     ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1172     DestroyWindow(mdi_child);
1173
1174     trace("Creating maximized child with a caption and a thick frame\n");
1175     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1176                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1177                                 CW_USEDEFAULT, CW_USEDEFAULT,
1178                                 CW_USEDEFAULT, CW_USEDEFAULT,
1179                                 mdi_client, 0, GetModuleHandle(0),
1180                                 (LPVOID)mdi_lParam_test_message);
1181     ok(mdi_child != 0, "MDI child creation failed\n");
1182     ok(GetWindowLongA(mdi_child, GWL_ID) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child, GWL_ID));
1183     DestroyWindow(mdi_child);
1184 }
1185
1186 /**********************************************************************
1187  * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1188  *
1189  * Note: The rule here is that client rect of the maximized MDI child
1190  *       is equal to the client rect of the MDI client window.
1191  */
1192 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1193 {
1194     RECT rect;
1195
1196     GetClientRect( client, &rect );
1197     AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1198                         0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1199
1200     rect.right -= rect.left;
1201     rect.bottom -= rect.top;
1202     lpMinMax->ptMaxSize.x = rect.right;
1203     lpMinMax->ptMaxSize.y = rect.bottom;
1204
1205     lpMinMax->ptMaxPosition.x = rect.left;
1206     lpMinMax->ptMaxPosition.y = rect.top;
1207
1208     trace("max rect (%ld,%ld - %ld, %ld)\n",
1209            rect.left, rect.top, rect.right, rect.bottom);
1210 }
1211
1212 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1213 {
1214     switch (msg)
1215     {
1216         case WM_NCCREATE:
1217         case WM_CREATE:
1218         {
1219             CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1220             MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1221
1222             ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1223             ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1224
1225             ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1226             ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1227             ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1228             ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1229             ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1230
1231             /* MDICREATESTRUCT should have original values */
1232             ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1233                 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1234             ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1235             ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1236             ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1237             ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1238
1239             /* CREATESTRUCT should have fixed values */
1240             ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1241             ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1242
1243             /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1244             ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1245             ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1246
1247             ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1248
1249             if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1250             {
1251                 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1252                 ok(cs->style == style,
1253                    "cs->style does not match (%08lx)\n", cs->style);
1254             }
1255             else
1256             {
1257                 LONG style = mdi_cs->style;
1258                 style &= ~WS_POPUP;
1259                 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1260                     WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1261                 ok(cs->style == style,
1262                    "cs->style does not match (%08lx)\n", cs->style);
1263             }
1264             break;
1265         }
1266
1267         case WM_GETMINMAXINFO:
1268         {
1269             HWND client = GetParent(hwnd);
1270             RECT rc;
1271             MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1272             MINMAXINFO my_minmax;
1273             LONG style, exstyle;
1274
1275             style = GetWindowLongA(hwnd, GWL_STYLE);
1276             exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1277
1278             GetWindowRect(client, &rc);
1279             trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1280             GetClientRect(client, &rc);
1281             trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1282             trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1283                                             GetSystemMetrics(SM_CYSCREEN));
1284
1285             GetClientRect(client, &rc);
1286             if ((style & WS_CAPTION) == WS_CAPTION)
1287                 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1288             AdjustWindowRectEx(&rc, style, 0, exstyle);
1289             trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1290
1291             trace("ptReserved = (%ld,%ld)\n"
1292                   "ptMaxSize = (%ld,%ld)\n"
1293                   "ptMaxPosition = (%ld,%ld)\n"
1294                   "ptMinTrackSize = (%ld,%ld)\n"
1295                   "ptMaxTrackSize = (%ld,%ld)\n",
1296                   minmax->ptReserved.x, minmax->ptReserved.y,
1297                   minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1298                   minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1299                   minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1300                   minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1301
1302             ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1303                minmax->ptMaxSize.x, rc.right - rc.left);
1304             ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1305                minmax->ptMaxSize.y, rc.bottom - rc.top);
1306
1307             DefMDIChildProcA(hwnd, msg, wparam, lparam);
1308
1309             trace("DefMDIChildProc returned:\n"
1310                   "ptReserved = (%ld,%ld)\n"
1311                   "ptMaxSize = (%ld,%ld)\n"
1312                   "ptMaxPosition = (%ld,%ld)\n"
1313                   "ptMinTrackSize = (%ld,%ld)\n"
1314                   "ptMaxTrackSize = (%ld,%ld)\n",
1315                   minmax->ptReserved.x, minmax->ptReserved.y,
1316                   minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1317                   minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1318                   minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1319                   minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1320
1321             MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1322             ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1323                minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1324             ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1325                minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1326
1327             return 1;
1328         }
1329
1330         case WM_MDIACTIVATE:
1331         {
1332             HWND active, client = GetParent(hwnd);
1333             /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1334             active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1335             if (hwnd == (HWND)lparam) /* if we are being activated */
1336                 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1337             else
1338                 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1339             break;
1340         }
1341     }
1342     return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1343 }
1344
1345 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1346 {
1347     switch (msg)
1348     {
1349         case WM_NCCREATE:
1350         case WM_CREATE:
1351         {
1352             CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1353
1354             trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1355             trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1356
1357             ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1358             ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1359
1360             ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1361             ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1362
1363             /* CREATESTRUCT should have fixed values */
1364             /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1365                while NT does. */
1366             /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1367             ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1368
1369             /* cx/cy == CW_USEDEFAULT are translated to 0 */
1370             /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1371                while Win95, Win2k, WinXP do. */
1372             /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1373             ok(cs->cy == 0, "%d != 0\n", cs->cy);
1374             break;
1375         }
1376
1377         case WM_GETMINMAXINFO:
1378         {
1379             HWND parent = GetParent(hwnd);
1380             RECT rc;
1381             MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1382             LONG style, exstyle;
1383
1384             trace("WM_GETMINMAXINFO\n");
1385
1386             style = GetWindowLongA(hwnd, GWL_STYLE);
1387             exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1388
1389             GetClientRect(parent, &rc);
1390             trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1391
1392             GetClientRect(parent, &rc);
1393             if ((style & WS_CAPTION) == WS_CAPTION)
1394                 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1395             AdjustWindowRectEx(&rc, style, 0, exstyle);
1396             trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1397
1398             trace("ptReserved = (%ld,%ld)\n"
1399                   "ptMaxSize = (%ld,%ld)\n"
1400                   "ptMaxPosition = (%ld,%ld)\n"
1401                   "ptMinTrackSize = (%ld,%ld)\n"
1402                   "ptMaxTrackSize = (%ld,%ld)\n",
1403                   minmax->ptReserved.x, minmax->ptReserved.y,
1404                   minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1405                   minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1406                   minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1407                   minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1408
1409             ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1410                minmax->ptMaxSize.x, rc.right - rc.left);
1411             ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1412                minmax->ptMaxSize.y, rc.bottom - rc.top);
1413             break;
1414         }
1415
1416         case WM_WINDOWPOSCHANGED:
1417         {
1418             WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1419             RECT rc1, rc2;
1420
1421             GetWindowRect(hwnd, &rc1);
1422             trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1423             SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1424             /* note: winpos coordinates are relative to parent */
1425             MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1426             trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1427             ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1428
1429             GetWindowRect(hwnd, &rc1);
1430             GetClientRect(hwnd, &rc2);
1431             DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1432             MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1433             ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1434         }
1435         /* fall through */
1436         case WM_WINDOWPOSCHANGING:
1437         {
1438             WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1439             WINDOWPOS my_winpos = *winpos;
1440
1441             trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1442             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1443                   winpos->hwnd, winpos->hwndInsertAfter,
1444                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1445
1446             DefWindowProcA(hwnd, msg, wparam, lparam);
1447
1448             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1449                   winpos->hwnd, winpos->hwndInsertAfter,
1450                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1451
1452             ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1453                "DefWindowProc should not change WINDOWPOS values\n");
1454
1455             return 1;
1456         }
1457     }
1458     return DefWindowProcA(hwnd, msg, wparam, lparam);
1459 }
1460
1461 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1462 {
1463     static HWND mdi_client;
1464
1465     switch (msg)
1466     {
1467         case WM_CREATE:
1468         {
1469             CLIENTCREATESTRUCT client_cs;
1470             RECT rc;
1471
1472             GetClientRect(hwnd, &rc);
1473
1474             client_cs.hWindowMenu = 0;
1475             client_cs.idFirstChild = 1;
1476
1477             /* MDIClient without MDIS_ALLCHILDSTYLES */
1478             mdi_client = CreateWindowExA(0, "mdiclient",
1479                                          NULL,
1480                                          WS_CHILD /*| WS_VISIBLE*/,
1481                                           /* tests depend on a not zero MDIClient size */
1482                                          0, 0, rc.right, rc.bottom,
1483                                          hwnd, 0, GetModuleHandle(0),
1484                                          (LPVOID)&client_cs);
1485             assert(mdi_client);
1486             test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1487             DestroyWindow(mdi_client);
1488
1489             /* MDIClient with MDIS_ALLCHILDSTYLES */
1490             mdi_client = CreateWindowExA(0, "mdiclient",
1491                                          NULL,
1492                                          WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1493                                           /* tests depend on a not zero MDIClient size */
1494                                          0, 0, rc.right, rc.bottom,
1495                                          hwnd, 0, GetModuleHandle(0),
1496                                          (LPVOID)&client_cs);
1497             assert(mdi_client);
1498             test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1499             DestroyWindow(mdi_client);
1500             break;
1501         }
1502
1503         case WM_WINDOWPOSCHANGED:
1504         {
1505             WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1506             RECT rc1, rc2;
1507
1508             GetWindowRect(hwnd, &rc1);
1509             trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1510             SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1511             /* note: winpos coordinates are relative to parent */
1512             MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1513             trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1514             ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1515
1516             GetWindowRect(hwnd, &rc1);
1517             GetClientRect(hwnd, &rc2);
1518             DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1519             MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1520             ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1521         }
1522         /* fall through */
1523         case WM_WINDOWPOSCHANGING:
1524         {
1525             WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1526             WINDOWPOS my_winpos = *winpos;
1527
1528             trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1529             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1530                   winpos->hwnd, winpos->hwndInsertAfter,
1531                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1532
1533             DefWindowProcA(hwnd, msg, wparam, lparam);
1534
1535             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1536                   winpos->hwnd, winpos->hwndInsertAfter,
1537                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1538
1539             ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1540                "DefWindowProc should not change WINDOWPOS values\n");
1541
1542             return 1;
1543         }
1544
1545         case WM_CLOSE:
1546             PostQuitMessage(0);
1547             break;
1548     }
1549     return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1550 }
1551
1552 static BOOL mdi_RegisterWindowClasses(void)
1553 {
1554     WNDCLASSA cls;
1555
1556     cls.style = 0;
1557     cls.lpfnWndProc = mdi_main_wnd_procA;
1558     cls.cbClsExtra = 0;
1559     cls.cbWndExtra = 0;
1560     cls.hInstance = GetModuleHandleA(0);
1561     cls.hIcon = 0;
1562     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1563     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1564     cls.lpszMenuName = NULL;
1565     cls.lpszClassName = "MDI_parent_Class";
1566     if(!RegisterClassA(&cls)) return FALSE;
1567
1568     cls.lpfnWndProc = mdi_child_wnd_proc_1;
1569     cls.lpszClassName = "MDI_child_Class_1";
1570     if(!RegisterClassA(&cls)) return FALSE;
1571
1572     cls.lpfnWndProc = mdi_child_wnd_proc_2;
1573     cls.lpszClassName = "MDI_child_Class_2";
1574     if(!RegisterClassA(&cls)) return FALSE;
1575
1576     return TRUE;
1577 }
1578
1579 static void test_mdi(void)
1580 {
1581     HWND mdi_hwndMain;
1582     /*MSG msg;*/
1583
1584     if (!mdi_RegisterWindowClasses()) assert(0);
1585
1586     mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1587                                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1588                                    WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1589                                    100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1590                                    GetDesktopWindow(), 0,
1591                                    GetModuleHandle(0), NULL);
1592     assert(mdi_hwndMain);
1593 /*
1594     while(GetMessage(&msg, 0, 0, 0))
1595     {
1596         TranslateMessage(&msg);
1597         DispatchMessage(&msg);
1598     }
1599 */
1600 }
1601
1602 static void test_icons(void)
1603 {
1604     WNDCLASSEXA cls;
1605     HWND hwnd;
1606     HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1607     HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1608     HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1609                                   GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1610     HICON res;
1611
1612     cls.cbSize = sizeof(cls);
1613     cls.style = 0;
1614     cls.lpfnWndProc = DefWindowProcA;
1615     cls.cbClsExtra = 0;
1616     cls.cbWndExtra = 0;
1617     cls.hInstance = 0;
1618     cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1619     cls.hIconSm = small_icon;
1620     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1621     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1622     cls.lpszMenuName = NULL;
1623     cls.lpszClassName = "IconWindowClass";
1624
1625     RegisterClassExA(&cls);
1626
1627     hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1628                            100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1629     assert( hwnd );
1630
1631     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1632     ok( res == 0, "wrong big icon %p/0\n", res );
1633     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1634     ok( res == 0, "wrong previous big icon %p/0\n", res );
1635     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1636     ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1637     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1638     ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1639     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1640     ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1641
1642     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1643     ok( res == 0, "wrong small icon %p/0\n", res );
1644     /* this test is XP specific */
1645     /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1646     ok( res != 0, "wrong small icon %p\n", res );*/
1647     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1648     ok( res == 0, "wrong previous small icon %p/0\n", res );
1649     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1650     ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1651     /* this test is XP specific */
1652     /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1653     ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1654     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1655     ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1656     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1657     ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1658     /* this test is XP specific */
1659     /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1660     ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1661
1662     /* make sure the big icon hasn't changed */
1663     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1664     ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1665 }
1666
1667 static void test_SetWindowPos(HWND hwnd)
1668 {
1669     RECT orig_win_rc;
1670     BOOL is_win9x = GetWindowLongW(hwnd, GWL_WNDPROC) == 0;
1671
1672     /* Win9x truncates coordinates to 16-bit irrespectively */
1673     if (is_win9x) return;
1674
1675     GetWindowRect(hwnd, &orig_win_rc);
1676
1677     SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1678     SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1679
1680     SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1681     SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1682
1683     SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1684                  orig_win_rc.right, orig_win_rc.bottom, 0);
1685 }
1686
1687 static void test_SetMenu(HWND parent)
1688 {
1689     HWND child;
1690     HMENU hMenu, ret;
1691     BOOL is_win9x = GetWindowLongW(parent, GWL_WNDPROC) == 0;
1692     BOOL retok;
1693
1694     hMenu = CreateMenu();
1695     assert(hMenu);
1696
1697     ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1698     test_nonclient_area(parent);
1699     ret = GetMenu(parent);
1700     ok(ret == hMenu, "unexpected menu id %p\n", ret);
1701     /* test whether we can destroy a menu assigned to a window */
1702     retok = DestroyMenu(hMenu);
1703     ok( retok, "DestroyMenu error %ld\n", GetLastError());
1704     ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1705     ret = GetMenu(parent);
1706     /* This test fails on Win9x */
1707     if (!is_win9x)
1708         ok(ret == hMenu, "unexpected menu id %p\n", ret);
1709     ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1710     test_nonclient_area(parent);
1711
1712     hMenu = CreateMenu();
1713     assert(hMenu);
1714
1715     /* parent */
1716     ret = GetMenu(parent);
1717     ok(ret == 0, "unexpected menu id %p\n", ret);
1718
1719     ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1720     test_nonclient_area(parent);
1721     ret = GetMenu(parent);
1722     ok(ret == 0, "unexpected menu id %p\n", ret);
1723
1724     ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1725     test_nonclient_area(parent);
1726     ret = GetMenu(parent);
1727     ok(ret == hMenu, "unexpected menu id %p\n", ret);
1728
1729     ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1730     test_nonclient_area(parent);
1731     ret = GetMenu(parent);
1732     ok(ret == 0, "unexpected menu id %p\n", ret);
1733  
1734     /* child */
1735     child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1736     assert(child);
1737
1738     ret = GetMenu(child);
1739     ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1740
1741     ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1742     test_nonclient_area(child);
1743     ret = GetMenu(child);
1744     ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1745
1746     ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1747     test_nonclient_area(child);
1748     ret = GetMenu(child);
1749     ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1750
1751     ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1752     test_nonclient_area(child);
1753     ret = GetMenu(child);
1754     ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1755
1756     DestroyWindow(child);
1757     DestroyMenu(hMenu);
1758 }
1759
1760 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1761 {
1762     HWND child[5], hwnd;
1763     int i;
1764
1765     assert(total <= 5);
1766
1767     hwnd = GetWindow(parent, GW_CHILD);
1768     ok(!hwnd, "have to start without children to perform the test\n");
1769
1770     for (i = 0; i < total; i++)
1771     {
1772         child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1773                                    parent, 0, 0, NULL);
1774         trace("child[%d] = %p\n", i, child[i]);
1775         ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1776     }
1777
1778     hwnd = GetWindow(parent, GW_CHILD);
1779     ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1780     ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1781     ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1782
1783     for (i = 0; i < total; i++)
1784     {
1785         trace("hwnd[%d] = %p\n", i, hwnd);
1786         ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1787
1788         hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1789     }
1790
1791     for (i = 0; i < total; i++)
1792         ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1793 }
1794
1795 static void test_children_zorder(HWND parent)
1796 {
1797     const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1798                                     WS_CHILD };
1799     const int simple_order[5] = { 0, 1, 2, 3, 4 };
1800
1801     const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1802                              WS_CHILD | WS_VISIBLE, WS_CHILD,
1803                              WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
1804     const int complex_order_1[1] = { 0 };
1805     const int complex_order_2[2] = { 1, 0 };
1806     const int complex_order_3[3] = { 1, 0, 2 };
1807     const int complex_order_4[4] = { 1, 0, 2, 3 };
1808     const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
1809
1810     /* simple WS_CHILD */
1811     test_window_tree(parent, simple_style, simple_order, 5);
1812
1813     /* complex children styles */
1814     test_window_tree(parent, complex_style, complex_order_1, 1);
1815     test_window_tree(parent, complex_style, complex_order_2, 2);
1816     test_window_tree(parent, complex_style, complex_order_3, 3);
1817     test_window_tree(parent, complex_style, complex_order_4, 4);
1818     test_window_tree(parent, complex_style, complex_order_5, 5);
1819 }
1820
1821 static void test_SetFocus(HWND hwnd)
1822 {
1823     HWND child;
1824
1825     /* check if we can set focus to non-visible windows */
1826
1827     ShowWindow(hwnd, SW_SHOW);
1828     SetFocus(0);
1829     SetFocus(hwnd);
1830     ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1831     ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
1832     ShowWindow(hwnd, SW_HIDE);
1833     SetFocus(0);
1834     SetFocus(hwnd);
1835     ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
1836     ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
1837     child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1838     assert(child);
1839     SetFocus(child);
1840     ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
1841     ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1842     ShowWindow(child, SW_SHOW);
1843     ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
1844     ok( GetFocus() == child, "Focus no longer on child %p\n", child );
1845     ShowWindow(child, SW_HIDE);
1846     ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
1847     ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1848     ShowWindow(child, SW_SHOW);
1849     SetFocus(child);
1850     ok( GetFocus() == child, "Focus should be on child %p\n", child );
1851     SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
1852     ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1853
1854     ShowWindow(child, SW_HIDE);
1855     SetFocus(hwnd);
1856     ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
1857     SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1858     ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1859     ShowWindow(child, SW_HIDE);
1860     ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
1861
1862     ShowWindow(hwnd, SW_SHOW);
1863     ShowWindow(child, SW_SHOW);
1864     SetFocus(child);
1865     ok( GetFocus() == child, "Focus should be on child %p\n", child );
1866     EnableWindow(hwnd, FALSE);
1867     ok( GetFocus() == child, "Focus should still be on child %p\n", child );
1868     EnableWindow(hwnd, TRUE);
1869
1870     DestroyWindow( child );
1871 }
1872
1873 static void test_SetActiveWindow(HWND hwnd)
1874 {
1875     HWND hwnd2;
1876
1877     ShowWindow(hwnd, SW_SHOW);
1878     SetActiveWindow(0);
1879     SetActiveWindow(hwnd);
1880     ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
1881     SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1882     ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
1883     SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
1884     ShowWindow(hwnd, SW_HIDE);
1885     ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
1886
1887     /* trace("**testing an invisible window now\n"); */
1888     SetActiveWindow(hwnd);
1889     ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
1890     ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
1891     
1892     ShowWindow(hwnd, SW_SHOW);
1893
1894     hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1895     ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1896     DestroyWindow(hwnd2);
1897     ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1898
1899     hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
1900     ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
1901     SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
1902     ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
1903     DestroyWindow(hwnd2);
1904     ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
1905 }
1906
1907 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
1908 {
1909     ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1910     if (foreground)
1911         ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1912     ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
1913     ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
1914 }
1915
1916 static WNDPROC old_button_proc;
1917
1918 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
1919 {
1920     LRESULT ret;
1921     USHORT key_state;
1922
1923     key_state = GetKeyState(VK_LBUTTON);
1924     ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
1925
1926     ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
1927
1928     if (msg == WM_LBUTTONDOWN)
1929     {
1930         HWND hwnd, capture;
1931
1932         check_wnd_state(button, button, button, button);
1933
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);
1937
1938         check_wnd_state(button, button, button, button);
1939
1940         ShowWindow(hwnd, SW_SHOWNOACTIVATE);
1941
1942         check_wnd_state(button, button, button, button);
1943
1944         DestroyWindow(hwnd);
1945
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);
1949
1950         check_wnd_state(button, button, button, button);
1951
1952         /* button wnd proc should release capture on WM_KILLFOCUS if it does
1953          * match internal button state.
1954          */
1955         SendMessage(button, WM_KILLFOCUS, 0, 0);
1956         check_wnd_state(button, button, button, 0);
1957
1958         ShowWindow(hwnd, SW_SHOW);
1959         check_wnd_state(hwnd, hwnd, hwnd, 0);
1960
1961         capture = SetCapture(hwnd);
1962         ok(capture == 0, "SetCapture() = %p\n", capture);
1963
1964         check_wnd_state(hwnd, hwnd, hwnd, hwnd);
1965
1966         DestroyWindow(hwnd);
1967
1968         check_wnd_state(button, 0, button, 0);
1969     }
1970
1971     return ret;
1972 }
1973
1974 static void test_capture_1(void)
1975 {
1976     HWND button, capture;
1977
1978     capture = GetCapture();
1979     ok(capture == 0, "GetCapture() = %p\n", capture);
1980
1981     button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1982     assert(button);
1983     trace("button %p\n", button);
1984
1985     old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
1986
1987     SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
1988
1989     DestroyWindow(button);
1990 }
1991
1992 static void test_capture_2(void)
1993 {
1994     HWND button, hwnd, capture;
1995
1996     check_wnd_state(0, 0, 0, 0);
1997
1998     button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
1999     assert(button);
2000     trace("button %p\n", button);
2001
2002     check_wnd_state(button, button, button, 0);
2003
2004     capture = SetCapture(button);
2005     ok(capture == 0, "SetCapture() = %p\n", capture);
2006
2007     check_wnd_state(button, button, button, button);
2008
2009     /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2010      * internal button state.
2011      */
2012     SendMessage(button, WM_KILLFOCUS, 0, 0);
2013     check_wnd_state(button, button, button, button);
2014
2015     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2016     assert(hwnd);
2017     trace("hwnd %p\n", hwnd);
2018
2019     check_wnd_state(button, button, button, button);
2020
2021     ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2022
2023     check_wnd_state(button, button, button, button);
2024
2025     DestroyWindow(hwnd);
2026
2027     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2028     assert(hwnd);
2029     trace("hwnd %p\n", hwnd);
2030
2031     check_wnd_state(button, button, button, button);
2032
2033     ShowWindow(hwnd, SW_SHOW);
2034
2035     check_wnd_state(hwnd, hwnd, hwnd, button);
2036
2037     capture = SetCapture(hwnd);
2038     ok(capture == button, "SetCapture() = %p\n", capture);
2039
2040     check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2041
2042     DestroyWindow(hwnd);
2043     check_wnd_state(button, button, button, 0);
2044
2045     DestroyWindow(button);
2046     check_wnd_state(0, 0, 0, 0);
2047 }
2048
2049 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2050 {
2051     ShowWindow(hwnd1, SW_HIDE);
2052     ShowWindow(hwnd2, SW_HIDE);
2053
2054     ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2055     ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2056
2057     SetCapture(hwnd1);
2058     check_wnd_state(0, 0, 0, hwnd1);
2059
2060     SetCapture(hwnd2);
2061     check_wnd_state(0, 0, 0, hwnd2);
2062
2063     ShowWindow(hwnd1, SW_SHOW);
2064     check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2065
2066     ReleaseCapture();
2067 }
2068
2069 static void test_keyboard_input(HWND hwnd)
2070 {
2071     MSG msg;
2072     BOOL ret;
2073
2074     ShowWindow(hwnd, SW_SHOW);
2075     UpdateWindow(hwnd);
2076
2077     ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2078
2079     SetFocus(hwnd);
2080     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2081
2082     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2083
2084     PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2085     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2086     ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2087     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2088     ok( !ret, "message %04x available\n", msg.message);
2089
2090     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2091
2092     PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2093     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2094     ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2095     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2096     ok( !ret, "message %04x available\n", msg.message);
2097
2098     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2099
2100     keybd_event(VK_SPACE, 0, 0, 0);
2101     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2102     ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2103     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2104     ok( !ret, "message %04x available\n", msg.message);
2105
2106     SetFocus(0);
2107     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2108
2109     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2110
2111     PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2112     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2113     ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2114     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2115     ok( !ret, "message %04x available\n", msg.message);
2116
2117     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2118
2119     PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2120     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2121     ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2122     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2123     ok( !ret, "message %04x available\n", msg.message);
2124
2125     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2126
2127     keybd_event(VK_SPACE, 0, 0, 0);
2128     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2129     ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2130     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2131     ok( !ret, "message %04x available\n", msg.message);
2132 }
2133
2134 static void test_mouse_input(HWND hwnd)
2135 {
2136     RECT rc;
2137     POINT pt;
2138     int x, y;
2139     HWND popup;
2140     MSG msg;
2141     BOOL ret;
2142
2143     ShowWindow(hwnd, SW_SHOW);
2144     UpdateWindow(hwnd);
2145
2146     GetWindowRect(hwnd, &rc);
2147     trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2148
2149     popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2150                             rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2151                             hwnd, 0, 0, NULL);
2152     assert(popup != 0);
2153     ShowWindow(popup, SW_SHOW);
2154     UpdateWindow(popup);
2155
2156     GetWindowRect(popup, &rc);
2157     trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2158
2159     x = rc.left + (rc.right - rc.left) / 2;
2160     y = rc.top + (rc.bottom - rc.top) / 2;
2161     trace("setting cursor to (%d,%d)\n", x, y);
2162
2163     SetCursorPos(x, y);
2164     GetCursorPos(&pt);
2165     ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2166
2167     /* force the system to update its internal queue mouse position,
2168      * otherwise it won't generate relative mouse movements below.
2169      */
2170     mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2171     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2172
2173     msg.message = 0;
2174     mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2175     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2176     ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2177     /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2178     if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2179         ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2180     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2181     ok( !ret, "message %04x available\n", msg.message);
2182
2183     mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2184     ShowWindow(popup, SW_HIDE);
2185     ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2186     ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2187     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2188
2189     mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2190     ShowWindow(hwnd, SW_HIDE);
2191     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2192     ok( !ret, "message %04x available\n", msg.message);
2193
2194     DestroyWindow(popup);
2195 }
2196
2197 START_TEST(win)
2198 {
2199     pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2200     pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2201
2202     hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
2203     if (hwndMain)
2204     {
2205         ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
2206         if (pGetAncestor)
2207         {
2208             hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
2209             ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2210             trace("hwndMessage %p\n", hwndMessage);
2211         }
2212         DestroyWindow(hwndMain);
2213     }
2214     else
2215         trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2216
2217     if (!RegisterWindowClasses()) assert(0);
2218
2219     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
2220     assert(hhook);
2221
2222     hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2223                                WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2224                                WS_MAXIMIZEBOX | WS_POPUP,
2225                                100, 100, 200, 200,
2226                                0, 0, 0, NULL);
2227     hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2228                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2229                                 WS_MAXIMIZEBOX | WS_POPUP,
2230                                 100, 100, 200, 200,
2231                                 0, 0, 0, NULL);
2232     assert( hwndMain );
2233     assert( hwndMain2 );
2234
2235     test_capture_1();
2236     test_capture_2();
2237     test_capture_3(hwndMain, hwndMain2);
2238
2239     test_parent_owner();
2240     test_shell_window();
2241
2242     test_mdi();
2243     test_icons();
2244     test_SetWindowPos(hwndMain);
2245     test_SetMenu(hwndMain);
2246     test_SetFocus(hwndMain);
2247     test_SetActiveWindow(hwndMain);
2248
2249     test_children_zorder(hwndMain);
2250     test_keyboard_input(hwndMain);
2251     test_mouse_input(hwndMain);
2252
2253     UnhookWindowsHookEx(hhook);
2254 }