quartz: Use proper alloc/free functions for COM objects.
[wine] / dlls / user32 / tests / msg.c
1 /*
2  * Unit tests for window message handling
3  *
4  * Copyright 1999 Ove Kaaven
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2004, 2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42
43 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
44
45 #ifndef WM_SYSTIMER
46 #define WM_SYSTIMER         0x0118
47 #endif
48
49 #define WND_PARENT_ID           1
50 #define WND_POPUP_ID            2
51 #define WND_CHILD_ID            3
52
53 static BOOL test_DestroyWindow_flag;
54 static HWINEVENTHOOK hEvent_hook;
55
56 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
57
58 static void dump_winpos_flags(UINT flags);
59
60 /*
61 FIXME: add tests for these
62 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
63  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
64  WS_THICKFRAME: thick border
65  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
66  WS_BORDER (default for overlapped windows): single black border
67  none (default for child (and popup?) windows): no border
68 */
69
70 typedef enum {
71     sent=0x1,
72     posted=0x2,
73     parent=0x4,
74     wparam=0x8,
75     lparam=0x10,
76     defwinproc=0x20,
77     beginpaint=0x40,
78     optional=0x80,
79     hook=0x100,
80     winevent_hook=0x200
81 } msg_flags_t;
82
83 struct message {
84     UINT message;          /* the WM_* code */
85     msg_flags_t flags;     /* message props */
86     WPARAM wParam;         /* expected value of wParam */
87     LPARAM lParam;         /* expected value of lParam */
88 };
89
90 /* Empty message sequence */
91 static const struct message WmEmptySeq[] =
92 {
93     { 0 }
94 };
95 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
96 static const struct message WmCreateOverlappedSeq[] = {
97     { HCBT_CREATEWND, hook },
98     { WM_GETMINMAXINFO, sent },
99     { WM_NCCREATE, sent },
100     { WM_NCCALCSIZE, sent|wparam, 0 },
101     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
102     { WM_CREATE, sent },
103     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
104     { 0 }
105 };
106 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
107  * for a not visible overlapped window.
108  */
109 static const struct message WmSWP_ShowOverlappedSeq[] = {
110     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
111     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
112     { WM_NCPAINT, sent|wparam|optional, 1 },
113     { WM_GETTEXT, sent|defwinproc|optional },
114     { WM_ERASEBKGND, sent|optional },
115     { HCBT_ACTIVATE, hook },
116     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
117     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
118     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
119     { WM_ACTIVATEAPP, sent|wparam, 1 },
120     { WM_NCACTIVATE, sent|wparam, 1 },
121     { WM_GETTEXT, sent|defwinproc|optional },
122     { WM_ACTIVATE, sent|wparam, 1 },
123     { HCBT_SETFOCUS, hook },
124     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
125     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
126     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
127     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
128     { WM_NCPAINT, sent|wparam|optional, 1 },
129     { WM_GETTEXT, sent|defwinproc|optional },
130     { WM_ERASEBKGND, sent|optional },
131     /* Win9x adds SWP_NOZORDER below */
132     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
133     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
134     { WM_NCPAINT, sent|wparam|optional, 1 },
135     { WM_ERASEBKGND, sent|optional },
136     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
137     { 0 }
138 };
139 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
140  * for a visible overlapped window.
141  */
142 static const struct message WmSWP_HideOverlappedSeq[] = {
143     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
144     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
145     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
146     { 0 }
147 };
148
149 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
150  * for a visible overlapped window.
151  */
152 static const struct message WmSWP_ResizeSeq[] = {
153     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
154     { WM_GETMINMAXINFO, sent|defwinproc },
155     { WM_NCCALCSIZE, sent|wparam, TRUE },
156     { WM_NCPAINT, sent|optional },
157     { WM_GETTEXT, sent|defwinproc|optional },
158     { WM_ERASEBKGND, sent|optional },
159     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
160     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
161     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
162     { WM_NCPAINT, sent|optional },
163     { WM_GETTEXT, sent|defwinproc|optional },
164     { WM_ERASEBKGND, sent|optional },
165     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
166     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
167     { 0 }
168 };
169
170 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
171  * for a visible popup window.
172  */
173 static const struct message WmSWP_ResizePopupSeq[] = {
174     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
175     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
176     { WM_NCCALCSIZE, sent|wparam, TRUE },
177     { WM_NCPAINT, sent|optional },
178     { WM_GETTEXT, sent|defwinproc|optional },
179     { WM_ERASEBKGND, sent|optional },
180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
181     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
182     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
183     { WM_NCPAINT, sent|optional },
184     { WM_GETTEXT, sent|defwinproc|optional },
185     { WM_ERASEBKGND, sent|optional },
186     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
187     { 0 }
188 };
189
190 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
191  * for a visible overlapped window.
192  */
193 static const struct message WmSWP_MoveSeq[] = {
194     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
195     { WM_NCPAINT, sent|optional },
196     { WM_GETTEXT, sent|defwinproc|optional },
197     { WM_ERASEBKGND, sent|optional },
198     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
199     { WM_MOVE, sent|defwinproc|wparam, 0 },
200     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
201     { 0 }
202 };
203
204 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
205                 SWP_NOZORDER|SWP_FRAMECHANGED)
206  * for a visible overlapped window with WS_CLIPCHILDREN style set.
207  */
208 static const struct message WmSWP_FrameChanged_clip[] = {
209     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
210     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
211     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
212     { WM_GETTEXT, sent|parent|defwinproc|optional },
213     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
214     { WM_NCPAINT, sent }, /* wparam != 1 */
215     { WM_ERASEBKGND, sent },
216     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
217     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
218     { WM_PAINT, sent },
219     { 0 }
220 };
221 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
222                 SWP_NOZORDER|SWP_FRAMECHANGED)
223  * for a visible overlapped window.
224  */
225 static const struct message WmSWP_FrameChangedDeferErase[] = {
226     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
227     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
228     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
229     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
230     { WM_PAINT, sent|parent },
231     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
232     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
233     { WM_PAINT, sent },
234     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
235     { WM_ERASEBKGND, sent|beginpaint },
236     { 0 }
237 };
238
239 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
240                 SWP_NOZORDER|SWP_FRAMECHANGED)
241  * for a visible overlapped window without WS_CLIPCHILDREN style set.
242  */
243 static const struct message WmSWP_FrameChanged_noclip[] = {
244     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
245     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
246     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
247     { WM_GETTEXT, sent|parent|defwinproc|optional },
248     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
249     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
250     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
251     { WM_PAINT, sent },
252     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
253     { WM_ERASEBKGND, sent|beginpaint },
254     { 0 }
255 };
256
257 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
258 static const struct message WmShowOverlappedSeq[] = {
259     { WM_SHOWWINDOW, sent|wparam, 1 },
260     { WM_NCPAINT, sent|wparam|optional, 1 },
261     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
262     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
263     { WM_NCPAINT, sent|wparam|optional, 1 },
264     { WM_GETTEXT, sent|defwinproc|optional },
265     { WM_ERASEBKGND, sent|optional },
266     { HCBT_ACTIVATE, hook },
267     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
268     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
269     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
270     { WM_NCPAINT, sent|wparam|optional, 1 },
271     { WM_ACTIVATEAPP, sent|wparam, 1 },
272     { WM_NCACTIVATE, sent|wparam, 1 },
273     { WM_GETTEXT, sent|defwinproc|optional },
274     { WM_ACTIVATE, sent|wparam, 1 },
275     { HCBT_SETFOCUS, hook },
276     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
277     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
278     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
279     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
280     { WM_NCPAINT, sent|wparam|optional, 1 },
281     { WM_GETTEXT, sent|defwinproc|optional },
282     { WM_ERASEBKGND, sent|optional },
283     /* Win9x adds SWP_NOZORDER below */
284     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
285     { WM_NCCALCSIZE, sent|optional },
286     { WM_NCPAINT, sent|optional },
287     { WM_ERASEBKGND, sent|optional },
288 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
289        * messages. Does that mean that CreateWindow doesn't set initial
290        * window dimensions for overlapped windows?
291        */
292     { WM_SIZE, sent },
293     { WM_MOVE, sent },
294 #endif
295     { 0 }
296 };
297 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
298 static const struct message WmShowMaxOverlappedSeq[] = {
299     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
300     { WM_GETMINMAXINFO, sent },
301     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
302     { WM_GETMINMAXINFO, sent|defwinproc },
303     { WM_NCCALCSIZE, sent|wparam, TRUE },
304     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
305     { HCBT_ACTIVATE, hook },
306     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
307     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
308     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
309     { WM_ACTIVATEAPP, sent|wparam, 1 },
310     { WM_NCACTIVATE, sent|wparam, 1 },
311     { WM_GETTEXT, sent|defwinproc|optional },
312     { WM_ACTIVATE, sent|wparam, 1 },
313     { HCBT_SETFOCUS, hook },
314     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
315     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
316     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
317     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
318     { WM_NCPAINT, sent|wparam|optional, 1 },
319     { WM_GETTEXT, sent|defwinproc|optional },
320     { WM_ERASEBKGND, sent|optional },
321     /* Win9x adds SWP_NOZORDER below */
322     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
323     { WM_MOVE, sent|defwinproc },
324     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
325     { WM_NCCALCSIZE, sent|optional },
326     { WM_NCPAINT, sent|optional },
327     { WM_ERASEBKGND, sent|optional },
328     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
329     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
330     { 0 }
331 };
332 /* ShowWindow(SW_HIDE) for a visible overlapped window */
333 static const struct message WmHideOverlappedSeq[] = {
334     { WM_SHOWWINDOW, sent|wparam, 0 },
335     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
336     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
337     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
338     { WM_SIZE, sent|optional }, /* XP doesn't send it */
339     { WM_MOVE, sent|optional }, /* XP doesn't send it */
340     { WM_NCACTIVATE, sent|wparam, 0 },
341     { WM_ACTIVATE, sent|wparam, 0 },
342     { WM_ACTIVATEAPP, sent|wparam, 0 },
343     { WM_KILLFOCUS, sent|wparam, 0 },
344     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
345     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
346     { 0 }
347 };
348 /* DestroyWindow for a visible overlapped window */
349 static const struct message WmDestroyOverlappedSeq[] = {
350     { HCBT_DESTROYWND, hook },
351     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
352     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
354     { WM_NCACTIVATE, sent|wparam, 0 },
355     { WM_ACTIVATE, sent|wparam, 0 },
356     { WM_ACTIVATEAPP, sent|wparam, 0 },
357     { WM_KILLFOCUS, sent|wparam, 0 },
358     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
359     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
360     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
361     { WM_DESTROY, sent },
362     { WM_NCDESTROY, sent },
363     { 0 }
364 };
365 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
366 static const struct message WmCreateMaxPopupSeq[] = {
367     { HCBT_CREATEWND, hook },
368     { WM_NCCREATE, sent },
369     { WM_NCCALCSIZE, sent|wparam, 0 },
370     { WM_CREATE, sent },
371     { WM_SIZE, sent|wparam, SIZE_RESTORED },
372     { WM_MOVE, sent },
373     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
374     { WM_GETMINMAXINFO, sent },
375     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
376     { WM_NCCALCSIZE, sent|wparam, TRUE },
377     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
378     { WM_MOVE, sent|defwinproc },
379     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
380     { WM_SHOWWINDOW, sent|wparam, 1 },
381     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
382     { HCBT_ACTIVATE, hook },
383     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
384     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
385     { WM_ACTIVATEAPP, sent|wparam, 1 },
386     { WM_NCACTIVATE, sent|wparam, 1 },
387     { WM_ACTIVATE, sent|wparam, 1 },
388     { HCBT_SETFOCUS, hook },
389     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
390     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
391     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
392     { WM_SYNCPAINT, sent|wparam|optional, 4 },
393     { WM_NCPAINT, sent|wparam|optional, 1 },
394     { WM_ERASEBKGND, sent|optional },
395     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
396     { 0 }
397 };
398 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
399 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
400     { HCBT_CREATEWND, hook },
401     { WM_NCCREATE, sent },
402     { WM_NCCALCSIZE, sent|wparam, 0 },
403     { WM_CREATE, sent },
404     { WM_SIZE, sent|wparam, SIZE_RESTORED },
405     { WM_MOVE, sent },
406     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
407     { WM_GETMINMAXINFO, sent },
408     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
409     { WM_NCCALCSIZE, sent|wparam, TRUE },
410     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
411     { WM_MOVE, sent|defwinproc },
412     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
413     { 0 }
414 };
415 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
416 static const struct message WmShowMaxPopupResizedSeq[] = {
417     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
418     { WM_GETMINMAXINFO, sent },
419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
420     { WM_NCCALCSIZE, sent|wparam, TRUE },
421     { HCBT_ACTIVATE, hook },
422     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
423     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
424     { WM_ACTIVATEAPP, sent|wparam, 1 },
425     { WM_NCACTIVATE, sent|wparam, 1 },
426     { WM_ACTIVATE, sent|wparam, 1 },
427     { HCBT_SETFOCUS, hook },
428     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
429     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
430     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
431     { WM_NCPAINT, sent|wparam|optional, 1 },
432     { WM_ERASEBKGND, sent|optional },
433     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
434     /* WinNT4.0 sends WM_MOVE */
435     { WM_MOVE, sent|defwinproc|optional },
436     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
437     { 0 }
438 };
439 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
440 static const struct message WmShowMaxPopupSeq[] = {
441     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
442     { WM_GETMINMAXINFO, sent },
443     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
444     { WM_NCCALCSIZE, sent|wparam, TRUE },
445     { HCBT_ACTIVATE, hook },
446     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
447     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
448     { WM_ACTIVATEAPP, sent|wparam, 1 },
449     { WM_NCACTIVATE, sent|wparam, 1 },
450     { WM_ACTIVATE, sent|wparam, 1 },
451     { HCBT_SETFOCUS, hook },
452     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
453     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
454     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
455     { WM_SYNCPAINT, sent|wparam|optional, 4 },
456     { WM_NCPAINT, sent|wparam|optional, 1 },
457     { WM_ERASEBKGND, sent|optional },
458     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
459     { 0 }
460 };
461 /* CreateWindow(WS_VISIBLE) for popup window */
462 static const struct message WmCreatePopupSeq[] = {
463     { HCBT_CREATEWND, hook },
464     { WM_NCCREATE, sent },
465     { WM_NCCALCSIZE, sent|wparam, 0 },
466     { WM_CREATE, sent },
467     { WM_SIZE, sent|wparam, SIZE_RESTORED },
468     { WM_MOVE, sent },
469     { WM_SHOWWINDOW, sent|wparam, 1 },
470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
471     { HCBT_ACTIVATE, hook },
472     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
473     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
474     { WM_NCPAINT, sent|wparam|optional, 1 },
475     { WM_ERASEBKGND, sent|optional },
476     { WM_ACTIVATEAPP, sent|wparam, 1 },
477     { WM_NCACTIVATE, sent|wparam, 1 },
478     { WM_ACTIVATE, sent|wparam, 1 },
479     { HCBT_SETFOCUS, hook },
480     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
481     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
482     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
483     { WM_SYNCPAINT, sent|wparam|optional, 4 },
484     { WM_NCPAINT, sent|wparam|optional, 1 },
485     { WM_ERASEBKGND, sent|optional },
486     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
487     { 0 }
488 };
489 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
490 static const struct message WmShowVisMaxPopupSeq[] = {
491     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
492     { WM_GETMINMAXINFO, sent },
493     { WM_GETTEXT, sent|optional },
494     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
495     { WM_NCCALCSIZE, sent|wparam, TRUE },
496     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
497     { WM_NCPAINT, sent|wparam|optional, 1 },
498     { WM_ERASEBKGND, sent|optional },
499     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
500     { WM_MOVE, sent|defwinproc },
501     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
502     { 0 }
503 };
504 /* CreateWindow (for a child popup window, not initially visible) */
505 static const struct message WmCreateChildPopupSeq[] = {
506     { HCBT_CREATEWND, hook },
507     { WM_NCCREATE, sent }, 
508     { WM_NCCALCSIZE, sent|wparam, 0 },
509     { WM_CREATE, sent },
510     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
511     { WM_SIZE, sent|wparam, SIZE_RESTORED },
512     { WM_MOVE, sent },
513     { 0 }
514 };
515 /* CreateWindow (for a popup window, not initially visible,
516  * which sets WS_VISIBLE in WM_CREATE handler)
517  */
518 static const struct message WmCreateInvisiblePopupSeq[] = {
519     { HCBT_CREATEWND, hook },
520     { WM_NCCREATE, sent }, 
521     { WM_NCCALCSIZE, sent|wparam, 0 },
522     { WM_CREATE, sent },
523     { WM_STYLECHANGING, sent },
524     { WM_STYLECHANGED, sent },
525     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
526     { WM_SIZE, sent|wparam, SIZE_RESTORED },
527     { WM_MOVE, sent },
528     { 0 }
529 };
530 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
531  * for a popup window with WS_VISIBLE style set
532  */
533 static const struct message WmShowVisiblePopupSeq_2[] = {
534     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
535     { 0 }
536 };
537 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
538  * for a popup window with WS_VISIBLE style set
539  */
540 static const struct message WmShowVisiblePopupSeq_3[] = {
541     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
542     { HCBT_ACTIVATE, hook },
543     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
544     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
545     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
546     { WM_NCACTIVATE, sent|wparam, 1 },
547     { WM_ACTIVATE, sent|wparam, 1 },
548     { HCBT_SETFOCUS, hook },
549     { WM_KILLFOCUS, sent|parent },
550     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
551     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
552     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
553     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
554     { WM_SETFOCUS, sent|defwinproc },
555     { 0 }
556 };
557 /* CreateWindow (for child window, not initially visible) */
558 static const struct message WmCreateChildSeq[] = {
559     { HCBT_CREATEWND, hook },
560     { WM_NCCREATE, sent }, 
561     /* child is inserted into parent's child list after WM_NCCREATE returns */
562     { WM_NCCALCSIZE, sent|wparam, 0 },
563     { WM_CREATE, sent },
564     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
565     { WM_SIZE, sent|wparam, SIZE_RESTORED },
566     { WM_MOVE, sent },
567     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
568     { 0 }
569 };
570 /* CreateWindow (for maximized child window, not initially visible) */
571 static const struct message WmCreateMaximizedChildSeq[] = {
572     { HCBT_CREATEWND, hook },
573     { WM_NCCREATE, sent }, 
574     { WM_NCCALCSIZE, sent|wparam, 0 },
575     { WM_CREATE, sent },
576     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
577     { WM_SIZE, sent|wparam, SIZE_RESTORED },
578     { WM_MOVE, sent },
579     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
580     { WM_GETMINMAXINFO, sent },
581     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
582     { WM_NCCALCSIZE, sent|wparam, 1 },
583     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
584     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
585     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
586     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
587     { 0 }
588 };
589 /* CreateWindow (for a child window, initially visible) */
590 static const struct message WmCreateVisibleChildSeq[] = {
591     { HCBT_CREATEWND, hook },
592     { WM_NCCREATE, sent }, 
593     /* child is inserted into parent's child list after WM_NCCREATE returns */
594     { WM_NCCALCSIZE, sent|wparam, 0 },
595     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
596     { WM_CREATE, sent },
597     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
598     { WM_SIZE, sent|wparam, SIZE_RESTORED },
599     { WM_MOVE, sent },
600     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
601     { WM_SHOWWINDOW, sent|wparam, 1 },
602     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
603     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
604     { WM_ERASEBKGND, sent|parent|optional },
605     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
606     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
607     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
608     { 0 }
609 };
610 /* ShowWindow(SW_SHOW) for a not visible child window */
611 static const struct message WmShowChildSeq[] = {
612     { WM_SHOWWINDOW, sent|wparam, 1 },
613     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
614     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
615     { WM_ERASEBKGND, sent|parent|optional },
616     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
617     { 0 }
618 };
619 /* ShowWindow(SW_HIDE) for a visible child window */
620 static const struct message WmHideChildSeq[] = {
621     { WM_SHOWWINDOW, sent|wparam, 0 },
622     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
623     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
624     { WM_ERASEBKGND, sent|parent|optional },
625     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
626     { 0 }
627 };
628 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
629  * for a not visible child window
630  */
631 static const struct message WmShowChildSeq_2[] = {
632     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
633     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
634     { WM_CHILDACTIVATE, sent },
635     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
636     { 0 }
637 };
638 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
639  * for a not visible child window
640  */
641 static const struct message WmShowChildSeq_3[] = {
642     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
643     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
644     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
645     { 0 }
646 };
647 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
648  * for a visible child window with a caption
649  */
650 static const struct message WmShowChildSeq_4[] = {
651     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
652     { WM_CHILDACTIVATE, sent },
653     { 0 }
654 };
655 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
656 static const struct message WmShowChildInvisibleParentSeq_1[] = {
657     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
658     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
659     { WM_NCCALCSIZE, sent|wparam, 1 },
660     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
661     { WM_MOVE, sent|defwinproc },
662     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
663     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
664     /* FIXME: Wine creates an icon/title window while Windows doesn't */
665     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
666     { WM_GETTEXT, sent|optional },
667     { 0 }
668 };
669 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
670 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
671     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
672     { 0 }
673 };
674 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
675 static const struct message WmShowChildInvisibleParentSeq_2[] = {
676     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
677     { WM_GETMINMAXINFO, sent },
678     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
679     { WM_NCCALCSIZE, sent|wparam, 1 },
680     { WM_CHILDACTIVATE, sent },
681     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
682     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
683     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
684     { 0 }
685 };
686 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
687 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
688     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
689     { 0 }
690 };
691 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
692 static const struct message WmShowChildInvisibleParentSeq_3[] = {
693     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
694     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
695     { WM_NCCALCSIZE, sent|wparam, 1 },
696     { WM_CHILDACTIVATE, sent },
697     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
698     { WM_MOVE, sent|defwinproc },
699     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
701     /* FIXME: Wine creates an icon/title window while Windows doesn't */
702     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
703     { WM_GETTEXT, sent|optional },
704     { 0 }
705 };
706 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
707 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
708     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
709     { 0 }
710 };
711 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
712 static const struct message WmShowChildInvisibleParentSeq_4[] = {
713     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
714     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
715     { WM_NCCALCSIZE, sent|wparam, 1 },
716     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
717     { WM_MOVE, sent|defwinproc },
718     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
719     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
720     /* FIXME: Wine creates an icon/title window while Windows doesn't */
721     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
722     { WM_GETTEXT, sent|optional },
723     { 0 }
724 };
725 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
726 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
727     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
728     { 0 }
729 };
730 /* ShowWindow(SW_SHOW) for child with invisible parent */
731 static const struct message WmShowChildInvisibleParentSeq_5[] = {
732     { WM_SHOWWINDOW, sent|wparam, 1 },
733     { 0 }
734 };
735 /* ShowWindow(SW_HIDE) for child with invisible parent */
736 static const struct message WmHideChildInvisibleParentSeq[] = {
737     { WM_SHOWWINDOW, sent|wparam, 0 },
738     { 0 }
739 };
740 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
741 static const struct message WmShowChildInvisibleParentSeq_6[] = {
742     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
743     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
744     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
745     { 0 }
746 };
747 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
748 static const struct message WmHideChildInvisibleParentSeq_2[] = {
749     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
750     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
751     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
752     { 0 }
753 };
754 /* DestroyWindow for a visible child window */
755 static const struct message WmDestroyChildSeq[] = {
756     { HCBT_DESTROYWND, hook },
757     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
758     { WM_SHOWWINDOW, sent|wparam, 0 },
759     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
760     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
761     { WM_ERASEBKGND, sent|parent|optional },
762     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
763     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
764     { WM_KILLFOCUS, sent },
765     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
766     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
767     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
768     { WM_SETFOCUS, sent|parent },
769     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
770     { WM_DESTROY, sent },
771     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
772     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
773     { WM_NCDESTROY, sent },
774     { 0 }
775 };
776 /* DestroyWindow for a visible child window with invisible parent */
777 static const struct message WmDestroyInvisibleChildSeq[] = {
778     { HCBT_DESTROYWND, hook },
779     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
780     { WM_SHOWWINDOW, sent|wparam, 0 },
781     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
782     { WM_DESTROY, sent },
783     { WM_NCDESTROY, sent },
784     { 0 }
785 };
786 /* Moving the mouse in nonclient area */
787 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
788     { WM_NCHITTEST, sent },
789     { WM_SETCURSOR, sent },
790     { WM_NCMOUSEMOVE, posted },
791     { 0 }
792 };
793 /* Moving the mouse in client area */
794 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
795     { WM_NCHITTEST, sent },
796     { WM_SETCURSOR, sent },
797     { WM_MOUSEMOVE, posted },
798     { 0 }
799 };
800 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
801 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
802     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
803     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
804     { WM_GETMINMAXINFO, sent|defwinproc },
805     { WM_ENTERSIZEMOVE, sent|defwinproc },
806     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
807     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
808     { WM_MOVE, sent|defwinproc },
809     { WM_EXITSIZEMOVE, sent|defwinproc },
810     { 0 }
811 };
812 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
813 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
814     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
815     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
816     { WM_GETMINMAXINFO, sent|defwinproc },
817     { WM_ENTERSIZEMOVE, sent|defwinproc },
818     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
819     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
820     { WM_GETMINMAXINFO, sent|defwinproc },
821     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
822     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
823     { WM_GETTEXT, sent|defwinproc },
824     { WM_ERASEBKGND, sent|defwinproc },
825     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
826     { WM_MOVE, sent|defwinproc },
827     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
828     { WM_EXITSIZEMOVE, sent|defwinproc },
829     { 0 }
830 };
831 /* Resizing child window with MoveWindow (32) */
832 static const struct message WmResizingChildWithMoveWindowSeq[] = {
833     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
834     { WM_NCCALCSIZE, sent|wparam, 1 },
835     { WM_ERASEBKGND, sent|optional },
836     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
837     { WM_MOVE, sent|defwinproc },
838     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
839     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
840     { 0 }
841 };
842 /* Clicking on inactive button */
843 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
844     { WM_NCHITTEST, sent },
845     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
846     { WM_MOUSEACTIVATE, sent },
847     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
848     { WM_SETCURSOR, sent },
849     { WM_SETCURSOR, sent|parent|defwinproc },
850     { WM_LBUTTONDOWN, posted },
851     { WM_KILLFOCUS, posted|parent },
852     { WM_SETFOCUS, posted },
853     { WM_CTLCOLORBTN, posted|parent },
854     { BM_SETSTATE, posted },
855     { WM_CTLCOLORBTN, posted|parent },
856     { WM_LBUTTONUP, posted },
857     { BM_SETSTATE, posted },
858     { WM_CTLCOLORBTN, posted|parent },
859     { WM_COMMAND, posted|parent },
860     { 0 }
861 };
862 /* Reparenting a button (16/32) */
863 /* The last child (button) reparented gets topmost for its new parent. */
864 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
865     { WM_SHOWWINDOW, sent|wparam, 0 },
866     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
867     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
868     { WM_ERASEBKGND, sent|parent },
869     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
870     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
871     { WM_CHILDACTIVATE, sent },
872     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
873     { WM_MOVE, sent|defwinproc },
874     { WM_SHOWWINDOW, sent|wparam, 1 },
875     { 0 }
876 };
877 /* Creation of a custom dialog (32) */
878 static const struct message WmCreateCustomDialogSeq[] = {
879     { HCBT_CREATEWND, hook },
880     { WM_GETMINMAXINFO, sent },
881     { WM_NCCREATE, sent },
882     { WM_NCCALCSIZE, sent|wparam, 0 },
883     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
884     { WM_CREATE, sent },
885     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
886     { WM_SHOWWINDOW, sent|wparam, 1 },
887     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
888     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
889     { HCBT_ACTIVATE, hook },
890     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
891
892
893     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
894
895     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
896
897     { WM_NCACTIVATE, sent|wparam, 1 },
898     { WM_GETTEXT, sent|optional|defwinproc },
899     { WM_GETTEXT, sent|optional|defwinproc },
900     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
901     { WM_ACTIVATE, sent|wparam, 1 },
902     { WM_KILLFOCUS, sent|parent },
903     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
904     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
905     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
906     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
907     { WM_SETFOCUS, sent },
908     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
909     { WM_NCPAINT, sent|wparam, 1 },
910     { WM_GETTEXT, sent|optional|defwinproc },
911     { WM_GETTEXT, sent|optional|defwinproc },
912     { WM_ERASEBKGND, sent },
913     { WM_CTLCOLORDLG, sent|defwinproc },
914     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
915     { WM_GETTEXT, sent|optional },
916     { WM_GETTEXT, sent|optional },
917     { WM_NCCALCSIZE, sent|optional },
918     { WM_NCPAINT, sent|optional },
919     { WM_GETTEXT, sent|optional|defwinproc },
920     { WM_GETTEXT, sent|optional|defwinproc },
921     { WM_ERASEBKGND, sent|optional },
922     { WM_CTLCOLORDLG, sent|optional|defwinproc },
923     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
924     { WM_SIZE, sent|wparam, SIZE_RESTORED },
925     { WM_MOVE, sent },
926     { 0 }
927 };
928 /* Calling EndDialog for a custom dialog (32) */
929 static const struct message WmEndCustomDialogSeq[] = {
930     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
931     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
933     { WM_GETTEXT, sent|optional },
934     { HCBT_ACTIVATE, hook },
935     { WM_NCACTIVATE, sent|wparam, 0 },
936     { WM_GETTEXT, sent|optional|defwinproc },
937     { WM_GETTEXT, sent|optional|defwinproc },
938     { WM_ACTIVATE, sent|wparam, 0 },
939     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
940     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
941     { HCBT_SETFOCUS, hook },
942     { WM_KILLFOCUS, sent },
943     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
944     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
945     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
946     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
947     { WM_SETFOCUS, sent|parent|defwinproc },
948     { 0 }
949 };
950 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
951 static const struct message WmShowCustomDialogSeq[] = {
952     { WM_SHOWWINDOW, sent|wparam, 1 },
953     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
954     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
955     { HCBT_ACTIVATE, hook },
956     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
957
958     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
959
960     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
961     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
962     { WM_NCACTIVATE, sent|wparam, 1 },
963     { WM_ACTIVATE, sent|wparam, 1 },
964
965     { WM_KILLFOCUS, sent|parent },
966     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
967     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
968     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
969     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
970     { WM_SETFOCUS, sent },
971     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
972     { WM_NCPAINT, sent|wparam, 1 },
973     { WM_ERASEBKGND, sent },
974     { WM_CTLCOLORDLG, sent|defwinproc },
975     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
976     { 0 }
977 };
978 /* Creation and destruction of a modal dialog (32) */
979 static const struct message WmModalDialogSeq[] = {
980     { WM_CANCELMODE, sent|parent },
981     { HCBT_SETFOCUS, hook },
982     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
983     { WM_KILLFOCUS, sent|parent },
984     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
985     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
986     { WM_ENABLE, sent|parent|wparam, 0 },
987     { HCBT_CREATEWND, hook },
988     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
989     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
990     { WM_SETFONT, sent },
991     { WM_INITDIALOG, sent },
992     { WM_CHANGEUISTATE, sent|optional },
993     { WM_UPDATEUISTATE, sent|optional },
994     { WM_SHOWWINDOW, sent },
995     { HCBT_ACTIVATE, hook },
996     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
997     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
998     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
999     { WM_NCACTIVATE, sent|wparam, 1 },
1000     { WM_GETTEXT, sent|optional },
1001     { WM_ACTIVATE, sent|wparam, 1 },
1002     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1003     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1004     { WM_NCPAINT, sent },
1005     { WM_GETTEXT, sent|optional },
1006     { WM_ERASEBKGND, sent },
1007     { WM_CTLCOLORDLG, sent },
1008     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1009     { WM_GETTEXT, sent|optional },
1010     { WM_NCCALCSIZE, sent|optional },
1011     { WM_NCPAINT, sent|optional },
1012     { WM_GETTEXT, sent|optional },
1013     { WM_ERASEBKGND, sent|optional },
1014     { WM_CTLCOLORDLG, sent|optional },
1015     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1016     { WM_PAINT, sent|optional },
1017     { WM_CTLCOLORBTN, sent },
1018     { WM_ENTERIDLE, sent|parent|optional },
1019     { WM_ENTERIDLE, sent|parent|optional },
1020     { WM_ENTERIDLE, sent|parent|optional },
1021     { WM_ENTERIDLE, sent|parent|optional },
1022     { WM_ENTERIDLE, sent|parent|optional },
1023     { WM_ENTERIDLE, sent|parent|optional },
1024     { WM_ENTERIDLE, sent|parent|optional },
1025     { WM_ENTERIDLE, sent|parent|optional },
1026     { WM_ENTERIDLE, sent|parent|optional },
1027     { WM_ENTERIDLE, sent|parent|optional },
1028     { WM_ENTERIDLE, sent|parent|optional },
1029     { WM_ENTERIDLE, sent|parent|optional },
1030     { WM_ENTERIDLE, sent|parent|optional },
1031     { WM_ENTERIDLE, sent|parent|optional },
1032     { WM_ENTERIDLE, sent|parent|optional },
1033     { WM_ENTERIDLE, sent|parent|optional },
1034     { WM_ENTERIDLE, sent|parent|optional },
1035     { WM_ENTERIDLE, sent|parent|optional },
1036     { WM_ENTERIDLE, sent|parent|optional },
1037     { WM_ENTERIDLE, sent|parent|optional },
1038     { WM_TIMER, sent },
1039     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1040     { WM_ENABLE, sent|parent|wparam, 1 },
1041     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1042     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1043     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1044     { WM_GETTEXT, sent|optional },
1045     { HCBT_ACTIVATE, hook },
1046     { WM_NCACTIVATE, sent|wparam, 0 },
1047     { WM_GETTEXT, sent|optional },
1048     { WM_ACTIVATE, sent|wparam, 0 },
1049     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1050     { WM_WINDOWPOSCHANGING, sent|optional },
1051     { HCBT_SETFOCUS, hook },
1052     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1053     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1054     { WM_SETFOCUS, sent|parent|defwinproc },
1055     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1056     { HCBT_DESTROYWND, hook },
1057     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1058     { WM_DESTROY, sent },
1059     { WM_NCDESTROY, sent },
1060     { 0 }
1061 };
1062 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1063 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1064     /* (inside dialog proc, handling WM_INITDIALOG) */
1065     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1066     { WM_NCCALCSIZE, sent },
1067     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1068     { WM_GETTEXT, sent|defwinproc },
1069     { WM_ACTIVATE, sent|parent|wparam, 0 },
1070     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1071     { WM_WINDOWPOSCHANGING, sent|parent },
1072     { WM_NCACTIVATE, sent|wparam, 1 },
1073     { WM_ACTIVATE, sent|wparam, 1 },
1074     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1075     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1076     /* (setting focus) */
1077     { WM_SHOWWINDOW, sent|wparam, 1 },
1078     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1079     { WM_NCPAINT, sent },
1080     { WM_GETTEXT, sent|defwinproc },
1081     { WM_ERASEBKGND, sent },
1082     { WM_CTLCOLORDLG, sent|defwinproc },
1083     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1084     { WM_PAINT, sent },
1085     /* (bunch of WM_CTLCOLOR* for each control) */
1086     { WM_PAINT, sent|parent },
1087     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1088     { WM_SETCURSOR, sent|parent },
1089     { 0 }
1090 };
1091 /* SetMenu for NonVisible windows with size change*/
1092 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1093     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1094     { WM_NCCALCSIZE, sent|wparam, 1 },
1095     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1096     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1097     { WM_MOVE, sent|defwinproc },
1098     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1099     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1100     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1101     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1102     { WM_GETTEXT, sent|optional },
1103     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1104     { 0 }
1105 };
1106 /* SetMenu for NonVisible windows with no size change */
1107 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1108     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1109     { WM_NCCALCSIZE, sent|wparam, 1 },
1110     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1111     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1112     { 0 }
1113 };
1114 /* SetMenu for Visible windows with size change */
1115 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1116     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1117     { WM_NCCALCSIZE, sent|wparam, 1 },
1118     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1119     { WM_NCPAINT, sent }, /* wparam != 1 */
1120     { WM_GETTEXT, sent|defwinproc|optional },
1121     { WM_ERASEBKGND, sent|optional },
1122     { WM_ACTIVATE, sent|optional },
1123     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1124     { WM_MOVE, sent|defwinproc },
1125     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1126     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1127     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1128     { WM_ERASEBKGND, sent|optional },
1129     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1130     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1131     { 0 }
1132 };
1133 /* SetMenu for Visible windows with no size change */
1134 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1135     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1136     { WM_NCCALCSIZE, sent|wparam, 1 },
1137     { WM_NCPAINT, sent }, /* wparam != 1 */
1138     { WM_GETTEXT, sent|defwinproc|optional },
1139     { WM_ERASEBKGND, sent|optional },
1140     { WM_ACTIVATE, sent|optional },
1141     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1142     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1143     { 0 }
1144 };
1145 /* DrawMenuBar for a visible window */
1146 static const struct message WmDrawMenuBarSeq[] =
1147 {
1148     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1149     { WM_NCCALCSIZE, sent|wparam, 1 },
1150     { WM_NCPAINT, sent }, /* wparam != 1 */
1151     { WM_GETTEXT, sent|defwinproc|optional },
1152     { WM_ERASEBKGND, sent|optional },
1153     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1154     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1155     { 0 }
1156 };
1157
1158 static const struct message WmSetRedrawFalseSeq[] =
1159 {
1160     { WM_SETREDRAW, sent|wparam, 0 },
1161     { 0 }
1162 };
1163
1164 static const struct message WmSetRedrawTrueSeq[] =
1165 {
1166     { WM_SETREDRAW, sent|wparam, 1 },
1167     { 0 }
1168 };
1169
1170 static const struct message WmEnableWindowSeq_1[] =
1171 {
1172     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1173     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1174     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1175     { 0 }
1176 };
1177
1178 static const struct message WmEnableWindowSeq_2[] =
1179 {
1180     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1181     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1182     { 0 }
1183 };
1184
1185 static const struct message WmGetScrollRangeSeq[] =
1186 {
1187     { SBM_GETRANGE, sent },
1188     { 0 }
1189 };
1190 static const struct message WmGetScrollInfoSeq[] =
1191 {
1192     { SBM_GETSCROLLINFO, sent },
1193     { 0 }
1194 };
1195 static const struct message WmSetScrollRangeSeq[] =
1196 {
1197     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1198        sends SBM_SETSCROLLINFO.
1199      */
1200     { SBM_SETSCROLLINFO, sent },
1201     { 0 }
1202 };
1203 /* SetScrollRange for a window without a non-client area */
1204 static const struct message WmSetScrollRangeHSeq_empty[] =
1205 {
1206     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1207     { 0 }
1208 };
1209 static const struct message WmSetScrollRangeVSeq_empty[] =
1210 {
1211     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1212     { 0 }
1213 };
1214 static const struct message WmSetScrollRangeHVSeq[] =
1215 {
1216     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1217     { WM_NCCALCSIZE, sent|wparam, 1 },
1218     { WM_GETTEXT, sent|defwinproc|optional },
1219     { WM_ERASEBKGND, sent|optional },
1220     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1221     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1222     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1223     { 0 }
1224 };
1225 /* SetScrollRange for a window with a non-client area */
1226 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1227 {
1228     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1229     { WM_NCCALCSIZE, sent|wparam, 1 },
1230     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1231     { WM_NCPAINT, sent|optional },
1232     { WM_GETTEXT, sent|defwinproc|optional },
1233     { WM_GETTEXT, sent|defwinproc|optional },
1234     { WM_ERASEBKGND, sent|optional },
1235     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1236     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1237     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1238     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1239     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1240     { WM_GETTEXT, sent|optional },
1241     { WM_GETTEXT, sent|optional },
1242     { WM_GETTEXT, sent|optional },
1243     { WM_GETTEXT, sent|optional },
1244     { 0 }
1245 };
1246 /* test if we receive the right sequence of messages */
1247 /* after calling ShowWindow( SW_SHOWNA) */
1248 static const struct message WmSHOWNAChildInvisParInvis[] = {
1249     { WM_SHOWWINDOW, sent|wparam, 1 },
1250     { 0 }
1251 };
1252 static const struct message WmSHOWNAChildVisParInvis[] = {
1253     { WM_SHOWWINDOW, sent|wparam, 1 },
1254     { 0 }
1255 };
1256 static const struct message WmSHOWNAChildVisParVis[] = {
1257     { WM_SHOWWINDOW, sent|wparam, 1 },
1258     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1259     { 0 }
1260 };
1261 static const struct message WmSHOWNAChildInvisParVis[] = {
1262     { WM_SHOWWINDOW, sent|wparam, 1 },
1263     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1264     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1265     { WM_ERASEBKGND, sent|optional },
1266     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1267     { 0 }
1268 };
1269 static const struct message WmSHOWNATopVisible[] = {
1270     { WM_SHOWWINDOW, sent|wparam, 1 },
1271     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1272     { 0 }
1273 };
1274 static const struct message WmSHOWNATopInvisible[] = {
1275     { WM_SHOWWINDOW, sent|wparam, 1 },
1276     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1277     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1278     { WM_NCPAINT, sent|wparam, 1 },
1279     { WM_GETTEXT, sent|defwinproc|optional },
1280     { WM_ERASEBKGND, sent|optional },
1281     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1282     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1283     { WM_NCPAINT, sent|wparam|optional, 1 },
1284     { WM_ERASEBKGND, sent|optional },
1285     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1286     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1287     { WM_MOVE, sent },
1288     { 0 }
1289 };
1290
1291 static int after_end_dialog, test_def_id;
1292 static int sequence_cnt, sequence_size;
1293 static struct message* sequence;
1294 static int log_all_parent_messages;
1295
1296 static void add_message(const struct message *msg)
1297 {
1298     if (!sequence) 
1299     {
1300         sequence_size = 10;
1301         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1302     }
1303     if (sequence_cnt == sequence_size) 
1304     {
1305         sequence_size *= 2;
1306         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1307     }
1308     assert(sequence);
1309
1310     sequence[sequence_cnt].message = msg->message;
1311     sequence[sequence_cnt].flags = msg->flags;
1312     sequence[sequence_cnt].wParam = msg->wParam;
1313     sequence[sequence_cnt].lParam = msg->lParam;
1314
1315     sequence_cnt++;
1316 }
1317
1318 /* try to make sure pending X events have been processed before continuing */
1319 static void flush_events(void)
1320 {
1321     MSG msg;
1322     int diff = 100;
1323     DWORD time = GetTickCount() + diff;
1324
1325     while (diff > 0)
1326     {
1327         MsgWaitForMultipleObjects( 0, NULL, FALSE, diff, QS_ALLINPUT );
1328         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1329         diff = time - GetTickCount();
1330     }
1331 }
1332
1333 static void flush_sequence(void)
1334 {
1335     HeapFree(GetProcessHeap(), 0, sequence);
1336     sequence = 0;
1337     sequence_cnt = sequence_size = 0;
1338 }
1339
1340 #define ok_sequence( exp, contx, todo) \
1341         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1342
1343
1344 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1345         const char *file, int line)
1346 {
1347     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1348     const struct message *actual;
1349     int failcount = 0;
1350     
1351     add_message(&end_of_sequence);
1352
1353     actual = sequence;
1354
1355     while (expected->message && actual->message)
1356     {
1357         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1358
1359         if (expected->message == actual->message)
1360         {
1361             if (expected->flags & wparam)
1362             {
1363                 if (expected->wParam != actual->wParam && todo)
1364                 {
1365                     todo_wine {
1366                         failcount ++;
1367                         ok_( file, line) (FALSE,
1368                             "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1369                             context, expected->message, expected->wParam, actual->wParam);
1370                     }
1371                 }
1372                 else
1373                 ok_( file, line) (expected->wParam == actual->wParam,
1374                      "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1375                      context, expected->message, expected->wParam, actual->wParam);
1376             }
1377             if (expected->flags & lparam)
1378             {
1379                 if (expected->lParam != actual->lParam && todo)
1380                 {
1381                     todo_wine {
1382                         failcount ++;
1383                         ok_( file, line) (FALSE,
1384                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1385                             context, expected->message, expected->lParam, actual->lParam);
1386                     }
1387                 }
1388                 else
1389                  ok_( file, line) (expected->lParam == actual->lParam,
1390                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1391                      context, expected->message, expected->lParam, actual->lParam);
1392             }
1393             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1394             {
1395                     todo_wine {
1396                         failcount ++;
1397                         ok_( file, line) (FALSE,
1398                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1399                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1400                     }
1401             }
1402             else
1403                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1404                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1405                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1406             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1407                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1408                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1409             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1410                 "%s: the msg 0x%04x should have been %s\n",
1411                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1412             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1413                 "%s: the msg 0x%04x was expected in %s\n",
1414                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1415             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1416                 "%s: the msg 0x%04x should have been sent by a hook\n",
1417                 context, expected->message);
1418             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1419                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1420                 context, expected->message);
1421             expected++;
1422             actual++;
1423         }
1424         /* silently drop winevent messages if there is no support for them */
1425         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1426             expected++;
1427         else if (todo)
1428         {
1429             failcount++;
1430             todo_wine {
1431                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1432                     context, expected->message, actual->message);
1433             }
1434             flush_sequence();
1435             return;
1436         }
1437         else
1438         {
1439             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1440                 context, expected->message, actual->message);
1441             expected++;
1442             actual++;
1443         }
1444     }
1445
1446     /* skip all optional trailing messages */
1447     while (expected->message && ((expected->flags & optional) ||
1448             ((expected->flags & winevent_hook) && !hEvent_hook)))
1449         expected++;
1450
1451     if (todo)
1452     {
1453         todo_wine {
1454             if (expected->message || actual->message) {
1455                 failcount++;
1456                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1457                     context, expected->message, actual->message);
1458             }
1459         }
1460     }
1461     else
1462     {
1463         if (expected->message || actual->message)
1464             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1465                 context, expected->message, actual->message);
1466     }
1467     if( todo && !failcount) /* succeeded yet marked todo */
1468         todo_wine {
1469             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1470         }
1471
1472     flush_sequence();
1473 }
1474
1475 /******************************** MDI test **********************************/
1476
1477 /* CreateWindow for MDI frame window, initially visible */
1478 static const struct message WmCreateMDIframeSeq[] = {
1479     { HCBT_CREATEWND, hook },
1480     { WM_GETMINMAXINFO, sent },
1481     { WM_NCCREATE, sent },
1482     { WM_NCCALCSIZE, sent|wparam, 0 },
1483     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1484     { WM_CREATE, sent },
1485     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1486     { WM_SHOWWINDOW, sent|wparam, 1 },
1487     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1488     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1489     { HCBT_ACTIVATE, hook },
1490     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1491     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1492     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1493     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1494     { WM_NCACTIVATE, sent|wparam, 1 },
1495     { WM_GETTEXT, sent|defwinproc|optional },
1496     { WM_ACTIVATE, sent|wparam, 1 },
1497     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1498     { HCBT_SETFOCUS, hook },
1499     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1500     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1501     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1502     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1503     /* Win9x adds SWP_NOZORDER below */
1504     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1505     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1506     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1507     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1508     { WM_MOVE, sent },
1509     { 0 }
1510 };
1511 /* DestroyWindow for MDI frame window, initially visible */
1512 static const struct message WmDestroyMDIframeSeq[] = {
1513     { HCBT_DESTROYWND, hook },
1514     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1515     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1516     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1517     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1518     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1519     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1520     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1521     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1522     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1523     { WM_DESTROY, sent },
1524     { WM_NCDESTROY, sent },
1525     { 0 }
1526 };
1527 /* CreateWindow for MDI client window, initially visible */
1528 static const struct message WmCreateMDIclientSeq[] = {
1529     { HCBT_CREATEWND, hook },
1530     { WM_NCCREATE, sent },
1531     { WM_NCCALCSIZE, sent|wparam, 0 },
1532     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1533     { WM_CREATE, sent },
1534     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1535     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1536     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1537     { WM_MOVE, sent },
1538     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1539     { WM_SHOWWINDOW, sent|wparam, 1 },
1540     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1541     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1542     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1543     { 0 }
1544 };
1545 /* ShowWindow(SW_SHOW) for MDI client window */
1546 static const struct message WmShowMDIclientSeq[] = {
1547     { WM_SHOWWINDOW, sent|wparam, 1 },
1548     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1549     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1550     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1551     { 0 }
1552 };
1553 /* ShowWindow(SW_HIDE) for MDI client window */
1554 static const struct message WmHideMDIclientSeq[] = {
1555     { WM_SHOWWINDOW, sent|wparam, 0 },
1556     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1557     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1558     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1559     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1560     { 0 }
1561 };
1562 /* DestroyWindow for MDI client window, initially visible */
1563 static const struct message WmDestroyMDIclientSeq[] = {
1564     { HCBT_DESTROYWND, hook },
1565     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1566     { WM_SHOWWINDOW, sent|wparam, 0 },
1567     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1568     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1569     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1570     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1571     { WM_DESTROY, sent },
1572     { WM_NCDESTROY, sent },
1573     { 0 }
1574 };
1575 /* CreateWindow for MDI child window, initially visible */
1576 static const struct message WmCreateMDIchildVisibleSeq[] = {
1577     { HCBT_CREATEWND, hook },
1578     { WM_NCCREATE, sent }, 
1579     { WM_NCCALCSIZE, sent|wparam, 0 },
1580     { WM_CREATE, sent },
1581     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1582     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1583     { WM_MOVE, sent },
1584     /* Win2k sends wparam set to
1585      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1586      * while Win9x doesn't bother to set child window id according to
1587      * CLIENTCREATESTRUCT.idFirstChild
1588      */
1589     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1590     { WM_SHOWWINDOW, sent|wparam, 1 },
1591     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1592     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1593     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1594     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1595     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1596     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1597     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1598
1599     /* Win9x: message sequence terminates here. */
1600
1601     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1602     { HCBT_SETFOCUS, hook }, /* in MDI client */
1603     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1604     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1605     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1606     { WM_SETFOCUS, sent }, /* in MDI client */
1607     { HCBT_SETFOCUS, hook },
1608     { WM_KILLFOCUS, sent }, /* in MDI client */
1609     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1610     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1611     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1612     { WM_SETFOCUS, sent|defwinproc },
1613     { WM_MDIACTIVATE, sent|defwinproc },
1614     { 0 }
1615 };
1616 /* CreateWindow for MDI child window with invisible parent */
1617 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1618     { HCBT_CREATEWND, hook },
1619     { WM_GETMINMAXINFO, sent },
1620     { WM_NCCREATE, sent }, 
1621     { WM_NCCALCSIZE, sent|wparam, 0 },
1622     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1623     { WM_CREATE, sent },
1624     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1625     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1626     { WM_MOVE, sent },
1627     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1628     { WM_SHOWWINDOW, sent|wparam, 1 },
1629     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1630     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1631     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1632     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1633
1634     /* Win9x: message sequence terminates here. */
1635
1636     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1637     { HCBT_SETFOCUS, hook }, /* in MDI client */
1638     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1639     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1640     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1641     { WM_SETFOCUS, sent }, /* in MDI client */
1642     { HCBT_SETFOCUS, hook },
1643     { WM_KILLFOCUS, sent }, /* in MDI client */
1644     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1645     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1646     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1647     { WM_SETFOCUS, sent|defwinproc },
1648     { WM_MDIACTIVATE, sent|defwinproc },
1649     { 0 }
1650 };
1651 /* DestroyWindow for MDI child window, initially visible */
1652 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1653     { HCBT_DESTROYWND, hook },
1654     /* Win2k sends wparam set to
1655      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1656      * while Win9x doesn't bother to set child window id according to
1657      * CLIENTCREATESTRUCT.idFirstChild
1658      */
1659     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1660     { WM_SHOWWINDOW, sent|wparam, 0 },
1661     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1662     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1663     { WM_ERASEBKGND, sent|parent|optional },
1664     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1665
1666     /* { WM_DESTROY, sent }
1667      * Win9x: message sequence terminates here.
1668      */
1669
1670     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1671     { WM_KILLFOCUS, sent },
1672     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1673     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1674     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1675     { WM_SETFOCUS, sent }, /* in MDI client */
1676
1677     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1678     { WM_KILLFOCUS, sent }, /* in MDI client */
1679     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1680     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1681     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1682     { WM_SETFOCUS, sent }, /* in MDI client */
1683
1684     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1685
1686     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1687     { WM_KILLFOCUS, sent },
1688     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1689     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1690     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1691     { WM_SETFOCUS, sent }, /* in MDI client */
1692
1693     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1694     { WM_KILLFOCUS, sent }, /* in MDI client */
1695     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1696     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1697     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1698     { WM_SETFOCUS, sent }, /* in MDI client */
1699
1700     { WM_DESTROY, sent },
1701
1702     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1703     { WM_KILLFOCUS, sent },
1704     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1705     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1706     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1707     { WM_SETFOCUS, sent }, /* in MDI client */
1708
1709     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1710     { WM_KILLFOCUS, sent }, /* in MDI client */
1711     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1712     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1713     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1714     { WM_SETFOCUS, sent }, /* in MDI client */
1715
1716     { WM_NCDESTROY, sent },
1717     { 0 }
1718 };
1719 /* CreateWindow for MDI child window, initially invisible */
1720 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1721     { HCBT_CREATEWND, hook },
1722     { WM_NCCREATE, sent }, 
1723     { WM_NCCALCSIZE, sent|wparam, 0 },
1724     { WM_CREATE, sent },
1725     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1726     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1727     { WM_MOVE, sent },
1728     /* Win2k sends wparam set to
1729      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1730      * while Win9x doesn't bother to set child window id according to
1731      * CLIENTCREATESTRUCT.idFirstChild
1732      */
1733     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1734     { 0 }
1735 };
1736 /* DestroyWindow for MDI child window, initially invisible */
1737 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1738     { HCBT_DESTROYWND, hook },
1739     /* Win2k sends wparam set to
1740      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1741      * while Win9x doesn't bother to set child window id according to
1742      * CLIENTCREATESTRUCT.idFirstChild
1743      */
1744     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1745     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1746     { WM_DESTROY, sent },
1747     { WM_NCDESTROY, sent },
1748     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
1749     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
1750     { 0 }
1751 };
1752 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1753 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1754     { HCBT_CREATEWND, hook },
1755     { WM_NCCREATE, sent }, 
1756     { WM_NCCALCSIZE, sent|wparam, 0 },
1757     { WM_CREATE, sent },
1758     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1759     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1760     { WM_MOVE, sent },
1761     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1762     { WM_GETMINMAXINFO, sent },
1763     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1764     { WM_NCCALCSIZE, sent|wparam, 1 },
1765     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1766     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1767      /* in MDI frame */
1768     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1769     { WM_NCCALCSIZE, sent|wparam, 1 },
1770     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1771     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1772     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1773     /* Win2k sends wparam set to
1774      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1775      * while Win9x doesn't bother to set child window id according to
1776      * CLIENTCREATESTRUCT.idFirstChild
1777      */
1778     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1779     { WM_SHOWWINDOW, sent|wparam, 1 },
1780     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1781     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1782     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1783     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1784     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1785     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1786     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1787
1788     /* Win9x: message sequence terminates here. */
1789
1790     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1791     { HCBT_SETFOCUS, hook }, /* in MDI client */
1792     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1793     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1794     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1795     { WM_SETFOCUS, sent }, /* in MDI client */
1796     { HCBT_SETFOCUS, hook },
1797     { WM_KILLFOCUS, sent }, /* in MDI client */
1798     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1799     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1800     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1801     { WM_SETFOCUS, sent|defwinproc },
1802     { WM_MDIACTIVATE, sent|defwinproc },
1803      /* in MDI frame */
1804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1805     { WM_NCCALCSIZE, sent|wparam, 1 },
1806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1807     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1808     { 0 }
1809 };
1810 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
1811 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
1812     /* restore the 1st MDI child */
1813     { WM_SETREDRAW, sent|wparam, 0 },
1814     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
1815     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1816     { WM_NCCALCSIZE, sent|wparam, 1 },
1817     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1819     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1820      /* in MDI frame */
1821     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1822     { WM_NCCALCSIZE, sent|wparam, 1 },
1823     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1824     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1825     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1826     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
1827     /* create the 2nd MDI child */
1828     { HCBT_CREATEWND, hook },
1829     { WM_NCCREATE, sent }, 
1830     { WM_NCCALCSIZE, sent|wparam, 0 },
1831     { WM_CREATE, sent },
1832     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1833     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1834     { WM_MOVE, sent },
1835     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1836     { WM_GETMINMAXINFO, sent },
1837     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1838     { WM_NCCALCSIZE, sent|wparam, 1 },
1839     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1840     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1841     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1842      /* in MDI frame */
1843     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1844     { WM_NCCALCSIZE, sent|wparam, 1 },
1845     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1846     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1847     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1848     /* Win2k sends wparam set to
1849      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1850      * while Win9x doesn't bother to set child window id according to
1851      * CLIENTCREATESTRUCT.idFirstChild
1852      */
1853     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1854     { WM_SHOWWINDOW, sent|wparam, 1 },
1855     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1856     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1858     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1859     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1860     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1861
1862     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1863     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1864
1865     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1866
1867     /* Win9x: message sequence terminates here. */
1868
1869     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1870     { HCBT_SETFOCUS, hook },
1871     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
1872     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
1873     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1874     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1875     { WM_SETFOCUS, sent }, /* in MDI client */
1876     { HCBT_SETFOCUS, hook },
1877     { WM_KILLFOCUS, sent }, /* in MDI client */
1878     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1879     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1880     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1881     { WM_SETFOCUS, sent|defwinproc },
1882
1883     { WM_MDIACTIVATE, sent|defwinproc },
1884      /* in MDI frame */
1885     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1886     { WM_NCCALCSIZE, sent|wparam, 1 },
1887     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1888     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1889     { 0 }
1890 };
1891 /* WM_MDICREATE MDI child window, initially visible and maximized */
1892 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
1893     { WM_MDICREATE, sent },
1894     { HCBT_CREATEWND, hook },
1895     { WM_NCCREATE, sent }, 
1896     { WM_NCCALCSIZE, sent|wparam, 0 },
1897     { WM_CREATE, sent },
1898     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1899     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1900     { WM_MOVE, sent },
1901     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1902     { WM_GETMINMAXINFO, sent },
1903     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1904     { WM_NCCALCSIZE, sent|wparam, 1 },
1905     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1906     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1907
1908      /* in MDI frame */
1909     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1910     { WM_NCCALCSIZE, sent|wparam, 1 },
1911     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1912     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1913     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1914
1915     /* Win2k sends wparam set to
1916      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1917      * while Win9x doesn't bother to set child window id according to
1918      * CLIENTCREATESTRUCT.idFirstChild
1919      */
1920     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1921     { WM_SHOWWINDOW, sent|wparam, 1 },
1922     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1923
1924     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1925
1926     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1927     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1928     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1929
1930     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1931     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1932
1933     /* Win9x: message sequence terminates here. */
1934
1935     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1936     { WM_SETFOCUS, sent|optional }, /* in MDI client */
1937     { HCBT_SETFOCUS, hook }, /* in MDI client */
1938     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1939     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1940     { WM_SETFOCUS, sent|optional }, /* in MDI client */
1941     { HCBT_SETFOCUS, hook|optional },
1942     { WM_KILLFOCUS, sent }, /* in MDI client */
1943     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1944     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1945     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1946     { WM_SETFOCUS, sent|defwinproc },
1947
1948     { WM_MDIACTIVATE, sent|defwinproc },
1949
1950      /* in MDI child */
1951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1952     { WM_NCCALCSIZE, sent|wparam, 1 },
1953     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1954     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1955
1956      /* in MDI frame */
1957     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1958     { WM_NCCALCSIZE, sent|wparam, 1 },
1959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1960     { WM_MOVE, sent|defwinproc },
1961     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1962
1963      /* in MDI client */
1964     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1965     { WM_NCCALCSIZE, sent|wparam, 1 },
1966     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
1967     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1968
1969      /* in MDI child */
1970     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1971     { WM_NCCALCSIZE, sent|wparam, 1 },
1972     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
1973     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1974
1975     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1976     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1977     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
1978     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1979     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
1980
1981     { 0 }
1982 };
1983 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
1984 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
1985     { HCBT_CREATEWND, hook },
1986     { WM_GETMINMAXINFO, sent },
1987     { WM_NCCREATE, sent }, 
1988     { WM_NCCALCSIZE, sent|wparam, 0 },
1989     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1990     { WM_CREATE, sent },
1991     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1992     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1993     { WM_MOVE, sent },
1994     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1995     { WM_GETMINMAXINFO, sent },
1996     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1997     { WM_GETMINMAXINFO, sent|defwinproc },
1998     { WM_NCCALCSIZE, sent|wparam, 1 },
1999     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|0x8000 },
2000     { WM_MOVE, sent|defwinproc },
2001     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2002      /* in MDI frame */
2003     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2004     { WM_NCCALCSIZE, sent|wparam, 1 },
2005     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2006     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2007     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2008     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2009     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2010     /* Win2k sends wparam set to
2011      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2012      * while Win9x doesn't bother to set child window id according to
2013      * CLIENTCREATESTRUCT.idFirstChild
2014      */
2015     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2016     { 0 }
2017 };
2018 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2019 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2020     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2021     { HCBT_SYSCOMMAND, hook },
2022     { WM_CLOSE, sent|defwinproc },
2023     { WM_MDIDESTROY, sent }, /* in MDI client */
2024
2025     /* bring the 1st MDI child to top */
2026     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2027     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2028
2029     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2030
2031     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2032     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2033     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2034
2035     /* maximize the 1st MDI child */
2036     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2037     { WM_GETMINMAXINFO, sent|defwinproc },
2038     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
2039     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2040     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2041     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2042     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2043
2044     /* restore the 2nd MDI child */
2045     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2046     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2047     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2048     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2049
2050     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2051
2052     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2053     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2054
2055     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2056
2057     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2058      /* in MDI frame */
2059     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2060     { WM_NCCALCSIZE, sent|wparam, 1 },
2061     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2062     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2063     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2064
2065     /* bring the 1st MDI child to top */
2066     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2067     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2068     { HCBT_SETFOCUS, hook },
2069     { WM_KILLFOCUS, sent|defwinproc },
2070     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2071     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2072     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2073     { WM_SETFOCUS, sent }, /* in MDI client */
2074     { HCBT_SETFOCUS, hook },
2075     { WM_KILLFOCUS, sent }, /* in MDI client */
2076     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2077     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2078     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2079     { WM_SETFOCUS, sent|defwinproc },
2080     { WM_MDIACTIVATE, sent|defwinproc },
2081     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2082
2083     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2084     { WM_SHOWWINDOW, sent|wparam, 1 },
2085     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2086     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2087     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2088     { WM_MDIREFRESHMENU, sent },
2089
2090     { HCBT_DESTROYWND, hook },
2091     /* Win2k sends wparam set to
2092      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2093      * while Win9x doesn't bother to set child window id according to
2094      * CLIENTCREATESTRUCT.idFirstChild
2095      */
2096     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2097     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2098     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2099     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2100     { WM_ERASEBKGND, sent|parent|optional },
2101     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2102
2103     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2104     { WM_DESTROY, sent|defwinproc },
2105     { WM_NCDESTROY, sent|defwinproc },
2106     { 0 }
2107 };
2108 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2109 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2110     { WM_MDIDESTROY, sent }, /* in MDI client */
2111     { WM_SHOWWINDOW, sent|wparam, 0 },
2112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2113     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2114     { WM_ERASEBKGND, sent|parent|optional },
2115     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2116
2117     { HCBT_SETFOCUS, hook },
2118     { WM_KILLFOCUS, sent },
2119     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2120     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2121     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2122     { WM_SETFOCUS, sent }, /* in MDI client */
2123     { HCBT_SETFOCUS, hook },
2124     { WM_KILLFOCUS, sent }, /* in MDI client */
2125     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2126     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2127     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2128     { WM_SETFOCUS, sent },
2129
2130      /* in MDI child */
2131     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2132     { WM_NCCALCSIZE, sent|wparam, 1 },
2133     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2134     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2135
2136      /* in MDI frame */
2137     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2138     { WM_NCCALCSIZE, sent|wparam, 1 },
2139     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2140     { WM_MOVE, sent|defwinproc },
2141     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2142
2143      /* in MDI client */
2144     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2145     { WM_NCCALCSIZE, sent|wparam, 1 },
2146     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2147     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2148
2149      /* in MDI child */
2150     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2151     { WM_NCCALCSIZE, sent|wparam, 1 },
2152     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2153     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2154
2155      /* in MDI child */
2156     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2157     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2158     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2159     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2160
2161      /* in MDI frame */
2162     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2163     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2164     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2165     { WM_MOVE, sent|defwinproc },
2166     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2167
2168      /* in MDI client */
2169     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2170     { WM_NCCALCSIZE, sent|wparam, 1 },
2171     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2172     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2173
2174      /* in MDI child */
2175     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2176     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2177     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2178     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2179     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2180     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2181
2182     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2183
2184     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2185     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2186     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2187     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2188     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2189
2190      /* in MDI frame */
2191     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2192     { WM_NCCALCSIZE, sent|wparam, 1 },
2193     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2194     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2195
2196     { WM_NCACTIVATE, sent|wparam, 0 },
2197     { WM_MDIACTIVATE, sent },
2198
2199     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2200     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2201     { WM_NCCALCSIZE, sent|wparam, 1 },
2202
2203     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2204
2205     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2206     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|0x8000 },
2207     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2208
2209      /* in MDI child */
2210     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2211     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2212     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2213     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2214
2215      /* in MDI frame */
2216     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2217     { WM_NCCALCSIZE, sent|wparam, 1 },
2218     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2219     { WM_MOVE, sent|defwinproc },
2220     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2221
2222      /* in MDI client */
2223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2224     { WM_NCCALCSIZE, sent|wparam, 1 },
2225     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2226     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2227     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2228     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2229     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2230     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2231     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2232
2233     { HCBT_SETFOCUS, hook },
2234     { WM_KILLFOCUS, sent },
2235     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2236     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2237     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2238     { WM_SETFOCUS, sent }, /* in MDI client */
2239
2240     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2241
2242     { HCBT_DESTROYWND, hook },
2243     /* Win2k sends wparam set to
2244      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2245      * while Win9x doesn't bother to set child window id according to
2246      * CLIENTCREATESTRUCT.idFirstChild
2247      */
2248     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2249
2250     { WM_SHOWWINDOW, sent|wparam, 0 },
2251     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2252     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2253     { WM_ERASEBKGND, sent|parent|optional },
2254     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2255
2256     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2257     { WM_DESTROY, sent },
2258     { WM_NCDESTROY, sent },
2259     { 0 }
2260 };
2261 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2262 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2263     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2264     { WM_GETMINMAXINFO, sent },
2265     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2266     { WM_NCCALCSIZE, sent|wparam, 1 },
2267     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2268     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2269
2270     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2271     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2272     { HCBT_SETFOCUS, hook },
2273     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2274     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2275     { WM_SETFOCUS, sent }, /* in MDI client */
2276     { HCBT_SETFOCUS, hook },
2277     { WM_KILLFOCUS, sent }, /* in MDI client */
2278     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2279     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2280     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2281     { WM_SETFOCUS, sent|defwinproc },
2282     { WM_MDIACTIVATE, sent|defwinproc },
2283     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2284     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2285      /* in MDI frame */
2286     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2287     { WM_NCCALCSIZE, sent|wparam, 1 },
2288     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2289     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2290     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2291     { 0 }
2292 };
2293 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2294 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2295     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2296     { WM_GETMINMAXINFO, sent },
2297     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2298     { WM_GETMINMAXINFO, sent|defwinproc },
2299     { WM_NCCALCSIZE, sent|wparam, 1 },
2300     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2301     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2302
2303     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2304     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2305     { HCBT_SETFOCUS, hook },
2306     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2307     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2308     { WM_SETFOCUS, sent }, /* in MDI client */
2309     { HCBT_SETFOCUS, hook },
2310     { WM_KILLFOCUS, sent }, /* in MDI client */
2311     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2312     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2313     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2314     { WM_SETFOCUS, sent|defwinproc },
2315     { WM_MDIACTIVATE, sent|defwinproc },
2316     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2317     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2318     { 0 }
2319 };
2320 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2321 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2322     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2323     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2324     { WM_GETMINMAXINFO, sent },
2325     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2326     { WM_GETMINMAXINFO, sent|defwinproc },
2327     { WM_NCCALCSIZE, sent|wparam, 1 },
2328     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2329     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2330     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
2331     { WM_MOVE, sent|defwinproc },
2332     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2333
2334     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2335     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2336     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2337     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2338     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2339     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2340      /* in MDI frame */
2341     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2342     { WM_NCCALCSIZE, sent|wparam, 1 },
2343     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2344     { WM_MOVE, sent|defwinproc },
2345     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2346     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2347      /* in MDI client */
2348     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2349     { WM_NCCALCSIZE, sent|wparam, 1 },
2350     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2351     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2352      /* in MDI child */
2353     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2354     { WM_GETMINMAXINFO, sent|defwinproc },
2355     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2356     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2357     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2358     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2359     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2360     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2361     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2362     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2363      /* in MDI frame */
2364     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2365     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2366     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2367     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2368     { 0 }
2369 };
2370 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2371 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2372     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2373     { WM_GETMINMAXINFO, sent },
2374     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2375     { WM_NCCALCSIZE, sent|wparam, 1 },
2376     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2377     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2378     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2379      /* in MDI frame */
2380     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2381     { WM_NCCALCSIZE, sent|wparam, 1 },
2382     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2383     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2384     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2385     { 0 }
2386 };
2387 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2388 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2389     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2390     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2391     { WM_NCCALCSIZE, sent|wparam, 1 },
2392     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2393     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2394     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2395      /* in MDI frame */
2396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2397     { WM_NCCALCSIZE, sent|wparam, 1 },
2398     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2399     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2400     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2401     { 0 }
2402 };
2403 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2404 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2405     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2406     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2407     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
2408     { WM_NCCALCSIZE, sent|wparam, 1 },
2409     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2410     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2411     { WM_MOVE, sent|defwinproc },
2412     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2413     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2414     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2415     { HCBT_SETFOCUS, hook },
2416     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2417     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2418     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2419     { WM_SETFOCUS, sent },
2420     { 0 }
2421 };
2422 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2423 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2424     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
2426     { WM_NCCALCSIZE, sent|wparam, 1 },
2427     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2428     { WM_MOVE, sent|defwinproc },
2429     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2430     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2431     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2432     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2433     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2434     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2435     { 0 }
2436 };
2437 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2438 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2439     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2440     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2441     { WM_NCCALCSIZE, sent|wparam, 1 },
2442     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2443     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2444     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2445     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2446      /* in MDI frame */
2447     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2448     { WM_NCCALCSIZE, sent|wparam, 1 },
2449     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2450     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2451     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2452     { 0 }
2453 };
2454
2455 static HWND mdi_client;
2456 static WNDPROC old_mdi_client_proc;
2457
2458 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2459 {
2460     struct message msg;
2461
2462     /* do not log painting messages */
2463     if (message != WM_PAINT &&
2464         message != WM_NCPAINT &&
2465         message != WM_SYNCPAINT &&
2466         message != WM_ERASEBKGND &&
2467         message != WM_NCPAINT &&
2468         message != WM_NCHITTEST &&
2469         message != WM_GETTEXT &&
2470         message != WM_MDIGETACTIVE &&
2471         message != WM_GETICON &&
2472         message != WM_DEVICECHANGE)
2473     {
2474         trace("mdi client: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2475
2476         switch (message)
2477         {
2478             case WM_WINDOWPOSCHANGING:
2479             case WM_WINDOWPOSCHANGED:
2480             {
2481                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2482
2483                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2484                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2485                       winpos->hwnd, winpos->hwndInsertAfter,
2486                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2487                 dump_winpos_flags(winpos->flags);
2488
2489                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2490                  * in the high word for internal purposes
2491                  */
2492                 wParam = winpos->flags & 0xffff;
2493                 /* We are not interested in the flags that don't match under XP and Win9x */
2494                 wParam &= ~(SWP_NOZORDER);
2495                 break;
2496             }
2497         }
2498
2499         msg.message = message;
2500         msg.flags = sent|wparam|lparam;
2501         msg.wParam = wParam;
2502         msg.lParam = lParam;
2503         add_message(&msg);
2504     }
2505
2506     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2507 }
2508
2509 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2510 {
2511     static long defwndproc_counter = 0;
2512     LRESULT ret;
2513     struct message msg;
2514
2515     /* do not log painting messages */
2516     if (message != WM_PAINT &&
2517         message != WM_NCPAINT &&
2518         message != WM_SYNCPAINT &&
2519         message != WM_ERASEBKGND &&
2520         message != WM_NCPAINT &&
2521         message != WM_NCHITTEST &&
2522         message != WM_GETTEXT &&
2523         message != WM_GETICON &&
2524         message != WM_DEVICECHANGE)
2525     {
2526         trace("mdi child: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2527
2528         switch (message)
2529         {
2530             case WM_WINDOWPOSCHANGING:
2531             case WM_WINDOWPOSCHANGED:
2532             {
2533                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2534
2535                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2536                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2537                       winpos->hwnd, winpos->hwndInsertAfter,
2538                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2539                 dump_winpos_flags(winpos->flags);
2540
2541                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2542                  * in the high word for internal purposes
2543                  */
2544                 wParam = winpos->flags & 0xffff;
2545                 /* We are not interested in the flags that don't match under XP and Win9x */
2546                 wParam &= ~(SWP_NOZORDER);
2547                 break;
2548             }
2549
2550             case WM_MDIACTIVATE:
2551             {
2552                 HWND active, client = GetParent(hwnd);
2553
2554                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2555
2556                 if (hwnd == (HWND)lParam) /* if we are being activated */
2557                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2558                 else
2559                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2560                 break;
2561             }
2562         }
2563
2564         msg.message = message;
2565         msg.flags = sent|wparam|lparam;
2566         if (defwndproc_counter) msg.flags |= defwinproc;
2567         msg.wParam = wParam;
2568         msg.lParam = lParam;
2569         add_message(&msg);
2570     }
2571
2572     defwndproc_counter++;
2573     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2574     defwndproc_counter--;
2575
2576     return ret;
2577 }
2578
2579 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2580 {
2581     static long defwndproc_counter = 0;
2582     LRESULT ret;
2583     struct message msg;
2584
2585     /* do not log painting messages */
2586     if (message != WM_PAINT &&
2587         message != WM_NCPAINT &&
2588         message != WM_SYNCPAINT &&
2589         message != WM_ERASEBKGND &&
2590         message != WM_NCPAINT &&
2591         message != WM_NCHITTEST &&
2592         message != WM_GETTEXT &&
2593         message != WM_GETICON &&
2594         message != WM_DEVICECHANGE)
2595     {
2596         trace("mdi frame: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2597
2598         switch (message)
2599         {
2600             case WM_WINDOWPOSCHANGING:
2601             case WM_WINDOWPOSCHANGED:
2602             {
2603                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2604
2605                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2606                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2607                       winpos->hwnd, winpos->hwndInsertAfter,
2608                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2609                 dump_winpos_flags(winpos->flags);
2610
2611                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2612                  * in the high word for internal purposes
2613                  */
2614                 wParam = winpos->flags & 0xffff;
2615                 /* We are not interested in the flags that don't match under XP and Win9x */
2616                 wParam &= ~(SWP_NOZORDER);
2617                 break;
2618             }
2619         }
2620
2621         msg.message = message;
2622         msg.flags = sent|wparam|lparam;
2623         if (defwndproc_counter) msg.flags |= defwinproc;
2624         msg.wParam = wParam;
2625         msg.lParam = lParam;
2626         add_message(&msg);
2627     }
2628
2629     defwndproc_counter++;
2630     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2631     defwndproc_counter--;
2632
2633     return ret;
2634 }
2635
2636 static BOOL mdi_RegisterWindowClasses(void)
2637 {
2638     WNDCLASSA cls;
2639
2640     cls.style = 0;
2641     cls.lpfnWndProc = mdi_frame_wnd_proc;
2642     cls.cbClsExtra = 0;
2643     cls.cbWndExtra = 0;
2644     cls.hInstance = GetModuleHandleA(0);
2645     cls.hIcon = 0;
2646     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2647     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2648     cls.lpszMenuName = NULL;
2649     cls.lpszClassName = "MDI_frame_class";
2650     if (!RegisterClassA(&cls)) return FALSE;
2651
2652     cls.lpfnWndProc = mdi_child_wnd_proc;
2653     cls.lpszClassName = "MDI_child_class";
2654     if (!RegisterClassA(&cls)) return FALSE;
2655
2656     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2657     old_mdi_client_proc = cls.lpfnWndProc;
2658     cls.hInstance = GetModuleHandleA(0);
2659     cls.lpfnWndProc = mdi_client_hook_proc;
2660     cls.lpszClassName = "MDI_client_class";
2661     if (!RegisterClassA(&cls)) assert(0);
2662
2663     return TRUE;
2664 }
2665
2666 static void test_mdi_messages(void)
2667 {
2668     MDICREATESTRUCTA mdi_cs;
2669     CLIENTCREATESTRUCT client_cs;
2670     HWND mdi_frame, mdi_child, mdi_child2, active_child;
2671     BOOL zoomed;
2672     HMENU hMenu = CreateMenu();
2673
2674     assert(mdi_RegisterWindowClasses());
2675
2676     flush_sequence();
2677
2678     trace("creating MDI frame window\n");
2679     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2680                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2681                                 WS_MAXIMIZEBOX | WS_VISIBLE,
2682                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2683                                 GetDesktopWindow(), hMenu,
2684                                 GetModuleHandleA(0), NULL);
2685     assert(mdi_frame);
2686     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
2687
2688     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2689     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2690
2691     trace("creating MDI client window\n");
2692     client_cs.hWindowMenu = 0;
2693     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2694     mdi_client = CreateWindowExA(0, "MDI_client_class",
2695                                  NULL,
2696                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2697                                  0, 0, 0, 0,
2698                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2699     assert(mdi_client);
2700     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2701
2702     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2703     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2704
2705     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2706     ok(!active_child, "wrong active MDI child %p\n", active_child);
2707     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2708
2709     SetFocus(0);
2710     flush_sequence();
2711
2712     trace("creating invisible MDI child window\n");
2713     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2714                                 WS_CHILD,
2715                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2716                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2717     assert(mdi_child);
2718
2719     flush_sequence();
2720     ShowWindow(mdi_child, SW_SHOWNORMAL);
2721     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2722
2723     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2724     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2725
2726     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2727     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2728
2729     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2730     ok(!active_child, "wrong active MDI child %p\n", active_child);
2731     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2732
2733     ShowWindow(mdi_child, SW_HIDE);
2734     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2735     flush_sequence();
2736
2737     ShowWindow(mdi_child, SW_SHOW);
2738     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2739
2740     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2741     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2742
2743     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2744     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2745
2746     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2747     ok(!active_child, "wrong active MDI child %p\n", active_child);
2748     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2749
2750     DestroyWindow(mdi_child);
2751     flush_sequence();
2752
2753     trace("creating visible MDI child window\n");
2754     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2755                                 WS_CHILD | WS_VISIBLE,
2756                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2757                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2758     assert(mdi_child);
2759     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2760
2761     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2762     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2763
2764     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2765     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2766
2767     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2768     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2769     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2770     flush_sequence();
2771
2772     DestroyWindow(mdi_child);
2773     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2774
2775     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2776     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2777
2778     /* Win2k: MDI client still returns a just destroyed child as active
2779      * Win9x: MDI client returns 0
2780      */
2781     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2782     ok(active_child == mdi_child || /* win2k */
2783        !active_child, /* win9x */
2784        "wrong active MDI child %p\n", active_child);
2785     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2786
2787     flush_sequence();
2788
2789     trace("creating invisible MDI child window\n");
2790     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2791                                 WS_CHILD,
2792                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2793                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2794     assert(mdi_child2);
2795     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2796
2797     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2798     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2799
2800     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2801     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2802
2803     /* Win2k: MDI client still returns a just destroyed child as active
2804      * Win9x: MDI client returns mdi_child2
2805      */
2806     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2807     ok(active_child == mdi_child || /* win2k */
2808        active_child == mdi_child2, /* win9x */
2809        "wrong active MDI child %p\n", active_child);
2810     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2811     flush_sequence();
2812
2813     ShowWindow(mdi_child2, SW_MAXIMIZE);
2814     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
2815
2816     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2817     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2818
2819     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2820     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2821     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2822     flush_sequence();
2823
2824     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2825     ok(GetFocus() == mdi_child2 || /* win2k */
2826        GetFocus() == 0, /* win9x */
2827        "wrong focus window %p\n", GetFocus());
2828
2829     SetFocus(0);
2830     flush_sequence();
2831
2832     ShowWindow(mdi_child2, SW_HIDE);
2833     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2834
2835     ShowWindow(mdi_child2, SW_RESTORE);
2836     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
2837     flush_sequence();
2838
2839     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2840     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2841
2842     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2843     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2844     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2845     flush_sequence();
2846
2847     SetFocus(0);
2848     flush_sequence();
2849
2850     ShowWindow(mdi_child2, SW_HIDE);
2851     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2852
2853     ShowWindow(mdi_child2, SW_SHOW);
2854     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
2855
2856     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2857     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2858
2859     ShowWindow(mdi_child2, SW_MAXIMIZE);
2860     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
2861
2862     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2863     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2864
2865     ShowWindow(mdi_child2, SW_RESTORE);
2866     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
2867
2868     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2869     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2870
2871     ShowWindow(mdi_child2, SW_MINIMIZE);
2872     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
2873
2874     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2875     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2876
2877     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2878     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2879     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2880     flush_sequence();
2881
2882     ShowWindow(mdi_child2, SW_RESTORE);
2883     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
2884
2885     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2886     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2887
2888     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2889     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2890     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2891     flush_sequence();
2892
2893     SetFocus(0);
2894     flush_sequence();
2895
2896     ShowWindow(mdi_child2, SW_HIDE);
2897     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2898
2899     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2900     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2901
2902     DestroyWindow(mdi_child2);
2903     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
2904
2905     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2906     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2907
2908     /* test for maximized MDI children */
2909     trace("creating maximized visible MDI child window 1\n");
2910     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2911                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2912                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2913                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2914     assert(mdi_child);
2915     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
2916     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2917
2918     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2919     ok(GetFocus() == mdi_child || /* win2k */
2920        GetFocus() == 0, /* win9x */
2921        "wrong focus window %p\n", GetFocus());
2922
2923     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2924     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2925     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2926     flush_sequence();
2927
2928     trace("creating maximized visible MDI child window 2\n");
2929     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2930                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2931                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2932                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2933     assert(mdi_child2);
2934     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2935     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2936     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2937
2938     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2939     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2940
2941     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2942     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2943     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2944     flush_sequence();
2945
2946     trace("destroying maximized visible MDI child window 2\n");
2947     DestroyWindow(mdi_child2);
2948     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2949
2950     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2951
2952     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2953     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2954
2955     /* Win2k: MDI client still returns a just destroyed child as active
2956      * Win9x: MDI client returns 0
2957      */
2958     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2959     ok(active_child == mdi_child2 || /* win2k */
2960        !active_child, /* win9x */
2961        "wrong active MDI child %p\n", active_child);
2962     flush_sequence();
2963
2964     ShowWindow(mdi_child, SW_MAXIMIZE);
2965     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2966     flush_sequence();
2967
2968     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2969     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2970
2971     trace("re-creating maximized visible MDI child window 2\n");
2972     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2973                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2974                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2975                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2976     assert(mdi_child2);
2977     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2978     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2979     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2980
2981     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2982     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2983
2984     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2985     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2986     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2987     flush_sequence();
2988
2989     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
2990     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
2991     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
2992
2993     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2994     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2995     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2996
2997     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2998     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2999     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3000     flush_sequence();
3001
3002     DestroyWindow(mdi_child);
3003     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3004
3005     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3006     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3007
3008     /* Win2k: MDI client still returns a just destroyed child as active
3009      * Win9x: MDI client returns 0
3010      */
3011     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3012     ok(active_child == mdi_child || /* win2k */
3013        !active_child, /* win9x */
3014        "wrong active MDI child %p\n", active_child);
3015     flush_sequence();
3016
3017     trace("creating maximized invisible MDI child window\n");
3018     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3019                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3020                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3021                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3022     assert(mdi_child2);
3023     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", TRUE);
3024     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3025     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3026     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3027
3028     /* Win2k: MDI client still returns a just destroyed child as active
3029      * Win9x: MDI client returns 0
3030      */
3031     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3032     ok(active_child == mdi_child || /* win2k */
3033        !active_child, /* win9x */
3034        "wrong active MDI child %p\n", active_child);
3035     flush_sequence();
3036
3037     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3038     ShowWindow(mdi_child2, SW_MAXIMIZE);
3039     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3040     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3041     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3042     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3043
3044     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3045     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3046     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3047     flush_sequence();
3048
3049     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3050     flush_sequence();
3051
3052     /* end of test for maximized MDI children */
3053
3054     mdi_cs.szClass = "MDI_child_Class";
3055     mdi_cs.szTitle = "MDI child";
3056     mdi_cs.hOwner = GetModuleHandleA(0);
3057     mdi_cs.x = 0;
3058     mdi_cs.y = 0;
3059     mdi_cs.cx = CW_USEDEFAULT;
3060     mdi_cs.cy = CW_USEDEFAULT;
3061     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3062     mdi_cs.lParam = 0;
3063     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3064     ok(mdi_child != 0, "MDI child creation failed\n");
3065     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3066
3067     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3068
3069     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3070     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3071
3072     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3073     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3074     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3075
3076     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3077     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3078     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3079     flush_sequence();
3080
3081     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3082     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3083
3084     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3085     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3086     ok(!active_child, "wrong active MDI child %p\n", active_child);
3087
3088     SetFocus(0);
3089     flush_sequence();
3090
3091     DestroyWindow(mdi_client);
3092     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3093
3094     /* test maximization of MDI child with invisible parent */
3095     client_cs.hWindowMenu = 0;
3096     mdi_client = CreateWindow("MDI_client_class",
3097                                  NULL,
3098                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3099                                  0, 0, 660, 430,
3100                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3101     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3102
3103     ShowWindow(mdi_client, SW_HIDE);
3104     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3105
3106     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3107                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3108                                 0, 0, 650, 440,
3109                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3110     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3111
3112     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3113     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3114     zoomed = IsZoomed(mdi_child);
3115     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3116     
3117     ShowWindow(mdi_client, SW_SHOW);
3118     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3119
3120     DestroyWindow(mdi_child);
3121     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3122
3123     DestroyWindow(mdi_client);
3124     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3125     /* end of test for maximization of MDI child with invisible parent */
3126     
3127     DestroyWindow(mdi_frame);
3128     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3129 }
3130 /************************* End of MDI test **********************************/
3131
3132 static void test_WM_SETREDRAW(HWND hwnd)
3133 {
3134     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3135
3136     flush_sequence();
3137
3138     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3139     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3140
3141     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3142     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3143
3144     flush_sequence();
3145     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3146     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3147
3148     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3149     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3150
3151     /* restore original WS_VISIBLE state */
3152     SetWindowLongA(hwnd, GWL_STYLE, style);
3153
3154     flush_sequence();
3155 }
3156
3157 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3158 {
3159     struct message msg;
3160
3161     trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
3162
3163     /* explicitly ignore WM_GETICON message */
3164     if (message == WM_GETICON) return 0;
3165
3166     switch (message)
3167     {
3168         /* ignore */
3169         case WM_MOUSEMOVE:
3170         case WM_SETCURSOR:
3171         case WM_DEVICECHANGE:
3172             return 0;
3173         case WM_NCHITTEST:
3174             return HTCLIENT;
3175
3176         case WM_WINDOWPOSCHANGING:
3177         case WM_WINDOWPOSCHANGED:
3178         {
3179             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3180
3181             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3182             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
3183                   winpos->hwnd, winpos->hwndInsertAfter,
3184                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3185             dump_winpos_flags(winpos->flags);
3186
3187             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3188              * in the high word for internal purposes
3189              */
3190             wParam = winpos->flags & 0xffff;
3191             /* We are not interested in the flags that don't match under XP and Win9x */
3192             wParam &= ~(SWP_NOZORDER);
3193             break;
3194         }
3195     }
3196
3197     msg.message = message;
3198     msg.flags = sent|wparam|lparam;
3199     msg.wParam = wParam;
3200     msg.lParam = lParam;
3201     add_message(&msg);
3202
3203     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3204     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3205     return 0;
3206 }
3207
3208 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3209 {
3210     DWORD style, exstyle;
3211     INT xmin, xmax;
3212     BOOL ret;
3213
3214     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3215     style = GetWindowLongA(hwnd, GWL_STYLE);
3216     /* do not be confused by WS_DLGFRAME set */
3217     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3218
3219     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3220     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3221
3222     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3223     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3224     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3225         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3226     else
3227         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3228
3229     style = GetWindowLongA(hwnd, GWL_STYLE);
3230     if (set) ok(style & set, "style %08x should be set\n", set);
3231     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3232
3233     /* a subsequent call should do nothing */
3234     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3235     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3236     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3237
3238     xmin = 0xdeadbeef;
3239     xmax = 0xdeadbeef;
3240     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3241     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3242     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3243     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3244     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3245     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3246 }
3247
3248 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3249 {
3250     DWORD style, exstyle;
3251     SCROLLINFO si;
3252     BOOL ret;
3253
3254     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3255     style = GetWindowLongA(hwnd, GWL_STYLE);
3256     /* do not be confused by WS_DLGFRAME set */
3257     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3258
3259     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3260     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3261
3262     si.cbSize = sizeof(si);
3263     si.fMask = SIF_RANGE;
3264     si.nMin = min;
3265     si.nMax = max;
3266     SetScrollInfo(hwnd, ctl, &si, TRUE);
3267     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3268         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3269     else
3270         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3271
3272     style = GetWindowLongA(hwnd, GWL_STYLE);
3273     if (set) ok(style & set, "style %08x should be set\n", set);
3274     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3275
3276     /* a subsequent call should do nothing */
3277     SetScrollInfo(hwnd, ctl, &si, TRUE);
3278     if (style & WS_HSCROLL)
3279         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3280     else if (style & WS_VSCROLL)
3281         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3282     else
3283         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3284
3285     si.fMask = SIF_PAGE;
3286     si.nPage = 5;
3287     SetScrollInfo(hwnd, ctl, &si, FALSE);
3288     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3289
3290     si.fMask = SIF_POS;
3291     si.nPos = max - 1;
3292     SetScrollInfo(hwnd, ctl, &si, FALSE);
3293     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3294
3295     si.fMask = SIF_RANGE;
3296     si.nMin = 0xdeadbeef;
3297     si.nMax = 0xdeadbeef;
3298     ret = GetScrollInfo(hwnd, ctl, &si);
3299     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3300     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3301     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3302     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3303 }
3304
3305 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3306 static void test_scroll_messages(HWND hwnd)
3307 {
3308     SCROLLINFO si;
3309     INT min, max;
3310     BOOL ret;
3311
3312     min = 0xdeadbeef;
3313     max = 0xdeadbeef;
3314     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3315     ok( ret, "GetScrollRange error %d\n", GetLastError());
3316     if (sequence->message != WmGetScrollRangeSeq[0].message)
3317         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3318     /* values of min and max are undefined */
3319     flush_sequence();
3320
3321     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3322     ok( ret, "SetScrollRange error %d\n", GetLastError());
3323     if (sequence->message != WmSetScrollRangeSeq[0].message)
3324         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3325     flush_sequence();
3326
3327     min = 0xdeadbeef;
3328     max = 0xdeadbeef;
3329     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3330     ok( ret, "GetScrollRange error %d\n", GetLastError());
3331     if (sequence->message != WmGetScrollRangeSeq[0].message)
3332         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3333     /* values of min and max are undefined */
3334     flush_sequence();
3335
3336     si.cbSize = sizeof(si);
3337     si.fMask = SIF_RANGE;
3338     si.nMin = 20;
3339     si.nMax = 160;
3340     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3341     if (sequence->message != WmSetScrollRangeSeq[0].message)
3342         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3343     flush_sequence();
3344
3345     si.fMask = SIF_PAGE;
3346     si.nPage = 10;
3347     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3348     if (sequence->message != WmSetScrollRangeSeq[0].message)
3349         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3350     flush_sequence();
3351
3352     si.fMask = SIF_POS;
3353     si.nPos = 20;
3354     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3355     if (sequence->message != WmSetScrollRangeSeq[0].message)
3356         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3357     flush_sequence();
3358
3359     si.fMask = SIF_RANGE;
3360     si.nMin = 0xdeadbeef;
3361     si.nMax = 0xdeadbeef;
3362     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3363     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3364     if (sequence->message != WmGetScrollInfoSeq[0].message)
3365         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3366     /* values of min and max are undefined */
3367     flush_sequence();
3368
3369     /* set WS_HSCROLL */
3370     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3371     /* clear WS_HSCROLL */
3372     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3373
3374     /* set WS_HSCROLL */
3375     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3376     /* clear WS_HSCROLL */
3377     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3378
3379     /* set WS_VSCROLL */
3380     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3381     /* clear WS_VSCROLL */
3382     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3383
3384     /* set WS_VSCROLL */
3385     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3386     /* clear WS_VSCROLL */
3387     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3388 }
3389
3390 static void test_showwindow(void)
3391 {
3392     HWND hwnd, hchild;
3393     RECT rc;
3394
3395     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3396                            100, 100, 200, 200, 0, 0, 0, NULL);
3397     ok (hwnd != 0, "Failed to create overlapped window\n");
3398     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3399                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3400     ok (hchild != 0, "Failed to create child\n");
3401     flush_sequence();
3402
3403     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3404     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3405     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3406     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3407     trace("done\n");
3408
3409     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3410     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3411     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3412     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3413     trace("done\n");
3414     /* back to invisible */
3415     ShowWindow(hchild, SW_HIDE);
3416     ShowWindow(hwnd, SW_HIDE);
3417     flush_sequence();
3418     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3419     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3420     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3421     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3422     trace("done\n");
3423     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3424     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3425     flush_sequence();
3426     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3427     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3428     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3429     trace("done\n");
3430     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3431     ShowWindow( hwnd, SW_SHOW);
3432     flush_sequence();
3433     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3434     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3435     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3436     trace("done\n");
3437
3438     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3439     ShowWindow( hchild, SW_HIDE);
3440     flush_sequence();
3441     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3442     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3443     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3444     trace("done\n");
3445
3446     SetCapture(hchild);
3447     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3448     DestroyWindow(hchild);
3449     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3450
3451     DestroyWindow(hwnd);
3452     flush_sequence();
3453
3454     /* Popup windows */
3455     /* Test 1:
3456      * 1. Create invisible maximized popup window.
3457      * 2. Move and resize it.
3458      * 3. Show it maximized.
3459      */
3460     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3461     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3462                            100, 100, 200, 200, 0, 0, 0, NULL);
3463     ok (hwnd != 0, "Failed to create popup window\n");
3464     ok(IsZoomed(hwnd), "window should be maximized\n");
3465     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3466     trace("done\n");
3467
3468     GetWindowRect(hwnd, &rc);
3469     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3470         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3471         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3472         rc.left, rc.top, rc.right, rc.bottom);
3473     /* Reset window's size & position */
3474     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3475     ok(IsZoomed(hwnd), "window should be maximized\n");
3476     flush_sequence();
3477
3478     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3479     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3480     ok(IsZoomed(hwnd), "window should be maximized\n");
3481     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3482     trace("done\n");
3483
3484     GetWindowRect(hwnd, &rc);
3485     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3486         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3487         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3488         rc.left, rc.top, rc.right, rc.bottom);
3489     DestroyWindow(hwnd);
3490     flush_sequence();
3491
3492     /* Test 2:
3493      * 1. Create invisible maximized popup window.
3494      * 2. Show it maximized.
3495      */
3496     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3497     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3498                            100, 100, 200, 200, 0, 0, 0, NULL);
3499     ok (hwnd != 0, "Failed to create popup window\n");
3500     ok(IsZoomed(hwnd), "window should be maximized\n");
3501     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3502     trace("done\n");
3503
3504     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3505     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3506     ok(IsZoomed(hwnd), "window should be maximized\n");
3507     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3508     trace("done\n");
3509     DestroyWindow(hwnd);
3510     flush_sequence();
3511
3512     /* Test 3:
3513      * 1. Create visible maximized popup window.
3514      */
3515     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3516     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3517                            100, 100, 200, 200, 0, 0, 0, NULL);
3518     ok (hwnd != 0, "Failed to create popup window\n");
3519     ok(IsZoomed(hwnd), "window should be maximized\n");
3520     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3521     trace("done\n");
3522     DestroyWindow(hwnd);
3523     flush_sequence();
3524
3525     /* Test 4:
3526      * 1. Create visible popup window.
3527      * 2. Maximize it.
3528      */
3529     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3530     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3531                            100, 100, 200, 200, 0, 0, 0, NULL);
3532     ok (hwnd != 0, "Failed to create popup window\n");
3533     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3534     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", TRUE);
3535     trace("done\n");
3536
3537     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3538     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3539     ok(IsZoomed(hwnd), "window should be maximized\n");
3540     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3541     trace("done\n");
3542     DestroyWindow(hwnd);
3543     flush_sequence();
3544 }
3545
3546 static void test_sys_menu(void)
3547 {
3548     HWND hwnd;
3549     HMENU hmenu;
3550     UINT state;
3551
3552     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3553                            100, 100, 200, 200, 0, 0, 0, NULL);
3554     ok (hwnd != 0, "Failed to create overlapped window\n");
3555
3556     flush_sequence();
3557
3558     /* test existing window without CS_NOCLOSE style */
3559     hmenu = GetSystemMenu(hwnd, FALSE);
3560     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3561
3562     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3563     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3564     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3565
3566     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3567     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3568
3569     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3570     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3571     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3572
3573     EnableMenuItem(hmenu, SC_CLOSE, 0);
3574     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3575
3576     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3577     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3578     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3579
3580     /* test whether removing WS_SYSMENU destroys a system menu */
3581     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
3582     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3583     flush_sequence();
3584     hmenu = GetSystemMenu(hwnd, FALSE);
3585     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3586
3587     DestroyWindow(hwnd);
3588
3589     /* test new window with CS_NOCLOSE style */
3590     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3591                            100, 100, 200, 200, 0, 0, 0, NULL);
3592     ok (hwnd != 0, "Failed to create overlapped window\n");
3593
3594     hmenu = GetSystemMenu(hwnd, FALSE);
3595     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3596
3597     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3598     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3599
3600     DestroyWindow(hwnd);
3601
3602     /* test new window without WS_SYSMENU style */
3603     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
3604                            100, 100, 200, 200, 0, 0, 0, NULL);
3605     ok(hwnd != 0, "Failed to create overlapped window\n");
3606
3607     hmenu = GetSystemMenu(hwnd, FALSE);
3608     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
3609
3610     DestroyWindow(hwnd);
3611 }
3612
3613 /* For shown WS_OVERLAPPEDWINDOW */
3614 static const struct message WmSetIcon_1[] = {
3615     { WM_SETICON, sent },
3616     { 0x00AE, sent|defwinproc|optional }, /* XP */
3617     { WM_GETTEXT, sent|defwinproc|optional },
3618     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
3619     { 0 }
3620 };
3621
3622 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
3623 static const struct message WmSetIcon_2[] = {
3624     { WM_SETICON, sent },
3625     { 0 }
3626 };
3627
3628 /* test if we receive the right sequence of messages */
3629 static void test_messages(void)
3630 {
3631     HWND hwnd, hparent, hchild;
3632     HWND hchild2, hbutton;
3633     HMENU hmenu;
3634     MSG msg;
3635     DWORD ret;
3636
3637     flush_sequence();
3638
3639     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3640                            100, 100, 200, 200, 0, 0, 0, NULL);
3641     ok (hwnd != 0, "Failed to create overlapped window\n");
3642     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3643
3644     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
3645     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
3646     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
3647
3648     /* test WM_SETREDRAW on a not visible top level window */
3649     test_WM_SETREDRAW(hwnd);
3650
3651     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3652     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
3653     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
3654
3655     ok(GetActiveWindow() == hwnd, "window should be active\n");
3656     ok(GetFocus() == hwnd, "window should have input focus\n");
3657     ShowWindow(hwnd, SW_HIDE);
3658     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
3659
3660     ShowWindow(hwnd, SW_SHOW);
3661     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
3662
3663     ShowWindow(hwnd, SW_HIDE);
3664     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
3665
3666     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3667     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
3668
3669     ShowWindow(hwnd, SW_RESTORE);
3670     /* FIXME: add ok_sequence() here */
3671     flush_sequence();
3672
3673     ShowWindow(hwnd, SW_SHOW);
3674     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
3675
3676     ok(GetActiveWindow() == hwnd, "window should be active\n");
3677     ok(GetFocus() == hwnd, "window should have input focus\n");
3678     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3679     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
3680     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
3681     ok(GetActiveWindow() == hwnd, "window should still be active\n");
3682
3683     /* test WM_SETREDRAW on a visible top level window */
3684     ShowWindow(hwnd, SW_SHOW);
3685     test_WM_SETREDRAW(hwnd);
3686
3687     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
3688     test_scroll_messages(hwnd);
3689
3690     /* test resizing and moving */
3691     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
3692     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
3693     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
3694     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
3695
3696     /* popups don't get WM_GETMINMAXINFO */
3697     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
3698     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3699     flush_sequence();
3700     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
3701     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
3702
3703     DestroyWindow(hwnd);
3704     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
3705
3706     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3707                               100, 100, 200, 200, 0, 0, 0, NULL);
3708     ok (hparent != 0, "Failed to create parent window\n");
3709     flush_sequence();
3710
3711     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
3712                              0, 0, 10, 10, hparent, 0, 0, NULL);
3713     ok (hchild != 0, "Failed to create child window\n");
3714     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
3715     DestroyWindow(hchild);
3716     flush_sequence();
3717
3718     /* visible child window with a caption */
3719     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
3720                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
3721                              0, 0, 10, 10, hparent, 0, 0, NULL);
3722     ok (hchild != 0, "Failed to create child window\n");
3723     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
3724
3725     trace("testing scroll APIs on a visible child window %p\n", hchild);
3726     test_scroll_messages(hchild);
3727
3728     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3729     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
3730
3731     DestroyWindow(hchild);
3732     flush_sequence();
3733
3734     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3735                              0, 0, 10, 10, hparent, 0, 0, NULL);
3736     ok (hchild != 0, "Failed to create child window\n");
3737     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3738     
3739     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
3740                                100, 100, 50, 50, hparent, 0, 0, NULL);
3741     ok (hchild2 != 0, "Failed to create child2 window\n");
3742     flush_sequence();
3743
3744     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
3745                               0, 100, 50, 50, hchild, 0, 0, NULL);
3746     ok (hbutton != 0, "Failed to create button window\n");
3747
3748     /* test WM_SETREDRAW on a not visible child window */
3749     test_WM_SETREDRAW(hchild);
3750
3751     ShowWindow(hchild, SW_SHOW);
3752     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3753
3754     ShowWindow(hchild, SW_HIDE);
3755     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
3756
3757     ShowWindow(hchild, SW_SHOW);
3758     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3759
3760     /* test WM_SETREDRAW on a visible child window */
3761     test_WM_SETREDRAW(hchild);
3762
3763     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
3764     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
3765
3766     ShowWindow(hchild, SW_HIDE);
3767     flush_sequence();
3768     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3769     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
3770
3771     ShowWindow(hchild, SW_HIDE);
3772     flush_sequence();
3773     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
3774     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
3775
3776     /* DestroyWindow sequence below expects that a child has focus */
3777     SetFocus(hchild);
3778     flush_sequence();
3779
3780     DestroyWindow(hchild);
3781     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
3782     DestroyWindow(hchild2);
3783     DestroyWindow(hbutton);
3784
3785     flush_sequence();
3786     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
3787                              0, 0, 100, 100, hparent, 0, 0, NULL);
3788     ok (hchild != 0, "Failed to create child popup window\n");
3789     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
3790     DestroyWindow(hchild);
3791
3792     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
3793     flush_sequence();
3794     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
3795                              0, 0, 100, 100, hparent, 0, 0, NULL);
3796     ok (hchild != 0, "Failed to create popup window\n");
3797     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3798     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3799     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3800     flush_sequence();
3801     ShowWindow(hchild, SW_SHOW);
3802     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3803     flush_sequence();
3804     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3805     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3806     flush_sequence();
3807     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3808     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
3809     DestroyWindow(hchild);
3810
3811     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
3812      * changes nothing in message sequences.
3813      */
3814     flush_sequence();
3815     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
3816                              0, 0, 100, 100, hparent, 0, 0, NULL);
3817     ok (hchild != 0, "Failed to create popup window\n");
3818     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3819     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3820     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3821     flush_sequence();
3822     ShowWindow(hchild, SW_SHOW);
3823     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3824     flush_sequence();
3825     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3826     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3827     DestroyWindow(hchild);
3828
3829     flush_sequence();
3830     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
3831                            0, 0, 100, 100, hparent, 0, 0, NULL);
3832     ok(hwnd != 0, "Failed to create custom dialog window\n");
3833     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
3834
3835     /*
3836     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
3837     test_scroll_messages(hwnd);
3838     */
3839
3840     flush_sequence();
3841
3842     test_def_id = 1;
3843     SendMessage(hwnd, WM_NULL, 0, 0);
3844
3845     flush_sequence();
3846     after_end_dialog = 1;
3847     EndDialog( hwnd, 0 );
3848     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
3849
3850     DestroyWindow(hwnd);
3851     after_end_dialog = 0;
3852     test_def_id = 0;
3853
3854     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
3855                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
3856     ok(hwnd != 0, "Failed to create custom dialog window\n");
3857     flush_sequence();
3858     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
3859     ShowWindow(hwnd, SW_SHOW);
3860     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
3861     DestroyWindow(hwnd);
3862
3863     flush_sequence();
3864     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
3865     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
3866
3867     DestroyWindow(hparent);
3868     flush_sequence();
3869
3870     /* Message sequence for SetMenu */
3871     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
3872     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
3873
3874     hmenu = CreateMenu();
3875     ok (hmenu != 0, "Failed to create menu\n");
3876     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
3877     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3878                            100, 100, 200, 200, 0, hmenu, 0, NULL);
3879     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3880     ok (SetMenu(hwnd, 0), "SetMenu\n");
3881     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
3882     ok (SetMenu(hwnd, 0), "SetMenu\n");
3883     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
3884     ShowWindow(hwnd, SW_SHOW);
3885     UpdateWindow( hwnd );
3886     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3887     flush_sequence();
3888     ok (SetMenu(hwnd, 0), "SetMenu\n");
3889     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
3890     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
3891     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
3892
3893     UpdateWindow( hwnd );
3894     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3895     flush_sequence();
3896     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
3897     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3898     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
3899
3900     DestroyWindow(hwnd);
3901     flush_sequence();
3902
3903     /* Message sequence for EnableWindow */
3904     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3905                               100, 100, 200, 200, 0, 0, 0, NULL);
3906     ok (hparent != 0, "Failed to create parent window\n");
3907     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
3908                              0, 0, 10, 10, hparent, 0, 0, NULL);
3909     ok (hchild != 0, "Failed to create child window\n");
3910
3911     SetFocus(hchild);
3912     flush_events();
3913     flush_sequence();
3914
3915     EnableWindow(hparent, FALSE);
3916     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
3917
3918     EnableWindow(hparent, TRUE);
3919     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
3920
3921     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3922     flush_sequence();
3923
3924     /* MsgWaitForMultipleObjects test */
3925     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3926     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3927
3928     PostMessageA(hparent, WM_USER, 0, 0);
3929
3930     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3931     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3932
3933     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3934     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3935
3936     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3937     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3938     /* end of MsgWaitForMultipleObjects test */
3939
3940     /* the following test causes an exception in user.exe under win9x */
3941     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
3942     {
3943         DestroyWindow(hparent);
3944         flush_sequence();
3945         return;
3946     }
3947     PostMessageW( hparent, WM_USER+1, 0, 0 );
3948     /* PeekMessage(NULL) fails, but still removes the message */
3949     SetLastError(0xdeadbeef);
3950     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
3951     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
3952         GetLastError() == 0xdeadbeef, /* NT4 */
3953         "last error is %d\n", GetLastError() );
3954     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
3955     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
3956
3957     DestroyWindow(hchild);
3958     DestroyWindow(hparent);
3959     flush_sequence();
3960
3961     /* Message sequences for WM_SETICON */
3962     trace("testing WM_SETICON\n");
3963     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3964                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
3965                            NULL, NULL, 0);
3966     ShowWindow(hwnd, SW_SHOW);
3967     UpdateWindow(hwnd);
3968     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3969     flush_sequence();
3970     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
3971     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
3972
3973     ShowWindow(hwnd, SW_HIDE);
3974     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3975     flush_sequence();
3976     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
3977     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
3978     DestroyWindow(hwnd);
3979     flush_sequence();
3980
3981     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
3982                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
3983                            NULL, NULL, 0);
3984     ShowWindow(hwnd, SW_SHOW);
3985     UpdateWindow(hwnd);
3986     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3987     flush_sequence();
3988     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
3989     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
3990
3991     ShowWindow(hwnd, SW_HIDE);
3992     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3993     flush_sequence();
3994     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
3995     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
3996     DestroyWindow(hwnd);
3997     flush_sequence();
3998 }
3999
4000 static void invisible_parent_tests(void)
4001 {
4002     HWND hparent, hchild;
4003
4004     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4005                               100, 100, 200, 200, 0, 0, 0, NULL);
4006     ok (hparent != 0, "Failed to create parent window\n");
4007     flush_sequence();
4008
4009     /* test showing child with hidden parent */
4010
4011     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4012                              0, 0, 10, 10, hparent, 0, 0, NULL);
4013     ok (hchild != 0, "Failed to create child window\n");
4014     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4015
4016     ShowWindow( hchild, SW_MINIMIZE );
4017     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4018     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4019     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4020
4021     /* repeat */
4022     flush_events();
4023     flush_sequence();
4024     ShowWindow( hchild, SW_MINIMIZE );
4025     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4026
4027     DestroyWindow(hchild);
4028     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4029                              0, 0, 10, 10, hparent, 0, 0, NULL);
4030     flush_sequence();
4031
4032     ShowWindow( hchild, SW_MAXIMIZE );
4033     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4034     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4035     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4036
4037     /* repeat */
4038     flush_events();
4039     flush_sequence();
4040     ShowWindow( hchild, SW_MAXIMIZE );
4041     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4042
4043     DestroyWindow(hchild);
4044     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4045                              0, 0, 10, 10, hparent, 0, 0, NULL);
4046     flush_sequence();
4047
4048     ShowWindow( hchild, SW_RESTORE );
4049     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4050     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4051     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4052
4053     DestroyWindow(hchild);
4054     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4055                              0, 0, 10, 10, hparent, 0, 0, NULL);
4056     flush_sequence();
4057
4058     ShowWindow( hchild, SW_SHOWMINIMIZED );
4059     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4060     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4061     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4062
4063     /* repeat */
4064     flush_events();
4065     flush_sequence();
4066     ShowWindow( hchild, SW_SHOWMINIMIZED );
4067     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4068
4069     DestroyWindow(hchild);
4070     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4071                              0, 0, 10, 10, hparent, 0, 0, NULL);
4072     flush_sequence();
4073
4074     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4075     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4076     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4077     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4078     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4079
4080     DestroyWindow(hchild);
4081     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4082                              0, 0, 10, 10, hparent, 0, 0, NULL);
4083     flush_sequence();
4084
4085     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4086     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4087     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4088     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4089
4090     /* repeat */
4091     flush_events();
4092     flush_sequence();
4093     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4094     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4095
4096     DestroyWindow(hchild);
4097     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4098                              0, 0, 10, 10, hparent, 0, 0, NULL);
4099     flush_sequence();
4100
4101     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4102     ShowWindow( hchild, SW_FORCEMINIMIZE );
4103     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4104 todo_wine {
4105     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4106 }
4107     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4108
4109     DestroyWindow(hchild);
4110     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4111                              0, 0, 10, 10, hparent, 0, 0, NULL);
4112     flush_sequence();
4113
4114     ShowWindow( hchild, SW_SHOWNA );
4115     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4116     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4117     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4118
4119     /* repeat */
4120     flush_events();
4121     flush_sequence();
4122     ShowWindow( hchild, SW_SHOWNA );
4123     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4124
4125     DestroyWindow(hchild);
4126     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4127                              0, 0, 10, 10, hparent, 0, 0, NULL);
4128     flush_sequence();
4129
4130     ShowWindow( hchild, SW_SHOW );
4131     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4132     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4133     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4134
4135     /* repeat */
4136     flush_events();
4137     flush_sequence();
4138     ShowWindow( hchild, SW_SHOW );
4139     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4140
4141     ShowWindow( hchild, SW_HIDE );
4142     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4143     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4144     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4145
4146     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4147     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4148     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4149     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4150
4151     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4152     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4153     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4154     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4155
4156     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4157     flush_sequence();
4158     DestroyWindow(hchild);
4159     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4160
4161     DestroyWindow(hparent);
4162     flush_sequence();
4163 }
4164
4165 /****************** button message test *************************/
4166 static const struct message WmSetFocusButtonSeq[] =
4167 {
4168     { HCBT_SETFOCUS, hook },
4169     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4170     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4171     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4172     { WM_SETFOCUS, sent|wparam, 0 },
4173     { WM_CTLCOLORBTN, sent|defwinproc },
4174     { 0 }
4175 };
4176 static const struct message WmKillFocusButtonSeq[] =
4177 {
4178     { HCBT_SETFOCUS, hook },
4179     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4180     { WM_KILLFOCUS, sent|wparam, 0 },
4181     { WM_CTLCOLORBTN, sent|defwinproc },
4182     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4183     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4184     { 0 }
4185 };
4186 static const struct message WmSetFocusStaticSeq[] =
4187 {
4188     { HCBT_SETFOCUS, hook },
4189     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4190     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4191     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4192     { WM_SETFOCUS, sent|wparam, 0 },
4193     { WM_CTLCOLORSTATIC, sent|defwinproc },
4194     { 0 }
4195 };
4196 static const struct message WmKillFocusStaticSeq[] =
4197 {
4198     { HCBT_SETFOCUS, hook },
4199     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4200     { WM_KILLFOCUS, sent|wparam, 0 },
4201     { WM_CTLCOLORSTATIC, sent|defwinproc },
4202     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4203     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4204     { 0 }
4205 };
4206 static const struct message WmLButtonDownSeq[] =
4207 {
4208     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4209     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4210     { HCBT_SETFOCUS, hook },
4211     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4212     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4213     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4214     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4215     { WM_CTLCOLORBTN, sent|defwinproc },
4216     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4217     { WM_CTLCOLORBTN, sent|defwinproc },
4218     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4219     { 0 }
4220 };
4221 static const struct message WmLButtonUpSeq[] =
4222 {
4223     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4224     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4225     { WM_CTLCOLORBTN, sent|defwinproc },
4226     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4227     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4228     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4229     { 0 }
4230 };
4231 static const struct message WmSetFontButtonSeq[] =
4232 {
4233     { WM_SETFONT, sent },
4234     { WM_PAINT, sent },
4235     { WM_ERASEBKGND, sent|defwinproc|optional },
4236     { WM_CTLCOLORBTN, sent|defwinproc },
4237     { 0 }
4238 };
4239
4240 static WNDPROC old_button_proc;
4241
4242 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4243 {
4244     static long defwndproc_counter = 0;
4245     LRESULT ret;
4246     struct message msg;
4247
4248     trace("button: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4249
4250     /* explicitly ignore WM_GETICON message */
4251     if (message == WM_GETICON) return 0;
4252
4253     msg.message = message;
4254     msg.flags = sent|wparam|lparam;
4255     if (defwndproc_counter) msg.flags |= defwinproc;
4256     msg.wParam = wParam;
4257     msg.lParam = lParam;
4258     add_message(&msg);
4259
4260     if (message == BM_SETSTATE)
4261         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4262
4263     defwndproc_counter++;
4264     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4265     defwndproc_counter--;
4266
4267     return ret;
4268 }
4269
4270 static void subclass_button(void)
4271 {
4272     WNDCLASSA cls;
4273
4274     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4275
4276     old_button_proc = cls.lpfnWndProc;
4277
4278     cls.hInstance = GetModuleHandle(0);
4279     cls.lpfnWndProc = button_hook_proc;
4280     cls.lpszClassName = "my_button_class";
4281     UnregisterClass(cls.lpszClassName, cls.hInstance);
4282     if (!RegisterClassA(&cls)) assert(0);
4283 }
4284
4285 static void test_button_messages(void)
4286 {
4287     static const struct
4288     {
4289         DWORD style;
4290         DWORD dlg_code;
4291         const struct message *setfocus;
4292         const struct message *killfocus;
4293     } button[] = {
4294         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4295           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4296         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4297           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4298         { BS_CHECKBOX, DLGC_BUTTON,
4299           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4300         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4301           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4302         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4303           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4304         { BS_3STATE, DLGC_BUTTON,
4305           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4306         { BS_AUTO3STATE, DLGC_BUTTON,
4307           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4308         { BS_GROUPBOX, DLGC_STATIC,
4309           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4310         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4311           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4312         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4313           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4314         { BS_OWNERDRAW, DLGC_BUTTON,
4315           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4316     };
4317     unsigned int i;
4318     HWND hwnd;
4319     DWORD dlg_code;
4320     HFONT zfont;
4321
4322     subclass_button();
4323
4324     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4325     {
4326         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4327                                0, 0, 50, 14, 0, 0, 0, NULL);
4328         ok(hwnd != 0, "Failed to create button window\n");
4329
4330         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4331         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4332
4333         ShowWindow(hwnd, SW_SHOW);
4334         UpdateWindow(hwnd);
4335         SetFocus(0);
4336         flush_sequence();
4337
4338         trace("button style %08x\n", button[i].style);
4339         SetFocus(hwnd);
4340         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4341
4342         SetFocus(0);
4343         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4344
4345         DestroyWindow(hwnd);
4346     }
4347
4348     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4349                            0, 0, 50, 14, 0, 0, 0, NULL);
4350     ok(hwnd != 0, "Failed to create button window\n");
4351
4352     SetFocus(0);
4353     flush_sequence();
4354
4355     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4356     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4357
4358     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4359     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4360
4361     flush_sequence();
4362     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4363     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4364     UpdateWindow(hwnd);
4365     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4366
4367     DestroyWindow(hwnd);
4368 }
4369
4370 /****************** static message test *************************/
4371 static const struct message WmSetFontStaticSeq[] =
4372 {
4373     { WM_SETFONT, sent },
4374     { WM_PAINT, sent|defwinproc },
4375     { WM_ERASEBKGND, sent|defwinproc|optional },
4376     { WM_CTLCOLORSTATIC, sent|defwinproc },
4377     { 0 }
4378 };
4379
4380 static WNDPROC old_static_proc;
4381
4382 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4383 {
4384     static long defwndproc_counter = 0;
4385     LRESULT ret;
4386     struct message msg;
4387
4388     trace("static: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4389
4390     /* explicitly ignore WM_GETICON message */
4391     if (message == WM_GETICON) return 0;
4392
4393     msg.message = message;
4394     msg.flags = sent|wparam|lparam;
4395     if (defwndproc_counter) msg.flags |= defwinproc;
4396     msg.wParam = wParam;
4397     msg.lParam = lParam;
4398     add_message(&msg);
4399
4400
4401     defwndproc_counter++;
4402     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
4403     defwndproc_counter--;
4404
4405     return ret;
4406 }
4407
4408 static void subclass_static(void)
4409 {
4410     WNDCLASSA cls;
4411
4412     if (!GetClassInfoA(0, "static", &cls)) assert(0);
4413
4414     old_static_proc = cls.lpfnWndProc;
4415
4416     cls.hInstance = GetModuleHandle(0);
4417     cls.lpfnWndProc = static_hook_proc;
4418     cls.lpszClassName = "my_static_class";
4419     UnregisterClass(cls.lpszClassName, cls.hInstance);
4420     if (!RegisterClassA(&cls)) assert(0);
4421 }
4422
4423 static void test_static_messages(void)
4424 {
4425     /* FIXME: make as comprehensive as the button message test */
4426     static const struct
4427     {
4428         DWORD style;
4429         DWORD dlg_code;
4430         const struct message *setfont;
4431     } static_ctrl[] = {
4432         { SS_LEFT, DLGC_STATIC,
4433           WmSetFontStaticSeq }
4434     };
4435     unsigned int i;
4436     HWND hwnd;
4437     DWORD dlg_code;
4438
4439     subclass_static();
4440
4441     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
4442     {
4443         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
4444                                0, 0, 50, 14, 0, 0, 0, NULL);
4445         ok(hwnd != 0, "Failed to create static window\n");
4446
4447         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4448         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4449
4450         ShowWindow(hwnd, SW_SHOW);
4451         UpdateWindow(hwnd);
4452         SetFocus(0);
4453         flush_sequence();
4454
4455         trace("static style %08x\n", static_ctrl[i].style);
4456         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
4457         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
4458
4459         DestroyWindow(hwnd);
4460     }
4461 }
4462
4463 /************* painting message test ********************/
4464
4465 void dump_region(HRGN hrgn)
4466 {
4467     DWORD i, size;
4468     RGNDATA *data = NULL;
4469     RECT *rect;
4470
4471     if (!hrgn)
4472     {
4473         printf( "null region\n" );
4474         return;
4475     }
4476     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
4477     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
4478     GetRegionData( hrgn, size, data );
4479     printf("%d rects:", data->rdh.nCount );
4480     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
4481         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
4482     printf("\n");
4483     HeapFree( GetProcessHeap(), 0, data );
4484 }
4485
4486 static void check_update_rgn( HWND hwnd, HRGN hrgn )
4487 {
4488     INT ret;
4489     RECT r1, r2;
4490     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
4491     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
4492
4493     ret = GetUpdateRgn( hwnd, update, FALSE );
4494     ok( ret != ERROR, "GetUpdateRgn failed\n" );
4495     if (ret == NULLREGION)
4496     {
4497         ok( !hrgn, "Update region shouldn't be empty\n" );
4498     }
4499     else
4500     {
4501         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
4502         {
4503             ok( 0, "Regions are different\n" );
4504             if (winetest_debug > 0)
4505             {
4506                 printf( "Update region: " );
4507                 dump_region( update );
4508                 printf( "Wanted region: " );
4509                 dump_region( hrgn );
4510             }
4511         }
4512     }
4513     GetRgnBox( update, &r1 );
4514     GetUpdateRect( hwnd, &r2, FALSE );
4515     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
4516         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
4517         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
4518
4519     DeleteObject( tmp );
4520     DeleteObject( update );
4521 }
4522
4523 static const struct message WmInvalidateRgn[] = {
4524     { WM_NCPAINT, sent },
4525     { WM_GETTEXT, sent|defwinproc|optional },
4526     { 0 }
4527 };
4528
4529 static const struct message WmGetUpdateRect[] = {
4530     { WM_NCPAINT, sent },
4531     { WM_GETTEXT, sent|defwinproc|optional },
4532     { WM_PAINT, sent },
4533     { 0 }
4534 };
4535
4536 static const struct message WmInvalidateFull[] = {
4537     { WM_NCPAINT, sent|wparam, 1 },
4538     { WM_GETTEXT, sent|defwinproc|optional },
4539     { 0 }
4540 };
4541
4542 static const struct message WmInvalidateErase[] = {
4543     { WM_NCPAINT, sent|wparam, 1 },
4544     { WM_GETTEXT, sent|defwinproc|optional },
4545     { WM_ERASEBKGND, sent },
4546     { 0 }
4547 };
4548
4549 static const struct message WmInvalidatePaint[] = {
4550     { WM_PAINT, sent },
4551     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4552     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4553     { 0 }
4554 };
4555
4556 static const struct message WmInvalidateErasePaint[] = {
4557     { WM_PAINT, sent },
4558     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4559     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4560     { WM_ERASEBKGND, sent|beginpaint },
4561     { 0 }
4562 };
4563
4564 static const struct message WmInvalidateErasePaint2[] = {
4565     { WM_PAINT, sent },
4566     { WM_NCPAINT, sent|beginpaint },
4567     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4568     { WM_ERASEBKGND, sent|beginpaint },
4569     { 0 }
4570 };
4571
4572 static const struct message WmErase[] = {
4573     { WM_ERASEBKGND, sent },
4574     { 0 }
4575 };
4576
4577 static const struct message WmPaint[] = {
4578     { WM_PAINT, sent },
4579     { 0 }
4580 };
4581
4582 static const struct message WmParentOnlyPaint[] = {
4583     { WM_PAINT, sent|parent },
4584     { 0 }
4585 };
4586
4587 static const struct message WmInvalidateParent[] = {
4588     { WM_NCPAINT, sent|parent },
4589     { WM_GETTEXT, sent|defwinproc|parent|optional },
4590     { WM_ERASEBKGND, sent|parent },
4591     { 0 }
4592 };
4593
4594 static const struct message WmInvalidateParentChild[] = {
4595     { WM_NCPAINT, sent|parent },
4596     { WM_GETTEXT, sent|defwinproc|parent|optional },
4597     { WM_ERASEBKGND, sent|parent },
4598     { WM_NCPAINT, sent },
4599     { WM_GETTEXT, sent|defwinproc|optional },
4600     { WM_ERASEBKGND, sent },
4601     { 0 }
4602 };
4603
4604 static const struct message WmInvalidateParentChild2[] = {
4605     { WM_ERASEBKGND, sent|parent },
4606     { WM_NCPAINT, sent },
4607     { WM_GETTEXT, sent|defwinproc|optional },
4608     { WM_ERASEBKGND, sent },
4609     { 0 }
4610 };
4611
4612 static const struct message WmParentPaint[] = {
4613     { WM_PAINT, sent|parent },
4614     { WM_PAINT, sent },
4615     { 0 }
4616 };
4617
4618 static const struct message WmParentPaintNc[] = {
4619     { WM_PAINT, sent|parent },
4620     { WM_PAINT, sent },
4621     { WM_NCPAINT, sent|beginpaint },
4622     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4623     { WM_ERASEBKGND, sent|beginpaint },
4624     { 0 }
4625 };
4626
4627 static const struct message WmChildPaintNc[] = {
4628     { WM_PAINT, sent },
4629     { WM_NCPAINT, sent|beginpaint },
4630     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4631     { WM_ERASEBKGND, sent|beginpaint },
4632     { 0 }
4633 };
4634
4635 static const struct message WmParentErasePaint[] = {
4636     { WM_PAINT, sent|parent },
4637     { WM_NCPAINT, sent|parent|beginpaint },
4638     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
4639     { WM_ERASEBKGND, sent|parent|beginpaint },
4640     { WM_PAINT, sent },
4641     { WM_NCPAINT, sent|beginpaint },
4642     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4643     { WM_ERASEBKGND, sent|beginpaint },
4644     { 0 }
4645 };
4646
4647 static const struct message WmParentOnlyNcPaint[] = {
4648     { WM_PAINT, sent|parent },
4649     { WM_NCPAINT, sent|parent|beginpaint },
4650     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
4651     { 0 }
4652 };
4653
4654 static const struct message WmSetParentStyle[] = {
4655     { WM_STYLECHANGING, sent|parent },
4656     { WM_STYLECHANGED, sent|parent },
4657     { 0 }
4658 };
4659
4660 static void test_paint_messages(void)
4661 {
4662     BOOL ret;
4663     RECT rect;
4664     POINT pt;
4665     MSG msg;
4666     HWND hparent, hchild;
4667     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4668     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
4669     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4670                                 100, 100, 200, 200, 0, 0, 0, NULL);
4671     ok (hwnd != 0, "Failed to create overlapped window\n");
4672
4673     ShowWindow( hwnd, SW_SHOW );
4674     UpdateWindow( hwnd );
4675     flush_events();
4676     flush_sequence();
4677
4678     check_update_rgn( hwnd, 0 );
4679     SetRectRgn( hrgn, 10, 10, 20, 20 );
4680     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
4681     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4682     check_update_rgn( hwnd, hrgn );
4683     SetRectRgn( hrgn2, 20, 20, 30, 30 );
4684     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
4685     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4686     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
4687     check_update_rgn( hwnd, hrgn );
4688     /* validate everything */
4689     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4690     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4691     check_update_rgn( hwnd, 0 );
4692
4693     /* test empty region */
4694     SetRectRgn( hrgn, 10, 10, 10, 15 );
4695     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
4696     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4697     check_update_rgn( hwnd, 0 );
4698     /* test empty rect */
4699     SetRect( &rect, 10, 10, 10, 15 );
4700     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
4701     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4702     check_update_rgn( hwnd, 0 );
4703
4704     /* flush pending messages */
4705     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4706     flush_sequence();
4707
4708     GetClientRect( hwnd, &rect );
4709     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
4710     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
4711      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
4712      */
4713     trace("testing InvalidateRect(0, NULL, FALSE)\n");
4714     SetRectEmpty( &rect );
4715     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
4716     check_update_rgn( hwnd, hrgn );
4717     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
4718     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4719     ok_sequence( WmPaint, "Paint", FALSE );
4720     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4721     check_update_rgn( hwnd, 0 );
4722
4723     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
4724      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
4725      */
4726     trace("testing ValidateRect(0, NULL)\n");
4727     SetRectEmpty( &rect );
4728     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
4729     check_update_rgn( hwnd, hrgn );
4730     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
4731     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4732     ok_sequence( WmPaint, "Paint", FALSE );
4733     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4734     check_update_rgn( hwnd, 0 );
4735
4736     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
4737     SetLastError(0xdeadbeef);
4738     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
4739     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
4740     check_update_rgn( hwnd, 0 );
4741     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4742     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
4743
4744     trace("testing ValidateRgn(0, NULL)\n");
4745     SetLastError(0xdeadbeef);
4746     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
4747     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
4748     check_update_rgn( hwnd, 0 );
4749     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4750     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
4751
4752     /* now with frame */
4753     SetRectRgn( hrgn, -5, -5, 20, 20 );
4754
4755     /* flush pending messages */
4756     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4757
4758     flush_sequence();
4759     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
4760     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
4761
4762     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
4763     check_update_rgn( hwnd, hrgn );
4764
4765     flush_sequence();
4766     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
4767     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
4768
4769     flush_sequence();
4770     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
4771     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
4772
4773     GetClientRect( hwnd, &rect );
4774     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
4775     check_update_rgn( hwnd, hrgn );
4776
4777     flush_sequence();
4778     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
4779     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
4780
4781     flush_sequence();
4782     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
4783     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
4784     check_update_rgn( hwnd, 0 );
4785
4786     flush_sequence();
4787     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
4788     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
4789     check_update_rgn( hwnd, 0 );
4790
4791     flush_sequence();
4792     SetRectRgn( hrgn, 0, 0, 100, 100 );
4793     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
4794     SetRectRgn( hrgn, 0, 0, 50, 100 );
4795     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
4796     SetRectRgn( hrgn, 50, 0, 100, 100 );
4797     check_update_rgn( hwnd, hrgn );
4798     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
4799     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
4800     check_update_rgn( hwnd, 0 );
4801
4802     flush_sequence();
4803     SetRectRgn( hrgn, 0, 0, 100, 100 );
4804     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
4805     SetRectRgn( hrgn, 0, 0, 100, 50 );
4806     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
4807     ok_sequence( WmErase, "Erase", FALSE );
4808     SetRectRgn( hrgn, 0, 50, 100, 100 );
4809     check_update_rgn( hwnd, hrgn );
4810
4811     flush_sequence();
4812     SetRectRgn( hrgn, 0, 0, 100, 100 );
4813     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
4814     SetRectRgn( hrgn, 0, 0, 50, 50 );
4815     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
4816     ok_sequence( WmPaint, "Paint", FALSE );
4817
4818     flush_sequence();
4819     SetRectRgn( hrgn, -4, -4, -2, -2 );
4820     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
4821     SetRectRgn( hrgn, -200, -200, -198, -198 );
4822     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
4823     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
4824
4825     flush_sequence();
4826     SetRectRgn( hrgn, -4, -4, -2, -2 );
4827     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
4828     SetRectRgn( hrgn, -4, -4, -3, -3 );
4829     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
4830     SetRectRgn( hrgn, 0, 0, 1, 1 );
4831     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
4832     ok_sequence( WmPaint, "Paint", FALSE );
4833
4834     flush_sequence();
4835     SetRectRgn( hrgn, -4, -4, -1, -1 );
4836     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
4837     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
4838     /* make sure no WM_PAINT was generated */
4839     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4840     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
4841
4842     flush_sequence();
4843     SetRectRgn( hrgn, -4, -4, -1, -1 );
4844     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
4845     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
4846     {
4847         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
4848         {
4849             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
4850             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
4851             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
4852             ret = GetUpdateRect( hwnd, &rect, FALSE );
4853             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
4854             /* this will send WM_NCPAINT and validate the non client area */
4855             ret = GetUpdateRect( hwnd, &rect, TRUE );
4856             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
4857         }
4858         DispatchMessage( &msg );
4859     }
4860     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
4861
4862     DestroyWindow( hwnd );
4863
4864     /* now test with a child window */
4865
4866     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4867                               100, 100, 200, 200, 0, 0, 0, NULL);
4868     ok (hparent != 0, "Failed to create parent window\n");
4869
4870     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
4871                            10, 10, 100, 100, hparent, 0, 0, NULL);
4872     ok (hchild != 0, "Failed to create child window\n");
4873
4874     ShowWindow( hparent, SW_SHOW );
4875     UpdateWindow( hparent );
4876     UpdateWindow( hchild );
4877     flush_events();
4878     flush_sequence();
4879     log_all_parent_messages++;
4880
4881     SetRect( &rect, 0, 0, 50, 50 );
4882     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4883     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
4884     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
4885
4886     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4887     pt.x = pt.y = 0;
4888     MapWindowPoints( hchild, hparent, &pt, 1 );
4889     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
4890     check_update_rgn( hchild, hrgn );
4891     SetRectRgn( hrgn, 0, 0, 50, 50 );
4892     check_update_rgn( hparent, hrgn );
4893     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
4894     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
4895     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
4896     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
4897
4898     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4899     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
4900
4901     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
4902     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
4903     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
4904     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
4905     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
4906
4907     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
4908     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
4909     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
4910
4911     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
4912     flush_sequence();
4913     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
4914     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
4915     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
4916
4917     /* flush all paint messages */
4918     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4919     flush_sequence();
4920
4921     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
4922     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
4923     SetRectRgn( hrgn, 0, 0, 50, 50 );
4924     check_update_rgn( hparent, hrgn );
4925     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
4926     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
4927     SetRectRgn( hrgn, 0, 0, 50, 50 );
4928     check_update_rgn( hparent, hrgn );
4929
4930     /* flush all paint messages */
4931     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4932     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
4933     flush_sequence();
4934
4935     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
4936     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4937     SetRectRgn( hrgn, 0, 0, 50, 50 );
4938     check_update_rgn( hparent, hrgn );
4939     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
4940     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
4941     SetRectRgn( hrgn2, 10, 10, 50, 50 );
4942     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
4943     check_update_rgn( hparent, hrgn );
4944     /* flush all paint messages */
4945     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4946     flush_sequence();
4947
4948     /* same as above but parent gets completely validated */
4949     SetRect( &rect, 20, 20, 30, 30 );
4950     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4951     SetRectRgn( hrgn, 20, 20, 30, 30 );
4952     check_update_rgn( hparent, hrgn );
4953     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
4954     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
4955     check_update_rgn( hparent, 0 );  /* no update region */
4956     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4957     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
4958
4959     /* make sure RDW_VALIDATE on child doesn't have the same effect */
4960     flush_sequence();
4961     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4962     SetRectRgn( hrgn, 20, 20, 30, 30 );
4963     check_update_rgn( hparent, hrgn );
4964     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
4965     SetRectRgn( hrgn, 20, 20, 30, 30 );
4966     check_update_rgn( hparent, hrgn );
4967
4968     /* same as above but normal WM_PAINT doesn't validate parent */
4969     flush_sequence();
4970     SetRect( &rect, 20, 20, 30, 30 );
4971     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4972     SetRectRgn( hrgn, 20, 20, 30, 30 );
4973     check_update_rgn( hparent, hrgn );
4974     /* no WM_PAINT in child while parent still pending */
4975     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4976     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
4977     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4978     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
4979
4980     flush_sequence();
4981     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4982     /* no WM_PAINT in child while parent still pending */
4983     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4984     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
4985     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
4986     /* now that parent is valid child should get WM_PAINT */
4987     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4988     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
4989     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4990     ok_sequence( WmEmptySeq, "No other message", FALSE );
4991
4992     /* same thing with WS_CLIPCHILDREN in parent */
4993     flush_sequence();
4994     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
4995     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
4996     /* changing style invalidates non client area, but we need to invalidate something else to see it */
4997     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
4998     ok_sequence( WmEmptySeq, "No message", FALSE );
4999     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5000     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5001
5002     flush_sequence();
5003     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5004     SetRectRgn( hrgn, 20, 20, 30, 30 );
5005     check_update_rgn( hparent, hrgn );
5006     /* no WM_PAINT in child while parent still pending */
5007     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5008     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5009     /* WM_PAINT in parent first */
5010     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5011     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5012
5013     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5014     flush_sequence();
5015     SetRect( &rect, 0, 0, 30, 30 );
5016     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5017     SetRectRgn( hrgn, 0, 0, 30, 30 );
5018     check_update_rgn( hparent, hrgn );
5019     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5020     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5021
5022     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5023     flush_sequence();
5024     SetRect( &rect, -10, 0, 30, 30 );
5025     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5026     SetRect( &rect, 0, 0, 20, 20 );
5027     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5028     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5029     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5030
5031     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5032     flush_sequence();
5033     SetRect( &rect, -10, 0, 30, 30 );
5034     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5035     SetRect( &rect, 0, 0, 100, 100 );
5036     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5037     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5038     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5039     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5040     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5041
5042     /* test RDW_INTERNALPAINT behavior */
5043
5044     flush_sequence();
5045     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5046     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5047     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5048
5049     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5050     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5051     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5052
5053     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5054     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5055     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5056
5057     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5058     UpdateWindow( hparent );
5059     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5060     flush_sequence();
5061     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5062     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5063     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5064                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5065     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5066     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5067
5068     UpdateWindow( hparent );
5069     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5070     flush_sequence();
5071     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5072     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5073     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5074                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5075     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5076     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5077
5078     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5079     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5080     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5081     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5082     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5083
5084     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5085     UpdateWindow( hparent );
5086     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5087     flush_sequence();
5088     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5089     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5090     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5091                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5092     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5093     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5094
5095     UpdateWindow( hparent );
5096     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5097     flush_sequence();
5098     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5099     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5100     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5101                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5102     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5103     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5104
5105     log_all_parent_messages--;
5106     DestroyWindow( hparent );
5107     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5108
5109     DeleteObject( hrgn );
5110     DeleteObject( hrgn2 );
5111 }
5112
5113 struct wnd_event
5114 {
5115     HWND hwnd;
5116     HANDLE event;
5117 };
5118
5119 static DWORD WINAPI thread_proc(void *param)
5120 {
5121     MSG msg;
5122     struct wnd_event *wnd_event = (struct wnd_event *)param;
5123
5124     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5125                                       100, 100, 200, 200, 0, 0, 0, NULL);
5126     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5127
5128     SetEvent(wnd_event->event);
5129
5130     while (GetMessage(&msg, 0, 0, 0))
5131     {
5132         TranslateMessage(&msg);
5133         DispatchMessage(&msg);
5134     }
5135
5136     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5137
5138     return 0;
5139 }
5140
5141 static void test_interthread_messages(void)
5142 {
5143     HANDLE hThread;
5144     DWORD tid;
5145     WNDPROC proc;
5146     MSG msg;
5147     char buf[256];
5148     int len, expected_len;
5149     struct wnd_event wnd_event;
5150     BOOL ret;
5151
5152     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
5153     if (!wnd_event.event)
5154     {
5155         trace("skipping interthread message test under win9x\n");
5156         return;
5157     }
5158
5159     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
5160     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
5161
5162     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5163
5164     CloseHandle(wnd_event.event);
5165
5166     SetLastError(0xdeadbeef);
5167     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
5168     ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %d\n", GetLastError());
5169
5170     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5171     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
5172
5173     expected_len = lstrlenA("window caption text");
5174     memset(buf, 0, sizeof(buf));
5175     SetLastError(0xdeadbeef);
5176     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
5177     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
5178     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
5179
5180     msg.hwnd = wnd_event.hwnd;
5181     msg.message = WM_GETTEXT;
5182     msg.wParam = sizeof(buf);
5183     msg.lParam = (LPARAM)buf;
5184     memset(buf, 0, sizeof(buf));
5185     SetLastError(0xdeadbeef);
5186     len = DispatchMessageA(&msg);
5187     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
5188        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
5189
5190     /* the following test causes an exception in user.exe under win9x */
5191     msg.hwnd = wnd_event.hwnd;
5192     msg.message = WM_TIMER;
5193     msg.wParam = 0;
5194     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5195     SetLastError(0xdeadbeef);
5196     len = DispatchMessageA(&msg);
5197     ok(!len && GetLastError() == 0xdeadbeef,
5198        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
5199
5200     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
5201     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
5202
5203     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5204     CloseHandle(hThread);
5205
5206     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
5207 }
5208
5209
5210 static const struct message WmVkN[] = {
5211     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5212     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5213     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5214     { WM_CHAR, wparam|lparam, 'n', 1 },
5215     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
5216     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5217     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5218     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5219     { 0 }
5220 };
5221 static const struct message WmShiftVkN[] = {
5222     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5223     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5224     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5225     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5226     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5227     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5228     { WM_CHAR, wparam|lparam, 'N', 1 },
5229     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
5230     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5231     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5232     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5233     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5234     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5235     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5236     { 0 }
5237 };
5238 static const struct message WmCtrlVkN[] = {
5239     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5240     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5241     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5242     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5243     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5244     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5245     { WM_CHAR, wparam|lparam, 0x000e, 1 },
5246     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5247     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5248     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5249     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5250     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5251     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5252     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5253     { 0 }
5254 };
5255 static const struct message WmCtrlVkN_2[] = {
5256     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5257     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5258     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5259     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5260     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5261     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5262     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5263     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5264     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5265     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5266     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5267     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5268     { 0 }
5269 };
5270 static const struct message WmAltVkN[] = {
5271     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5272     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5273     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5274     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5275     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5276     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5277     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
5278     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
5279     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
5280     { HCBT_SYSCOMMAND, hook },
5281     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5282     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5283     { 0x00AE, sent|defwinproc|optional }, /* XP */
5284     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
5285     { WM_INITMENU, sent|defwinproc },
5286     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5287     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
5288     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5289     { WM_CAPTURECHANGED, sent|defwinproc },
5290     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
5291     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5292     { WM_EXITMENULOOP, sent|defwinproc },
5293     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
5294     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
5295     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5296     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5297     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5298     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5299     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5300     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5301     { 0 }
5302 };
5303 static const struct message WmAltVkN_2[] = {
5304     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5305     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5306     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5307     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5308     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5309     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
5310     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5311     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5312     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5313     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5314     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5315     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5316     { 0 }
5317 };
5318 static const struct message WmCtrlAltVkN[] = {
5319     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5320     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5321     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5322     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5323     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5324     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5325     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5326     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5327     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5328     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5329     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5330     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5331     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5332     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5333     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5334     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5335     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5336     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5337     { 0 }
5338 };
5339 static const struct message WmCtrlShiftVkN[] = {
5340     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5341     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5342     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5343     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5344     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5345     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5346     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5347     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5348     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
5349     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5350     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5351     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5352     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5353     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5354     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5355     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5356     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5357     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5358     { 0 }
5359 };
5360 static const struct message WmCtrlAltShiftVkN[] = {
5361     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5362     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5363     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5364     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5365     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5366     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5367     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
5368     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
5369     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
5370     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5371     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5372     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
5373     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5374     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5375     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5376     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
5377     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
5378     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
5379     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5380     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5381     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5382     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5383     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5384     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5385     { 0 }
5386 };
5387 static const struct message WmAltPressRelease[] = {
5388     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5389     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5390     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5391     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5392     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5393     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5394     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
5395     { HCBT_SYSCOMMAND, hook },
5396     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5397     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5398     { WM_INITMENU, sent|defwinproc },
5399     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5400     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
5401     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5402
5403     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
5404
5405     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5406     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
5407     { WM_CAPTURECHANGED, sent|defwinproc },
5408     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
5409     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5410     { WM_EXITMENULOOP, sent|defwinproc },
5411     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5412     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5413     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5414     { 0 }
5415 };
5416 static const struct message WmAltMouseButton[] = {
5417     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5418     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5419     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5420     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
5421     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
5422     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
5423     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
5424     { WM_LBUTTONUP, wparam, 0, 0 },
5425     { WM_LBUTTONUP, sent|wparam, 0, 0 },
5426     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5427     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5428     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5429     { 0 }
5430 };
5431 static const struct message WmF1Seq[] = {
5432     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
5433     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
5434     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
5435     { 0x4d, wparam|lparam, 0, 0 },
5436     { 0x4d, sent|wparam|lparam, 0, 0 },
5437     { WM_HELP, sent|defwinproc },
5438     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
5439     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
5440     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
5441     { 0 }
5442 };
5443 static const struct message WmVkAppsSeq[] = {
5444     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
5445     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
5446     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
5447     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
5448     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
5449     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
5450     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
5451     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
5452     { 0 }
5453 };
5454
5455 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
5456 {
5457     MSG msg;
5458
5459     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5460     {
5461         struct message log_msg;
5462
5463         trace("accel: %p, %04x, %08x, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
5464
5465         /* ignore some unwanted messages */
5466         if (msg.message == WM_MOUSEMOVE ||
5467             msg.message == WM_GETICON ||
5468             msg.message == WM_DEVICECHANGE)
5469             continue;
5470
5471         log_msg.message = msg.message;
5472         log_msg.flags = wparam|lparam;
5473         log_msg.wParam = msg.wParam;
5474         log_msg.lParam = msg.lParam;
5475         add_message(&log_msg);
5476
5477         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
5478         {
5479             TranslateMessage(&msg);
5480             DispatchMessage(&msg);
5481         }
5482     }
5483 }
5484
5485 static void test_accelerators(void)
5486 {
5487     RECT rc;
5488     SHORT state;
5489     HACCEL hAccel;
5490     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5491                                 100, 100, 200, 200, 0, 0, 0, NULL);
5492     BOOL ret;
5493
5494     assert(hwnd != 0);
5495     UpdateWindow(hwnd);
5496     flush_events();
5497     flush_sequence();
5498
5499     SetFocus(hwnd);
5500     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
5501
5502     state = GetKeyState(VK_SHIFT);
5503     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
5504     state = GetKeyState(VK_CAPITAL);
5505     ok(state == 0, "wrong CapsLock state %04x\n", state);
5506
5507     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
5508     assert(hAccel != 0);
5509
5510     pump_msg_loop(hwnd, 0);
5511     flush_sequence();
5512
5513     trace("testing VK_N press/release\n");
5514     flush_sequence();
5515     keybd_event('N', 0, 0, 0);
5516     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5517     pump_msg_loop(hwnd, hAccel);
5518     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5519
5520     trace("testing Shift+VK_N press/release\n");
5521     flush_sequence();
5522     keybd_event(VK_SHIFT, 0, 0, 0);
5523     keybd_event('N', 0, 0, 0);
5524     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5525     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5526     pump_msg_loop(hwnd, hAccel);
5527     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5528
5529     trace("testing Ctrl+VK_N press/release\n");
5530     flush_sequence();
5531     keybd_event(VK_CONTROL, 0, 0, 0);
5532     keybd_event('N', 0, 0, 0);
5533     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5534     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5535     pump_msg_loop(hwnd, hAccel);
5536     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
5537
5538     trace("testing Alt+VK_N press/release\n");
5539     flush_sequence();
5540     keybd_event(VK_MENU, 0, 0, 0);
5541     keybd_event('N', 0, 0, 0);
5542     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5543     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5544     pump_msg_loop(hwnd, hAccel);
5545     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
5546
5547     trace("testing Ctrl+Alt+VK_N press/release 1\n");
5548     flush_sequence();
5549     keybd_event(VK_CONTROL, 0, 0, 0);
5550     keybd_event(VK_MENU, 0, 0, 0);
5551     keybd_event('N', 0, 0, 0);
5552     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5553     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5554     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5555     pump_msg_loop(hwnd, hAccel);
5556     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
5557
5558     ret = DestroyAcceleratorTable(hAccel);
5559     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
5560
5561     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
5562     assert(hAccel != 0);
5563
5564     trace("testing VK_N press/release\n");
5565     flush_sequence();
5566     keybd_event('N', 0, 0, 0);
5567     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5568     pump_msg_loop(hwnd, hAccel);
5569     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5570
5571     trace("testing Shift+VK_N press/release\n");
5572     flush_sequence();
5573     keybd_event(VK_SHIFT, 0, 0, 0);
5574     keybd_event('N', 0, 0, 0);
5575     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5576     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5577     pump_msg_loop(hwnd, hAccel);
5578     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5579
5580     trace("testing Ctrl+VK_N press/release 2\n");
5581     flush_sequence();
5582     keybd_event(VK_CONTROL, 0, 0, 0);
5583     keybd_event('N', 0, 0, 0);
5584     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5585     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5586     pump_msg_loop(hwnd, hAccel);
5587     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
5588
5589     trace("testing Alt+VK_N press/release 2\n");
5590     flush_sequence();
5591     keybd_event(VK_MENU, 0, 0, 0);
5592     keybd_event('N', 0, 0, 0);
5593     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5594     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5595     pump_msg_loop(hwnd, hAccel);
5596     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
5597
5598     trace("testing Ctrl+Alt+VK_N press/release 2\n");
5599     flush_sequence();
5600     keybd_event(VK_CONTROL, 0, 0, 0);
5601     keybd_event(VK_MENU, 0, 0, 0);
5602     keybd_event('N', 0, 0, 0);
5603     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5604     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5605     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5606     pump_msg_loop(hwnd, hAccel);
5607     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
5608
5609     trace("testing Ctrl+Shift+VK_N press/release\n");
5610     flush_sequence();
5611     keybd_event(VK_CONTROL, 0, 0, 0);
5612     keybd_event(VK_SHIFT, 0, 0, 0);
5613     keybd_event('N', 0, 0, 0);
5614     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5615     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5616     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5617     pump_msg_loop(hwnd, hAccel);
5618     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
5619
5620     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
5621     flush_sequence();
5622     keybd_event(VK_CONTROL, 0, 0, 0);
5623     keybd_event(VK_MENU, 0, 0, 0);
5624     keybd_event(VK_SHIFT, 0, 0, 0);
5625     keybd_event('N', 0, 0, 0);
5626     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5627     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5628     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5629     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5630     pump_msg_loop(hwnd, hAccel);
5631     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
5632
5633     ret = DestroyAcceleratorTable(hAccel);
5634     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
5635
5636     trace("testing Alt press/release\n");
5637     flush_sequence();
5638     keybd_event(VK_MENU, 0, 0, 0);
5639     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5640     keybd_event(VK_MENU, 0, 0, 0);
5641     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5642     pump_msg_loop(hwnd, 0);
5643     /* this test doesn't pass in Wine for managed windows */
5644     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
5645
5646     trace("testing Alt+MouseButton press/release\n");
5647     /* first, move mouse pointer inside of the window client area */
5648     GetClientRect(hwnd, &rc);
5649     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
5650     rc.left += (rc.right - rc.left)/2;
5651     rc.top += (rc.bottom - rc.top)/2;
5652     SetCursorPos(rc.left, rc.top);
5653
5654     pump_msg_loop(hwnd, 0);
5655     flush_sequence();
5656     keybd_event(VK_MENU, 0, 0, 0);
5657     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
5658     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
5659     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5660     pump_msg_loop(hwnd, 0);
5661     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
5662
5663     trace("testing VK_F1 press/release\n");
5664     keybd_event(VK_F1, 0, 0, 0);
5665     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
5666     pump_msg_loop(hwnd, 0);
5667     ok_sequence(WmF1Seq, "F1 press/release", TRUE);
5668
5669     trace("testing VK_APPS press/release\n");
5670     keybd_event(VK_APPS, 0, 0, 0);
5671     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
5672     pump_msg_loop(hwnd, 0);
5673     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
5674
5675     DestroyWindow(hwnd);
5676 }
5677
5678 /************* window procedures ********************/
5679
5680 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
5681                              WPARAM wParam, LPARAM lParam)
5682 {
5683     static long defwndproc_counter = 0;
5684     static long beginpaint_counter = 0;
5685     LRESULT ret;
5686     struct message msg;
5687
5688     trace("%p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
5689
5690     /* explicitly ignore WM_GETICON message */
5691     if (message == WM_GETICON) return 0;
5692
5693     switch (message)
5694     {
5695         case WM_ENABLE:
5696         {
5697             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
5698             ok((BOOL)wParam == !(style & WS_DISABLED),
5699                 "wrong WS_DISABLED state: %d != %d\n", wParam, !(style & WS_DISABLED));
5700             break;
5701         }
5702
5703         case WM_CAPTURECHANGED:
5704             if (test_DestroyWindow_flag)
5705             {
5706                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
5707                 if (style & WS_CHILD)
5708                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
5709                 else if (style & WS_POPUP)
5710                     lParam = WND_POPUP_ID;
5711                 else
5712                     lParam = WND_PARENT_ID;
5713             }
5714             break;
5715
5716         case WM_NCDESTROY:
5717         {
5718             HWND capture;
5719
5720             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
5721             capture = GetCapture();
5722             if (capture)
5723             {
5724                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
5725                 trace("current capture %p, releasing...\n", capture);
5726                 ReleaseCapture();
5727             }
5728         }
5729         /* fall through */
5730         case WM_DESTROY:
5731             if (pGetAncestor)
5732                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
5733             if (test_DestroyWindow_flag)
5734             {
5735                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
5736                 if (style & WS_CHILD)
5737                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
5738                 else if (style & WS_POPUP)
5739                     lParam = WND_POPUP_ID;
5740                 else
5741                     lParam = WND_PARENT_ID;
5742             }
5743             break;
5744
5745         /* test_accelerators() depends on this */
5746         case WM_NCHITTEST:
5747             return HTCLIENT;
5748     
5749         /* ignore */
5750         case WM_MOUSEMOVE:
5751         case WM_SETCURSOR:
5752         case WM_DEVICECHANGE:
5753             return 0;
5754
5755         case WM_WINDOWPOSCHANGING:
5756         case WM_WINDOWPOSCHANGED:
5757         {
5758             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
5759
5760             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
5761             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
5762                   winpos->hwnd, winpos->hwndInsertAfter,
5763                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
5764             dump_winpos_flags(winpos->flags);
5765
5766             /* Log only documented flags, win2k uses 0x1000 and 0x2000
5767              * in the high word for internal purposes
5768              */
5769             wParam = winpos->flags & 0xffff;
5770             /* We are not interested in the flags that don't match under XP and Win9x */
5771             wParam &= ~(SWP_NOZORDER);
5772             break;
5773         }
5774     }
5775
5776     msg.message = message;
5777     msg.flags = sent|wparam|lparam;
5778     if (defwndproc_counter) msg.flags |= defwinproc;
5779     if (beginpaint_counter) msg.flags |= beginpaint;
5780     msg.wParam = wParam;
5781     msg.lParam = lParam;
5782     add_message(&msg);
5783
5784     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
5785     {
5786         HWND parent = GetParent(hwnd);
5787         RECT rc;
5788         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
5789
5790         GetClientRect(parent, &rc);
5791         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
5792
5793         trace("ptReserved = (%d,%d)\n"
5794               "ptMaxSize = (%d,%d)\n"
5795               "ptMaxPosition = (%d,%d)\n"
5796               "ptMinTrackSize = (%d,%d)\n"
5797               "ptMaxTrackSize = (%d,%d)\n",
5798               minmax->ptReserved.x, minmax->ptReserved.y,
5799               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
5800               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
5801               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
5802               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
5803
5804         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
5805            minmax->ptMaxSize.x, rc.right);
5806         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
5807            minmax->ptMaxSize.y, rc.bottom);
5808     }
5809
5810     if (message == WM_PAINT)
5811     {
5812         PAINTSTRUCT ps;
5813         beginpaint_counter++;
5814         BeginPaint( hwnd, &ps );
5815         beginpaint_counter--;
5816         EndPaint( hwnd, &ps );
5817         return 0;
5818     }
5819
5820     defwndproc_counter++;
5821     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
5822                   : DefWindowProcA(hwnd, message, wParam, lParam);
5823     defwndproc_counter--;
5824
5825     return ret;
5826 }
5827
5828 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5829 {
5830     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
5831 }
5832
5833 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5834 {
5835     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
5836 }
5837
5838 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5839 {
5840     static long defwndproc_counter = 0;
5841     LRESULT ret;
5842     struct message msg;
5843
5844     trace("popup: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
5845
5846     /* explicitly ignore WM_GETICON message */
5847     if (message == WM_GETICON) return 0;
5848
5849     msg.message = message;
5850     msg.flags = sent|wparam|lparam;
5851     if (defwndproc_counter) msg.flags |= defwinproc;
5852     msg.wParam = wParam;
5853     msg.lParam = lParam;
5854     add_message(&msg);
5855
5856     if (message == WM_CREATE)
5857     {
5858         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
5859         SetWindowLongA(hwnd, GWL_STYLE, style);
5860     }
5861
5862     defwndproc_counter++;
5863     ret = DefWindowProcA(hwnd, message, wParam, lParam);
5864     defwndproc_counter--;
5865
5866     return ret;
5867 }
5868
5869 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5870 {
5871     static long defwndproc_counter = 0;
5872     static long beginpaint_counter = 0;
5873     LRESULT ret;
5874     struct message msg;
5875
5876     trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
5877
5878     /* explicitly ignore WM_GETICON message */
5879     if (message == WM_GETICON) return 0;
5880
5881     if (log_all_parent_messages ||
5882         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
5883         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
5884         message == WM_ENABLE || message == WM_ENTERIDLE ||
5885         message == WM_IME_SETCONTEXT)
5886     {
5887         switch (message)
5888         {
5889             /* ignore */
5890             case WM_NCHITTEST:
5891                 return HTCLIENT;
5892             case WM_SETCURSOR:
5893             case WM_MOUSEMOVE:
5894                 return 0;
5895
5896             case WM_ERASEBKGND:
5897             {
5898                 RECT rc;
5899                 INT ret = GetClipBox((HDC)wParam, &rc);
5900
5901                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
5902                        ret, rc.left, rc.top, rc.right, rc.bottom);
5903                 break;
5904             }
5905
5906             case WM_WINDOWPOSCHANGING:
5907             case WM_WINDOWPOSCHANGED:
5908             {
5909                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
5910
5911                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
5912                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
5913                       winpos->hwnd, winpos->hwndInsertAfter,
5914                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
5915                 dump_winpos_flags(winpos->flags);
5916
5917                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
5918                  * in the high word for internal purposes
5919                  */
5920                 wParam = winpos->flags & 0xffff;
5921                 /* We are not interested in the flags that don't match under XP and Win9x */
5922                 wParam &= ~(SWP_NOZORDER);
5923                 break;
5924             }
5925         }
5926
5927         msg.message = message;
5928         msg.flags = sent|parent|wparam|lparam;
5929         if (defwndproc_counter) msg.flags |= defwinproc;
5930         if (beginpaint_counter) msg.flags |= beginpaint;
5931         msg.wParam = wParam;
5932         msg.lParam = lParam;
5933         add_message(&msg);
5934     }
5935
5936     if (message == WM_PAINT)
5937     {
5938         PAINTSTRUCT ps;
5939         beginpaint_counter++;
5940         BeginPaint( hwnd, &ps );
5941         beginpaint_counter--;
5942         EndPaint( hwnd, &ps );
5943         return 0;
5944     }
5945
5946     defwndproc_counter++;
5947     ret = DefWindowProcA(hwnd, message, wParam, lParam);
5948     defwndproc_counter--;
5949
5950     return ret;
5951 }
5952
5953 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5954 {
5955     static long defwndproc_counter = 0;
5956     LRESULT ret;
5957     struct message msg;
5958
5959     trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
5960
5961     /* explicitly ignore WM_GETICON message */
5962     if (message == WM_GETICON) return 0;
5963
5964     if (test_def_id)
5965     {
5966         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
5967         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
5968         if (after_end_dialog)
5969             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
5970         else
5971             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
5972     }
5973
5974     switch (message)
5975     {
5976         case WM_WINDOWPOSCHANGING:
5977         case WM_WINDOWPOSCHANGED:
5978         {
5979             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
5980
5981             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
5982             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
5983                   winpos->hwnd, winpos->hwndInsertAfter,
5984                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
5985             dump_winpos_flags(winpos->flags);
5986
5987             /* Log only documented flags, win2k uses 0x1000 and 0x2000
5988              * in the high word for internal purposes
5989              */
5990             wParam = winpos->flags & 0xffff;
5991             /* We are not interested in the flags that don't match under XP and Win9x */
5992             wParam &= ~(SWP_NOZORDER);
5993             break;
5994         }
5995     }
5996
5997     msg.message = message;
5998     msg.flags = sent|wparam|lparam;
5999     if (defwndproc_counter) msg.flags |= defwinproc;
6000     msg.wParam = wParam;
6001     msg.lParam = lParam;
6002     add_message(&msg);
6003
6004     defwndproc_counter++;
6005     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6006     defwndproc_counter--;
6007
6008     return ret;
6009 }
6010
6011 static void dump_winpos_flags(UINT flags)
6012 {
6013     if (!winetest_debug) return;
6014
6015     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6016     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6017     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6018     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6019     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6020     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6021     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6022     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6023     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6024     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6025     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6026     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6027     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6028     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6029     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6030
6031 #define DUMPED_FLAGS \
6032     (SWP_NOSIZE | \
6033     SWP_NOMOVE | \
6034     SWP_NOZORDER | \
6035     SWP_NOREDRAW | \
6036     SWP_NOACTIVATE | \
6037     SWP_FRAMECHANGED | \
6038     SWP_SHOWWINDOW | \
6039     SWP_HIDEWINDOW | \
6040     SWP_NOCOPYBITS | \
6041     SWP_NOOWNERZORDER | \
6042     SWP_NOSENDCHANGING | \
6043     SWP_DEFERERASE | \
6044     SWP_ASYNCWINDOWPOS | \
6045     SWP_NOCLIENTSIZE | \
6046     SWP_NOCLIENTMOVE)
6047
6048     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6049     printf("\n");
6050 #undef DUMPED_FLAGS
6051 }
6052
6053 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6054 {
6055     static long defwndproc_counter = 0;
6056     LRESULT ret;
6057     struct message msg;
6058
6059     /* log only specific messages we are interested in */
6060     switch (message)
6061     {
6062 #if 0 /* probably log these as well */
6063     case WM_ACTIVATE:
6064     case WM_SETFOCUS:
6065     case WM_KILLFOCUS:
6066 #endif
6067     case WM_SHOWWINDOW:
6068         trace("WM_SHOWWINDOW %d\n", wParam);
6069         break;
6070     case WM_SIZE:
6071         trace("WM_SIZE %d\n", wParam);
6072         break;
6073     case WM_MOVE:
6074         trace("WM_MOVE\n");
6075         break;
6076     case WM_GETMINMAXINFO:
6077         trace("WM_GETMINMAXINFO\n");
6078         break;
6079
6080     case WM_WINDOWPOSCHANGING:
6081     case WM_WINDOWPOSCHANGED:
6082     {
6083         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6084
6085         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6086         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6087               winpos->hwnd, winpos->hwndInsertAfter,
6088               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6089         trace("flags: ");
6090         dump_winpos_flags(winpos->flags);
6091
6092         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6093          * in the high word for internal purposes
6094          */
6095         wParam = winpos->flags & 0xffff;
6096         /* We are not interested in the flags that don't match under XP and Win9x */
6097         wParam &= ~(SWP_NOZORDER);
6098         break;
6099     }
6100
6101     default: /* ignore */
6102         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6103         return DefWindowProcA(hwnd, message, wParam, lParam);
6104     }
6105
6106     msg.message = message;
6107     msg.flags = sent|wparam|lparam;
6108     if (defwndproc_counter) msg.flags |= defwinproc;
6109     msg.wParam = wParam;
6110     msg.lParam = lParam;
6111     add_message(&msg);
6112
6113     defwndproc_counter++;
6114     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6115     defwndproc_counter--;
6116
6117     return ret;
6118 }
6119
6120 static BOOL RegisterWindowClasses(void)
6121 {
6122     WNDCLASSA cls;
6123
6124     cls.style = 0;
6125     cls.lpfnWndProc = MsgCheckProcA;
6126     cls.cbClsExtra = 0;
6127     cls.cbWndExtra = 0;
6128     cls.hInstance = GetModuleHandleA(0);
6129     cls.hIcon = 0;
6130     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6131     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6132     cls.lpszMenuName = NULL;
6133     cls.lpszClassName = "TestWindowClass";
6134     if(!RegisterClassA(&cls)) return FALSE;
6135
6136     cls.lpfnWndProc = ShowWindowProcA;
6137     cls.lpszClassName = "ShowWindowClass";
6138     if(!RegisterClassA(&cls)) return FALSE;
6139
6140     cls.lpfnWndProc = PopupMsgCheckProcA;
6141     cls.lpszClassName = "TestPopupClass";
6142     if(!RegisterClassA(&cls)) return FALSE;
6143
6144     cls.lpfnWndProc = ParentMsgCheckProcA;
6145     cls.lpszClassName = "TestParentClass";
6146     if(!RegisterClassA(&cls)) return FALSE;
6147
6148     cls.lpfnWndProc = DefWindowProcA;
6149     cls.lpszClassName = "SimpleWindowClass";
6150     if(!RegisterClassA(&cls)) return FALSE;
6151
6152     cls.style = CS_NOCLOSE;
6153     cls.lpszClassName = "NoCloseWindowClass";
6154     if(!RegisterClassA(&cls)) return FALSE;
6155
6156     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6157     cls.style = 0;
6158     cls.hInstance = GetModuleHandleA(0);
6159     cls.hbrBackground = 0;
6160     cls.lpfnWndProc = TestDlgProcA;
6161     cls.lpszClassName = "TestDialogClass";
6162     if(!RegisterClassA(&cls)) return FALSE;
6163
6164     return TRUE;
6165 }
6166
6167 static HHOOK hCBT_hook;
6168 static DWORD cbt_hook_thread_id;
6169
6170 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6171
6172     static const char * const CBT_code_name[10] = {
6173         "HCBT_MOVESIZE",
6174         "HCBT_MINMAX",
6175         "HCBT_QS",
6176         "HCBT_CREATEWND",
6177         "HCBT_DESTROYWND",
6178         "HCBT_ACTIVATE",
6179         "HCBT_CLICKSKIPPED",
6180         "HCBT_KEYSKIPPED",
6181         "HCBT_SYSCOMMAND",
6182         "HCBT_SETFOCUS" };
6183     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6184     HWND hwnd;
6185     char buf[256];
6186
6187     trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
6188
6189     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6190
6191     if (nCode == HCBT_CLICKSKIPPED)
6192     {
6193         /* ignore this event, XP sends it a lot when switching focus between windows */
6194         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6195     }
6196
6197     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6198     {
6199         struct message msg;
6200
6201         msg.message = nCode;
6202         msg.flags = hook|wparam|lparam;
6203         msg.wParam = wParam;
6204         msg.lParam = lParam;
6205         add_message(&msg);
6206
6207         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6208     }
6209
6210     if (nCode == HCBT_DESTROYWND)
6211     {
6212         if (test_DestroyWindow_flag)
6213         {
6214             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6215             if (style & WS_CHILD)
6216                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6217             else if (style & WS_POPUP)
6218                 lParam = WND_POPUP_ID;
6219             else
6220                 lParam = WND_PARENT_ID;
6221         }
6222     }
6223
6224     /* Log also SetFocus(0) calls */
6225     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6226
6227     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6228     {
6229         if (!lstrcmpiA(buf, "TestWindowClass") ||
6230             !lstrcmpiA(buf, "ShowWindowClass") ||
6231             !lstrcmpiA(buf, "TestParentClass") ||
6232             !lstrcmpiA(buf, "TestPopupClass") ||
6233             !lstrcmpiA(buf, "SimpleWindowClass") ||
6234             !lstrcmpiA(buf, "TestDialogClass") ||
6235             !lstrcmpiA(buf, "MDI_frame_class") ||
6236             !lstrcmpiA(buf, "MDI_client_class") ||
6237             !lstrcmpiA(buf, "MDI_child_class") ||
6238             !lstrcmpiA(buf, "my_button_class") ||
6239             !lstrcmpiA(buf, "my_edit_class") ||
6240             !lstrcmpiA(buf, "static") ||
6241             !lstrcmpiA(buf, "#32770"))
6242         {
6243             struct message msg;
6244
6245             msg.message = nCode;
6246             msg.flags = hook|wparam|lparam;
6247             msg.wParam = wParam;
6248             msg.lParam = lParam;
6249             add_message(&msg);
6250         }
6251     }
6252     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6253 }
6254
6255 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6256                                     DWORD event,
6257                                     HWND hwnd,
6258                                     LONG object_id,
6259                                     LONG child_id,
6260                                     DWORD thread_id,
6261                                     DWORD event_time)
6262 {
6263     char buf[256];
6264
6265     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6266            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6267
6268     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6269
6270     /* ignore mouse cursor events */
6271     if (object_id == OBJID_CURSOR) return;
6272
6273     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6274     {
6275         if (!hwnd ||
6276             !lstrcmpiA(buf, "TestWindowClass") ||
6277             !lstrcmpiA(buf, "TestParentClass") ||
6278             !lstrcmpiA(buf, "TestPopupClass") ||
6279             !lstrcmpiA(buf, "SimpleWindowClass") ||
6280             !lstrcmpiA(buf, "TestDialogClass") ||
6281             !lstrcmpiA(buf, "MDI_frame_class") ||
6282             !lstrcmpiA(buf, "MDI_client_class") ||
6283             !lstrcmpiA(buf, "MDI_child_class") ||
6284             !lstrcmpiA(buf, "my_button_class") ||
6285             !lstrcmpiA(buf, "my_edit_class") ||
6286             !lstrcmpiA(buf, "static") ||
6287             !lstrcmpiA(buf, "#32770"))
6288         {
6289             struct message msg;
6290
6291             msg.message = event;
6292             msg.flags = winevent_hook|wparam|lparam;
6293             msg.wParam = object_id;
6294             msg.lParam = child_id;
6295             add_message(&msg);
6296         }
6297     }
6298 }
6299
6300 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
6301 static const WCHAR wszAnsi[] = {'U',0};
6302
6303 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6304 {
6305     switch (uMsg)
6306     {
6307     case CB_FINDSTRINGEXACT:
6308         trace("String: %p\n", (LPCWSTR)lParam);
6309         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
6310             return 1;
6311         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
6312             return 0;
6313         return -1;
6314     }
6315     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
6316 }
6317
6318 static const struct message WmGetTextLengthAfromW[] = {
6319     { WM_GETTEXTLENGTH, sent },
6320     { WM_GETTEXT, sent },
6321     { 0 }
6322 };
6323
6324 static const WCHAR testWindowClassW[] = 
6325 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
6326
6327 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
6328
6329 /* dummy window proc for WM_GETTEXTLENGTH test */
6330 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
6331 {
6332     switch(msg)
6333     {
6334     case WM_GETTEXTLENGTH:
6335         return lstrlenW(dummy_window_text) + 37;  /* some random length */
6336     case WM_GETTEXT:
6337         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
6338         return lstrlenW( (LPWSTR)lp );
6339     default:
6340         return DefWindowProcW( hwnd, msg, wp, lp );
6341     }
6342 }
6343
6344 static void test_message_conversion(void)
6345 {
6346     static const WCHAR wszMsgConversionClass[] =
6347         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
6348     WNDCLASSW cls;
6349     LRESULT lRes;
6350     HWND hwnd;
6351     WNDPROC wndproc, newproc;
6352     BOOL ret;
6353
6354     cls.style = 0;
6355     cls.lpfnWndProc = MsgConversionProcW;
6356     cls.cbClsExtra = 0;
6357     cls.cbWndExtra = 0;
6358     cls.hInstance = GetModuleHandleW(NULL);
6359     cls.hIcon = NULL;
6360     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
6361     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
6362     cls.lpszMenuName = NULL;
6363     cls.lpszClassName = wszMsgConversionClass;
6364     /* this call will fail on Win9x, but that doesn't matter as this test is
6365      * meaningless on those platforms */
6366     if(!RegisterClassW(&cls)) return;
6367
6368     cls.style = 0;
6369     cls.lpfnWndProc = MsgCheckProcW;
6370     cls.cbClsExtra = 0;
6371     cls.cbWndExtra = 0;
6372     cls.hInstance = GetModuleHandleW(0);
6373     cls.hIcon = 0;
6374     cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6375     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6376     cls.lpszMenuName = NULL;
6377     cls.lpszClassName = testWindowClassW;
6378     if(!RegisterClassW(&cls)) return;
6379
6380     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
6381                            100, 100, 200, 200, 0, 0, 0, NULL);
6382     ok(hwnd != NULL, "Window creation failed\n");
6383
6384     /* {W, A} -> A */
6385
6386     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
6387     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6388     ok(lRes == 0, "String should have been converted\n");
6389     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6390     ok(lRes == 1, "String shouldn't have been converted\n");
6391
6392     /* {W, A} -> W */
6393
6394     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
6395     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6396     ok(lRes == 1, "String shouldn't have been converted\n");
6397     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6398     ok(lRes == 1, "String shouldn't have been converted\n");
6399
6400     /* Synchronous messages */
6401
6402     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6403     ok(lRes == 0, "String should have been converted\n");
6404     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6405     ok(lRes == 1, "String shouldn't have been converted\n");
6406
6407     /* Asynchronous messages */
6408
6409     SetLastError(0);
6410     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6411     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6412         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6413     SetLastError(0);
6414     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6415     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6416         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6417     SetLastError(0);
6418     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6419     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6420         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6421     SetLastError(0);
6422     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6423     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6424         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6425     SetLastError(0);
6426     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6427     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6428         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6429     SetLastError(0);
6430     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6431     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6432         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6433     SetLastError(0);
6434     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6435     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6436         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6437     SetLastError(0);
6438     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6439     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6440         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6441
6442     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
6443
6444     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
6445                           WS_OVERLAPPEDWINDOW,
6446                           100, 100, 200, 200, 0, 0, 0, NULL);
6447     assert(hwnd);
6448     flush_sequence();
6449     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
6450     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6451     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6452         "got bad length %ld\n", lRes );
6453
6454     flush_sequence();
6455     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
6456                             hwnd, WM_GETTEXTLENGTH, 0, 0);
6457     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6458     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6459         "got bad length %ld\n", lRes );
6460
6461     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
6462     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
6463     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6464     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6465                                      NULL, 0, NULL, NULL ),
6466         "got bad length %ld\n", lRes );
6467
6468     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
6469     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6470     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6471                                      NULL, 0, NULL, NULL ),
6472         "got bad length %ld\n", lRes );
6473
6474     ret = DestroyWindow(hwnd);
6475     ok( ret, "DestroyWindow() error %d\n", GetLastError());
6476 }
6477
6478 struct timer_info
6479 {
6480     HWND hWnd;
6481     HANDLE handles[2];
6482     DWORD id;
6483 };
6484
6485 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT id, DWORD dwTime)
6486 {
6487 }
6488
6489 #define TIMER_ID  0x19
6490
6491 static DWORD WINAPI timer_thread_proc(LPVOID x)
6492 {
6493     struct timer_info *info = x;
6494     DWORD r;
6495
6496     r = KillTimer(info->hWnd, 0x19);
6497     ok(r,"KillTimer failed in thread\n");
6498     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
6499     ok(r,"SetTimer failed in thread\n");
6500     ok(r==TIMER_ID,"SetTimer id different\n");
6501     r = SetEvent(info->handles[0]);
6502     ok(r,"SetEvent failed in thread\n");
6503     return 0;
6504 }
6505
6506 static void test_timers(void)
6507 {
6508     struct timer_info info;
6509     DWORD id;
6510
6511     info.hWnd = CreateWindow ("TestWindowClass", NULL,
6512        WS_OVERLAPPEDWINDOW ,
6513        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
6514        NULL, NULL, 0);
6515
6516     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
6517     ok(info.id, "SetTimer failed\n");
6518     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
6519     info.handles[0] = CreateEvent(NULL,0,0,NULL);
6520     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
6521
6522     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
6523
6524     WaitForSingleObject(info.handles[1], INFINITE);
6525
6526     CloseHandle(info.handles[0]);
6527     CloseHandle(info.handles[1]);
6528
6529     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
6530
6531     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
6532 }
6533
6534 /* Various win events with arbitrary parameters */
6535 static const struct message WmWinEventsSeq[] = {
6536     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6537     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6538     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6539     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6540     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6541     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6542     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6543     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6544     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6545     /* our win event hook ignores OBJID_CURSOR events */
6546     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
6547     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
6548     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
6549     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
6550     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
6551     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6552     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6553     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6554     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6555     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6556     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6557     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6558     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6559     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6560     { 0 }
6561 };
6562 static const struct message WmWinEventCaretSeq[] = {
6563     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6564     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6565     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
6566     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6567     { 0 }
6568 };
6569 static const struct message WmWinEventCaretSeq_2[] = {
6570     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6571     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6572     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6573     { 0 }
6574 };
6575 static const struct message WmWinEventAlertSeq[] = {
6576     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
6577     { 0 }
6578 };
6579 static const struct message WmWinEventAlertSeq_2[] = {
6580     /* create window in the thread proc */
6581     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
6582     /* our test event */
6583     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
6584     { 0 }
6585 };
6586 static const struct message WmGlobalHookSeq_1[] = {
6587     /* create window in the thread proc */
6588     { HCBT_CREATEWND, hook|lparam, 0, 2 },
6589     /* our test events */
6590     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
6591     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
6592     { 0 }
6593 };
6594 static const struct message WmGlobalHookSeq_2[] = {
6595     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
6596     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
6597     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
6598     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
6599     { 0 }
6600 };
6601
6602 static const struct message WmMouseLLHookSeq[] = {
6603     { WM_MOUSEMOVE, hook },
6604     { WM_LBUTTONUP, hook },
6605     { WM_MOUSEMOVE, hook },
6606     { 0 }
6607 };
6608
6609 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
6610                                          DWORD event,
6611                                          HWND hwnd,
6612                                          LONG object_id,
6613                                          LONG child_id,
6614                                          DWORD thread_id,
6615                                          DWORD event_time)
6616 {
6617     char buf[256];
6618
6619     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6620            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6621
6622     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6623     {
6624         if (!lstrcmpiA(buf, "TestWindowClass") ||
6625             !lstrcmpiA(buf, "static"))
6626         {
6627             struct message msg;
6628
6629             msg.message = event;
6630             msg.flags = winevent_hook|wparam|lparam;
6631             msg.wParam = object_id;
6632             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
6633             add_message(&msg);
6634         }
6635     }
6636 }
6637
6638 static HHOOK hCBT_global_hook;
6639 static DWORD cbt_global_hook_thread_id;
6640
6641 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6642
6643     HWND hwnd;
6644     char buf[256];
6645
6646     trace("CBT_2: %d, %08x, %08lx\n", nCode, wParam, lParam);
6647
6648     if (nCode == HCBT_SYSCOMMAND)
6649     {
6650         struct message msg;
6651
6652         msg.message = nCode;
6653         msg.flags = hook|wparam|lparam;
6654         msg.wParam = wParam;
6655         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6656         add_message(&msg);
6657
6658         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6659     }
6660     /* WH_MOUSE_LL hook */
6661     if (nCode == HC_ACTION)
6662     {
6663         struct message msg;
6664         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
6665
6666         /* we can't test for real mouse events */
6667         if (mhll->flags & LLMHF_INJECTED)
6668         {
6669             msg.message = wParam;
6670             msg.flags = hook;
6671             add_message(&msg);
6672         }
6673         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6674     }
6675
6676     /* Log also SetFocus(0) calls */
6677     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6678
6679     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6680     {
6681         if (!lstrcmpiA(buf, "TestWindowClass") ||
6682             !lstrcmpiA(buf, "static"))
6683         {
6684             struct message msg;
6685
6686             msg.message = nCode;
6687             msg.flags = hook|wparam|lparam;
6688             msg.wParam = wParam;
6689             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6690             add_message(&msg);
6691         }
6692     }
6693     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6694 }
6695
6696 static DWORD WINAPI win_event_global_thread_proc(void *param)
6697 {
6698     HWND hwnd;
6699     MSG msg;
6700     HANDLE hevent = *(HANDLE *)param;
6701     HMODULE user32 = GetModuleHandleA("user32.dll");
6702     FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
6703
6704     assert(pNotifyWinEvent);
6705
6706     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6707     assert(hwnd);
6708     trace("created thread window %p\n", hwnd);
6709
6710     *(HWND *)param = hwnd;
6711
6712     flush_sequence();
6713     /* this event should be received only by our new hook proc,
6714      * an old one does not expect an event from another thread.
6715      */
6716     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
6717     SetEvent(hevent);
6718
6719     while (GetMessage(&msg, 0, 0, 0))
6720     {
6721         TranslateMessage(&msg);
6722         DispatchMessage(&msg);
6723     }
6724     return 0;
6725 }
6726
6727 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
6728 {
6729     HWND hwnd;
6730     MSG msg;
6731     HANDLE hevent = *(HANDLE *)param;
6732
6733     flush_sequence();
6734     /* these events should be received only by our new hook proc,
6735      * an old one does not expect an event from another thread.
6736      */
6737
6738     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6739     assert(hwnd);
6740     trace("created thread window %p\n", hwnd);
6741
6742     *(HWND *)param = hwnd;
6743
6744     /* Windows doesn't like when a thread plays games with the focus,
6745        that leads to all kinds of misbehaviours and failures to activate
6746        a window. So, better keep next lines commented out.
6747     SetFocus(0);
6748     SetFocus(hwnd);*/
6749
6750     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
6751     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
6752
6753     SetEvent(hevent);
6754
6755     while (GetMessage(&msg, 0, 0, 0))
6756     {
6757         TranslateMessage(&msg);
6758         DispatchMessage(&msg);
6759     }
6760     return 0;
6761 }
6762
6763 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
6764 {
6765     HWND hwnd;
6766     MSG msg;
6767     HANDLE hevent = *(HANDLE *)param;
6768
6769     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6770     assert(hwnd);
6771     trace("created thread window %p\n", hwnd);
6772
6773     *(HWND *)param = hwnd;
6774
6775     flush_sequence();
6776
6777     /* Windows doesn't like when a thread plays games with the focus,
6778      * that leads to all kinds of misbehaviours and failures to activate
6779      * a window. So, better don't generate a mouse click message below.
6780      */
6781     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
6782     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6783     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
6784
6785     SetEvent(hevent);
6786     while (GetMessage(&msg, 0, 0, 0))
6787     {
6788         TranslateMessage(&msg);
6789         DispatchMessage(&msg);
6790     }
6791     return 0;
6792 }
6793
6794 static void test_winevents(void)
6795 {
6796     BOOL ret;
6797     MSG msg;
6798     HWND hwnd, hwnd2;
6799     UINT i;
6800     HANDLE hthread, hevent;
6801     DWORD tid;
6802     HWINEVENTHOOK hhook;
6803     const struct message *events = WmWinEventsSeq;
6804     HMODULE user32 = GetModuleHandleA("user32.dll");
6805     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
6806     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
6807     FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
6808
6809     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
6810                            WS_OVERLAPPEDWINDOW,
6811                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
6812                            NULL, NULL, 0);
6813     assert(hwnd);
6814
6815     /****** start of global hook test *************/
6816     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
6817     assert(hCBT_global_hook);
6818
6819     hevent = CreateEventA(NULL, 0, 0, NULL);
6820     assert(hevent);
6821     hwnd2 = (HWND)hevent;
6822
6823     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
6824     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
6825
6826     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6827
6828     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
6829
6830     flush_sequence();
6831     /* this one should be received only by old hook proc */
6832     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
6833     /* this one should be received only by old hook proc */
6834     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
6835
6836     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
6837
6838     ret = UnhookWindowsHookEx(hCBT_global_hook);
6839     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
6840
6841     PostThreadMessageA(tid, WM_QUIT, 0, 0);
6842     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6843     CloseHandle(hthread);
6844     CloseHandle(hevent);
6845     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
6846     /****** end of global hook test *************/
6847
6848     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
6849     {
6850         ok(DestroyWindow(hwnd), "failed to destroy window\n");
6851         return;
6852     }
6853
6854     flush_sequence();
6855
6856     if (0)
6857     {
6858     /* this test doesn't pass under Win9x */
6859     /* win2k ignores events with hwnd == 0 */
6860     SetLastError(0xdeadbeef);
6861     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
6862     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
6863        GetLastError() == 0xdeadbeef, /* Win9x */
6864        "unexpected error %d\n", GetLastError());
6865     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
6866     }
6867
6868     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
6869         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
6870
6871     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
6872
6873     /****** start of event filtering test *************/
6874     hhook = (HWINEVENTHOOK)pSetWinEventHook(
6875         EVENT_OBJECT_SHOW, /* 0x8002 */
6876         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
6877         GetModuleHandleA(0), win_event_global_hook_proc,
6878         GetCurrentProcessId(), 0,
6879         WINEVENT_INCONTEXT);
6880     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
6881
6882     hevent = CreateEventA(NULL, 0, 0, NULL);
6883     assert(hevent);
6884     hwnd2 = (HWND)hevent;
6885
6886     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
6887     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
6888
6889     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6890
6891     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
6892
6893     flush_sequence();
6894     /* this one should be received only by old hook proc */
6895     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
6896     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
6897     /* this one should be received only by old hook proc */
6898     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
6899
6900     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
6901
6902     ret = pUnhookWinEvent(hhook);
6903     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
6904
6905     PostThreadMessageA(tid, WM_QUIT, 0, 0);
6906     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6907     CloseHandle(hthread);
6908     CloseHandle(hevent);
6909     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
6910     /****** end of event filtering test *************/
6911
6912     /****** start of out of context event test *************/
6913     hhook = (HWINEVENTHOOK)pSetWinEventHook(
6914         EVENT_MIN, EVENT_MAX,
6915         0, win_event_global_hook_proc,
6916         GetCurrentProcessId(), 0,
6917         WINEVENT_OUTOFCONTEXT);
6918     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
6919
6920     hevent = CreateEventA(NULL, 0, 0, NULL);
6921     assert(hevent);
6922     hwnd2 = (HWND)hevent;
6923
6924     flush_sequence();
6925
6926     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
6927     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
6928
6929     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6930
6931     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
6932     /* process pending winevent messages */
6933     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
6934     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
6935
6936     flush_sequence();
6937     /* this one should be received only by old hook proc */
6938     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
6939     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
6940     /* this one should be received only by old hook proc */
6941     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
6942
6943     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
6944     /* process pending winevent messages */
6945     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
6946     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
6947
6948     ret = pUnhookWinEvent(hhook);
6949     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
6950
6951     PostThreadMessageA(tid, WM_QUIT, 0, 0);
6952     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6953     CloseHandle(hthread);
6954     CloseHandle(hevent);
6955     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
6956     /****** end of out of context event test *************/
6957
6958     /****** start of MOUSE_LL hook test *************/
6959     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
6960     /* WH_MOUSE_LL is not supported on Win9x platforms */
6961     if (!hCBT_global_hook)
6962     {
6963         trace("Skipping WH_MOUSE_LL test on this platform\n");
6964         goto skip_mouse_ll_hook_test;
6965     }
6966
6967     hevent = CreateEventA(NULL, 0, 0, NULL);
6968     assert(hevent);
6969     hwnd2 = (HWND)hevent;
6970
6971     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
6972     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
6973
6974     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
6975         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6976
6977     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
6978     flush_sequence();
6979
6980     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
6981     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6982     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
6983
6984     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
6985
6986     ret = UnhookWindowsHookEx(hCBT_global_hook);
6987     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
6988
6989     PostThreadMessageA(tid, WM_QUIT, 0, 0);
6990     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6991     CloseHandle(hthread);
6992     CloseHandle(hevent);
6993     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
6994     /****** end of MOUSE_LL hook test *************/
6995 skip_mouse_ll_hook_test:
6996
6997     ok(DestroyWindow(hwnd), "failed to destroy window\n");
6998 }
6999
7000 static void test_set_hook(void)
7001 {
7002     BOOL ret;
7003     HHOOK hhook;
7004     HWINEVENTHOOK hwinevent_hook;
7005     HMODULE user32 = GetModuleHandleA("user32.dll");
7006     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
7007     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
7008
7009     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7010     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7011     UnhookWindowsHookEx(hhook);
7012
7013     if (0)
7014     {
7015     /* this test doesn't pass under Win9x: BUG! */
7016     SetLastError(0xdeadbeef);
7017     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7018     ok(!hhook, "global hook requires hModule != 0\n");
7019     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7020     }
7021
7022     SetLastError(0xdeadbeef);
7023     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7024     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7025     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7026        GetLastError() == 0xdeadbeef, /* Win9x */
7027        "unexpected error %d\n", GetLastError());
7028
7029     SetLastError(0xdeadbeef);
7030     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7031     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7032        GetLastError() == 0xdeadbeef, /* Win9x */
7033        "unexpected error %d\n", GetLastError());
7034
7035     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7036
7037     /* even process local incontext hooks require hmodule */
7038     SetLastError(0xdeadbeef);
7039     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7040         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7041     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7042     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7043        GetLastError() == 0xdeadbeef, /* Win9x */
7044        "unexpected error %d\n", GetLastError());
7045
7046     /* even thread local incontext hooks require hmodule */
7047     SetLastError(0xdeadbeef);
7048     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7049         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7050     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7051     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7052        GetLastError() == 0xdeadbeef, /* Win9x */
7053        "unexpected error %d\n", GetLastError());
7054
7055     if (0)
7056     {
7057     /* these 3 tests don't pass under Win9x */
7058     SetLastError(0xdeadbeef);
7059     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7060         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7061     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7062     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7063
7064     SetLastError(0xdeadbeef);
7065     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7066         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7067     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7068     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7069
7070     SetLastError(0xdeadbeef);
7071     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7072         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7073     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7074     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7075     }
7076
7077     SetLastError(0xdeadbeef);
7078     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7079         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7080     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7081     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7082     ret = pUnhookWinEvent(hwinevent_hook);
7083     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7084
7085 todo_wine {
7086     /* This call succeeds under win2k SP4, but fails under Wine.
7087        Does win2k test/use passed process id? */
7088     SetLastError(0xdeadbeef);
7089     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7090         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7091     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7092     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7093     ret = pUnhookWinEvent(hwinevent_hook);
7094     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7095 }
7096
7097     SetLastError(0xdeadbeef);
7098     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7099     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7100         GetLastError() == 0xdeadbeef, /* Win9x */
7101         "unexpected error %d\n", GetLastError());
7102 }
7103
7104 static const struct message ScrollWindowPaint1[] = {
7105     { WM_PAINT, sent },
7106     { WM_ERASEBKGND, sent|beginpaint },
7107     { 0 }
7108 };
7109
7110 static const struct message ScrollWindowPaint2[] = {
7111     { WM_PAINT, sent },
7112     { 0 }
7113 };
7114
7115 static void test_scrollwindowex(void)
7116 {
7117     HWND hwnd, hchild;
7118     RECT rect={0,0,130,130};
7119     MSG msg;
7120
7121     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7122             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7123             100, 100, 200, 200, 0, 0, 0, NULL);
7124     ok (hwnd != 0, "Failed to create overlapped window\n");
7125     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7126             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7127             10, 10, 150, 150, hwnd, 0, 0, NULL);
7128     ok (hchild != 0, "Failed to create child\n");
7129     UpdateWindow(hwnd);
7130     flush_events();
7131     flush_sequence();
7132
7133     /* scroll without the child window */
7134     trace("start scroll\n");
7135     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7136             SW_ERASE|SW_INVALIDATE);
7137     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7138     trace("end scroll\n");
7139     flush_sequence();
7140     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7141     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7142     flush_events();
7143     flush_sequence();
7144
7145     /* Now without the SW_ERASE flag */
7146     trace("start scroll\n");
7147     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7148     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7149     trace("end scroll\n");
7150     flush_sequence();
7151     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7152     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7153     flush_events();
7154     flush_sequence();
7155
7156     /* now scroll the child window as well */
7157     trace("start scroll\n");
7158     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7159             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7160     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7161                 /* windows sometimes a WM_MOVE */
7162         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7163     }
7164     trace("end scroll\n");
7165     flush_sequence();
7166     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7167     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7168     flush_events();
7169     flush_sequence();
7170
7171     /* now scroll with ScrollWindow() */
7172     trace("start scroll with ScrollWindow\n");
7173     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7174     trace("end scroll\n");
7175     flush_sequence();
7176     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7177     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7178
7179     ok(DestroyWindow(hchild), "failed to destroy window\n");
7180     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7181     flush_sequence();
7182 }
7183
7184 static const struct message destroy_window_with_children[] = {
7185     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7186     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7187     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7188     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7189     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7190     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7191     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7192     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7193     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7194     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7195     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7196     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7197     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7198     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7199     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7200     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7201     { 0 }
7202 };
7203
7204 static void test_DestroyWindow(void)
7205 {
7206     BOOL ret;
7207     HWND parent, child1, child2, child3, child4, test;
7208     UINT child_id = WND_CHILD_ID + 1;
7209
7210     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7211                              100, 100, 200, 200, 0, 0, 0, NULL);
7212     assert(parent != 0);
7213     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7214                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7215     assert(child1 != 0);
7216     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7217                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7218     assert(child2 != 0);
7219     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7220                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7221     assert(child3 != 0);
7222     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7223                              0, 0, 50, 50, parent, 0, 0, NULL);
7224     assert(child4 != 0);
7225
7226     /* test owner/parent of child2 */
7227     test = GetParent(child2);
7228     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7229     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7230     if(pGetAncestor) {
7231         test = pGetAncestor(child2, GA_PARENT);
7232         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7233     }
7234     test = GetWindow(child2, GW_OWNER);
7235     ok(!test, "wrong owner %p\n", test);
7236
7237     test = SetParent(child2, parent);
7238     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7239
7240     /* test owner/parent of the parent */
7241     test = GetParent(parent);
7242     ok(!test, "wrong parent %p\n", test);
7243 todo_wine {
7244     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7245 }
7246     if(pGetAncestor) {
7247         test = pGetAncestor(parent, GA_PARENT);
7248         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7249     }
7250     test = GetWindow(parent, GW_OWNER);
7251     ok(!test, "wrong owner %p\n", test);
7252
7253     /* test owner/parent of child1 */
7254     test = GetParent(child1);
7255     ok(test == parent, "wrong parent %p\n", test);
7256     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7257     if(pGetAncestor) {
7258         test = pGetAncestor(child1, GA_PARENT);
7259         ok(test == parent, "wrong parent %p\n", test);
7260     }
7261     test = GetWindow(child1, GW_OWNER);
7262     ok(!test, "wrong owner %p\n", test);
7263
7264     /* test owner/parent of child2 */
7265     test = GetParent(child2);
7266     ok(test == parent, "wrong parent %p\n", test);
7267     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7268     if(pGetAncestor) {
7269         test = pGetAncestor(child2, GA_PARENT);
7270         ok(test == parent, "wrong parent %p\n", test);
7271     }
7272     test = GetWindow(child2, GW_OWNER);
7273     ok(!test, "wrong owner %p\n", test);
7274
7275     /* test owner/parent of child3 */
7276     test = GetParent(child3);
7277     ok(test == child1, "wrong parent %p\n", test);
7278     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7279     if(pGetAncestor) {
7280         test = pGetAncestor(child3, GA_PARENT);
7281         ok(test == child1, "wrong parent %p\n", test);
7282     }
7283     test = GetWindow(child3, GW_OWNER);
7284     ok(!test, "wrong owner %p\n", test);
7285
7286     /* test owner/parent of child4 */
7287     test = GetParent(child4);
7288     ok(test == parent, "wrong parent %p\n", test);
7289     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7290     if(pGetAncestor) {
7291         test = pGetAncestor(child4, GA_PARENT);
7292         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7293     }
7294     test = GetWindow(child4, GW_OWNER);
7295     ok(test == parent, "wrong owner %p\n", test);
7296
7297     flush_sequence();
7298
7299     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7300            parent, child1, child2, child3, child4);
7301
7302     SetCapture(child4);
7303     test = GetCapture();
7304     ok(test == child4, "wrong capture window %p\n", test);
7305
7306     test_DestroyWindow_flag = TRUE;
7307     ret = DestroyWindow(parent);
7308     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7309     test_DestroyWindow_flag = FALSE;
7310     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7311
7312     ok(!IsWindow(parent), "parent still exists\n");
7313     ok(!IsWindow(child1), "child1 still exists\n");
7314     ok(!IsWindow(child2), "child2 still exists\n");
7315     ok(!IsWindow(child3), "child3 still exists\n");
7316     ok(!IsWindow(child4), "child4 still exists\n");
7317
7318     test = GetCapture();
7319     ok(!test, "wrong capture window %p\n", test);
7320 }
7321
7322
7323 static const struct message WmDispatchPaint[] = {
7324     { WM_NCPAINT, sent },
7325     { WM_GETTEXT, sent|defwinproc|optional },
7326     { WM_GETTEXT, sent|defwinproc|optional },
7327     { WM_ERASEBKGND, sent },
7328     { 0 }
7329 };
7330
7331 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7332 {
7333     if (message == WM_PAINT) return 0;
7334     return MsgCheckProcA( hwnd, message, wParam, lParam );
7335 }
7336
7337 static void test_DispatchMessage(void)
7338 {
7339     RECT rect;
7340     MSG msg;
7341     int count;
7342     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7343                                100, 100, 200, 200, 0, 0, 0, NULL);
7344     ShowWindow( hwnd, SW_SHOW );
7345     UpdateWindow( hwnd );
7346     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7347     flush_sequence();
7348     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
7349
7350     SetRect( &rect, -5, -5, 5, 5 );
7351     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7352     count = 0;
7353     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7354     {
7355         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7356         else
7357         {
7358             flush_sequence();
7359             DispatchMessage( &msg );
7360             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
7361             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7362             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
7363             if (++count > 10) break;
7364         }
7365     }
7366     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
7367
7368     trace("now without DispatchMessage\n");
7369     flush_sequence();
7370     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7371     count = 0;
7372     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7373     {
7374         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7375         else
7376         {
7377             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
7378             flush_sequence();
7379             /* this will send WM_NCCPAINT just like DispatchMessage does */
7380             GetUpdateRgn( hwnd, hrgn, TRUE );
7381             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7382             DeleteObject( hrgn );
7383             GetClientRect( hwnd, &rect );
7384             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
7385             ok( !count, "Got multiple WM_PAINTs\n" );
7386             if (++count > 10) break;
7387         }
7388     }
7389     DestroyWindow(hwnd);
7390 }
7391
7392
7393 static const struct message WmUser[] = {
7394     { WM_USER, sent },
7395     { 0 }
7396 };
7397
7398 struct sendmsg_info
7399 {
7400     HWND  hwnd;
7401     DWORD timeout;
7402     DWORD ret;
7403 };
7404
7405 static DWORD CALLBACK send_msg_thread( LPVOID arg )
7406 {
7407     struct sendmsg_info *info = arg;
7408     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
7409     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
7410     return 0;
7411 }
7412
7413 static void wait_for_thread( HANDLE thread )
7414 {
7415     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
7416     {
7417         MSG msg;
7418         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
7419     }
7420 }
7421
7422 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7423 {
7424     if (message == WM_USER) Sleep(200);
7425     return MsgCheckProcA( hwnd, message, wParam, lParam );
7426 }
7427
7428 static void test_SendMessageTimeout(void)
7429 {
7430     MSG msg;
7431     HANDLE thread;
7432     struct sendmsg_info info;
7433     DWORD tid;
7434
7435     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7436                                100, 100, 200, 200, 0, 0, 0, NULL);
7437     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7438     flush_sequence();
7439
7440     info.timeout = 1000;
7441     info.ret = 0xdeadbeef;
7442     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7443     wait_for_thread( thread );
7444     CloseHandle( thread );
7445     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7446     ok_sequence( WmUser, "WmUser", FALSE );
7447
7448     info.timeout = 1;
7449     info.ret = 0xdeadbeef;
7450     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7451     Sleep(100);  /* SendMessageTimeout should timeout here */
7452     wait_for_thread( thread );
7453     CloseHandle( thread );
7454     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7455     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7456
7457     /* 0 means infinite timeout */
7458     info.timeout = 0;
7459     info.ret = 0xdeadbeef;
7460     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7461     Sleep(100);
7462     wait_for_thread( thread );
7463     CloseHandle( thread );
7464     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7465     ok_sequence( WmUser, "WmUser", FALSE );
7466
7467     /* timeout is treated as signed despite the prototype */
7468     info.timeout = 0x7fffffff;
7469     info.ret = 0xdeadbeef;
7470     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7471     Sleep(100);
7472     wait_for_thread( thread );
7473     CloseHandle( thread );
7474     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7475     ok_sequence( WmUser, "WmUser", FALSE );
7476
7477     info.timeout = 0x80000000;
7478     info.ret = 0xdeadbeef;
7479     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7480     Sleep(100);
7481     wait_for_thread( thread );
7482     CloseHandle( thread );
7483     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7484     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7485
7486     /* now check for timeout during message processing */
7487     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
7488     info.timeout = 100;
7489     info.ret = 0xdeadbeef;
7490     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7491     wait_for_thread( thread );
7492     CloseHandle( thread );
7493     /* we should timeout but still get the message */
7494     ok( info.ret == 0, "SendMessageTimeout failed\n" );
7495     ok_sequence( WmUser, "WmUser", FALSE );
7496
7497     DestroyWindow( info.hwnd );
7498 }
7499
7500
7501 /****************** edit message test *************************/
7502 #define ID_EDIT 0x1234
7503 static const struct message sl_edit_setfocus[] =
7504 {
7505     { HCBT_SETFOCUS, hook },
7506     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7507     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7508     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7509     { WM_SETFOCUS, sent|wparam, 0 },
7510     { WM_CTLCOLOREDIT, sent|parent },
7511     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7512     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7513     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7514     { 0 }
7515 };
7516 static const struct message ml_edit_setfocus[] =
7517 {
7518     { HCBT_SETFOCUS, hook },
7519     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7520     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7521     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7522     { WM_SETFOCUS, sent|wparam, 0 },
7523     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7524     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7525     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7526     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7527     { 0 }
7528 };
7529 static const struct message sl_edit_killfocus[] =
7530 {
7531     { HCBT_SETFOCUS, hook },
7532     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7533     { WM_KILLFOCUS, sent|wparam, 0 },
7534     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7535     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7536     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
7537     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
7538     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
7539     { 0 }
7540 };
7541 static const struct message sl_edit_lbutton_dblclk[] =
7542 {
7543     { WM_LBUTTONDBLCLK, sent },
7544     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7545     { 0 }
7546 };
7547 static const struct message sl_edit_lbutton_down[] =
7548 {
7549     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7550     { HCBT_SETFOCUS, hook },
7551     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7552     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7553     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7554     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7555     { WM_CTLCOLOREDIT, sent|parent },
7556     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7557     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7558     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7559     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7560     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7561     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7562     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7563     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7564     { 0 }
7565 };
7566 static const struct message ml_edit_lbutton_down[] =
7567 {
7568     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7569     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7570     { HCBT_SETFOCUS, hook },
7571     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7572     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7573     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7574     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7575     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7576     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7577     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7578     { 0 }
7579 };
7580 static const struct message sl_edit_lbutton_up[] =
7581 {
7582     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7583     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7584     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7585     { WM_CAPTURECHANGED, sent|defwinproc },
7586     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7587     { 0 }
7588 };
7589 static const struct message ml_edit_lbutton_up[] =
7590 {
7591     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7592     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7593     { WM_CAPTURECHANGED, sent|defwinproc },
7594     { 0 }
7595 };
7596
7597 static WNDPROC old_edit_proc;
7598
7599 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7600 {
7601     static long defwndproc_counter = 0;
7602     LRESULT ret;
7603     struct message msg;
7604
7605     trace("edit: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
7606
7607     /* explicitly ignore WM_GETICON message */
7608     if (message == WM_GETICON) return 0;
7609
7610     msg.message = message;
7611     msg.flags = sent|wparam|lparam;
7612     if (defwndproc_counter) msg.flags |= defwinproc;
7613     msg.wParam = wParam;
7614     msg.lParam = lParam;
7615     add_message(&msg);
7616
7617     defwndproc_counter++;
7618     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
7619     defwndproc_counter--;
7620
7621     return ret;
7622 }
7623
7624 static void subclass_edit(void)
7625 {
7626     WNDCLASSA cls;
7627
7628     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
7629
7630     old_edit_proc = cls.lpfnWndProc;
7631
7632     cls.hInstance = GetModuleHandle(0);
7633     cls.lpfnWndProc = edit_hook_proc;
7634     cls.lpszClassName = "my_edit_class";
7635     UnregisterClass(cls.lpszClassName, cls.hInstance);
7636     if (!RegisterClassA(&cls)) assert(0);
7637 }
7638
7639 static void test_edit_messages(void)
7640 {
7641     HWND hwnd, parent;
7642     DWORD dlg_code;
7643
7644     subclass_edit();
7645     log_all_parent_messages++;
7646
7647     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7648                              100, 100, 200, 200, 0, 0, 0, NULL);
7649     ok (parent != 0, "Failed to create parent window\n");
7650
7651     /* test single line edit */
7652     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
7653                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7654     ok(hwnd != 0, "Failed to create edit window\n");
7655
7656     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7657     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
7658
7659     ShowWindow(hwnd, SW_SHOW);
7660     UpdateWindow(hwnd);
7661     SetFocus(0);
7662     flush_sequence();
7663
7664     SetFocus(hwnd);
7665     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
7666
7667     SetFocus(0);
7668     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
7669
7670     SetFocus(0);
7671     ReleaseCapture();
7672     flush_sequence();
7673
7674     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7675     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
7676
7677     SetFocus(0);
7678     ReleaseCapture();
7679     flush_sequence();
7680
7681     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7682     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
7683
7684     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7685     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
7686
7687     DestroyWindow(hwnd);
7688
7689     /* test multiline edit */
7690     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
7691                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7692     ok(hwnd != 0, "Failed to create edit window\n");
7693
7694     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7695     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
7696        "wrong dlg_code %08x\n", dlg_code);
7697
7698     ShowWindow(hwnd, SW_SHOW);
7699     UpdateWindow(hwnd);
7700     SetFocus(0);
7701     flush_sequence();
7702
7703     SetFocus(hwnd);
7704     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
7705
7706     SetFocus(0);
7707     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
7708
7709     SetFocus(0);
7710     ReleaseCapture();
7711     flush_sequence();
7712
7713     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7714     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
7715
7716     SetFocus(0);
7717     ReleaseCapture();
7718     flush_sequence();
7719
7720     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7721     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
7722
7723     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7724     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
7725
7726     DestroyWindow(hwnd);
7727     DestroyWindow(parent);
7728
7729     log_all_parent_messages--;
7730 }
7731
7732 /**************************** End of Edit test ******************************/
7733
7734 static const struct message WmKeyDownSkippedSeq[] =
7735 {
7736     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7737     { 0 }
7738 };
7739 static const struct message WmKeyUpSkippedSeq[] =
7740 {
7741     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7742     { 0 }
7743 };
7744
7745 #define EV_START_STOP 0
7746 #define EV_SENDMSG 1
7747 #define EV_ACK 2
7748
7749 struct peekmsg_info
7750 {
7751     HWND  hwnd;
7752     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
7753 };
7754
7755 static DWORD CALLBACK send_msg_thread_2(void *param)
7756 {
7757     DWORD ret;
7758     struct peekmsg_info *info = param;
7759
7760     trace("thread: waiting for start\n");
7761     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
7762     trace("thread: looping\n");
7763
7764     while (1)
7765     {
7766         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
7767
7768         switch (ret)
7769         {
7770         case WAIT_OBJECT_0 + EV_START_STOP:
7771             trace("thread: exiting\n");
7772             return 0;
7773
7774         case WAIT_OBJECT_0 + EV_SENDMSG:
7775             trace("thread: sending message\n");
7776             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
7777             SetEvent(info->hevent[EV_ACK]);
7778             break;
7779
7780         default:
7781             trace("unexpected return: %04x\n", ret);
7782             assert(0);
7783             break;
7784         }
7785     }
7786     return 0;
7787 }
7788
7789 static void test_PeekMessage(void)
7790 {
7791     MSG msg;
7792     HANDLE hthread;
7793     DWORD tid, qstatus;
7794     UINT qs_all_input = QS_ALLINPUT;
7795     UINT qs_input = QS_INPUT;
7796     BOOL ret;
7797     struct peekmsg_info info;
7798
7799     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7800                               100, 100, 200, 200, 0, 0, 0, NULL);
7801     assert(info.hwnd);
7802     ShowWindow(info.hwnd, SW_SHOW);
7803     UpdateWindow(info.hwnd);
7804     SetFocus(info.hwnd);
7805
7806     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
7807     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
7808     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
7809
7810     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
7811     Sleep(100);
7812
7813     trace("signalling to start looping\n");
7814     SetEvent(info.hevent[EV_START_STOP]);
7815
7816     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
7817     flush_sequence();
7818
7819     SetLastError(0xdeadbeef);
7820     qstatus = GetQueueStatus(qs_all_input);
7821     if (GetLastError() == ERROR_INVALID_FLAGS)
7822     {
7823         trace("QS_RAWINPUT not supported on this platform\n");
7824         qs_all_input &= ~QS_RAWINPUT;
7825         qs_input &= ~QS_RAWINPUT;
7826     }
7827     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
7828
7829     trace("signalling to send message\n");
7830     SetEvent(info.hevent[EV_SENDMSG]);
7831     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
7832
7833     /* pass invalid QS_xxxx flags */
7834     SetLastError(0xdeadbeef);
7835     qstatus = GetQueueStatus(0xffffffff);
7836     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
7837     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
7838
7839     qstatus = GetQueueStatus(qs_all_input);
7840     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
7841        "wrong qstatus %08x\n", qstatus);
7842
7843     msg.message = 0;
7844     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
7845     ok(!ret,
7846        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7847         msg.message);
7848     ok_sequence(WmUser, "WmUser", FALSE);
7849
7850     qstatus = GetQueueStatus(qs_all_input);
7851     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
7852
7853     keybd_event('N', 0, 0, 0);
7854     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7855     qstatus = GetQueueStatus(qs_all_input);
7856     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
7857        "wrong qstatus %08x\n", qstatus);
7858
7859     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
7860     qstatus = GetQueueStatus(qs_all_input);
7861     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
7862        "wrong qstatus %08x\n", qstatus);
7863
7864     InvalidateRect(info.hwnd, NULL, FALSE);
7865     qstatus = GetQueueStatus(qs_all_input);
7866     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
7867        "wrong qstatus %08x\n", qstatus);
7868
7869     trace("signalling to send message\n");
7870     SetEvent(info.hevent[EV_SENDMSG]);
7871     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
7872
7873     qstatus = GetQueueStatus(qs_all_input);
7874     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
7875        "wrong qstatus %08x\n", qstatus);
7876
7877     msg.message = 0;
7878     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
7879     ok(!ret,
7880        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7881         msg.message);
7882     ok_sequence(WmUser, "WmUser", FALSE);
7883
7884     qstatus = GetQueueStatus(qs_all_input);
7885     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
7886        "wrong qstatus %08x\n", qstatus);
7887
7888     trace("signalling to send message\n");
7889     SetEvent(info.hevent[EV_SENDMSG]);
7890     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
7891
7892     qstatus = GetQueueStatus(qs_all_input);
7893     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
7894        "wrong qstatus %08x\n", qstatus);
7895
7896     msg.message = 0;
7897     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
7898     ok(!ret,
7899        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7900         msg.message);
7901     ok_sequence(WmUser, "WmUser", FALSE);
7902
7903     qstatus = GetQueueStatus(qs_all_input);
7904     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
7905        "wrong qstatus %08x\n", qstatus);
7906
7907     msg.message = 0;
7908     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
7909     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
7910        "got %d and %04x wParam %08x instead of TRUE and WM_CHAR wParam 'z'\n",
7911        ret, msg.message, msg.wParam);
7912     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
7913
7914     qstatus = GetQueueStatus(qs_all_input);
7915     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
7916        "wrong qstatus %08x\n", qstatus);
7917
7918     msg.message = 0;
7919     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
7920     ok(!ret,
7921        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7922         msg.message);
7923     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
7924
7925     qstatus = GetQueueStatus(qs_all_input);
7926     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
7927        "wrong qstatus %08x\n", qstatus);
7928
7929     msg.message = 0;
7930     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
7931     ok(ret && msg.message == WM_PAINT,
7932        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
7933     DispatchMessageA(&msg);
7934     ok_sequence(WmPaint, "WmPaint", FALSE);
7935
7936     qstatus = GetQueueStatus(qs_all_input);
7937     ok(qstatus == MAKELONG(0, QS_KEY),
7938        "wrong qstatus %08x\n", qstatus);
7939
7940     msg.message = 0;
7941     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
7942     ok(!ret,
7943        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7944         msg.message);
7945     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
7946
7947     qstatus = GetQueueStatus(qs_all_input);
7948     ok(qstatus == MAKELONG(0, QS_KEY),
7949        "wrong qstatus %08x\n", qstatus);
7950
7951     trace("signalling to send message\n");
7952     SetEvent(info.hevent[EV_SENDMSG]);
7953     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
7954
7955     qstatus = GetQueueStatus(qs_all_input);
7956     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
7957        "wrong qstatus %08x\n", qstatus);
7958
7959     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
7960
7961     qstatus = GetQueueStatus(qs_all_input);
7962     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
7963        "wrong qstatus %08x\n", qstatus);
7964
7965     msg.message = 0;
7966     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
7967     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
7968        "got %d and %04x wParam %08x instead of TRUE and WM_CHAR wParam 'z'\n",
7969        ret, msg.message, msg.wParam);
7970     ok_sequence(WmUser, "WmUser", FALSE);
7971
7972     qstatus = GetQueueStatus(qs_all_input);
7973     ok(qstatus == MAKELONG(0, QS_KEY),
7974        "wrong qstatus %08x\n", qstatus);
7975
7976     msg.message = 0;
7977     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
7978     ok(!ret,
7979        "PeekMessageA should have returned FALSE instead of msg %04x\n",
7980         msg.message);
7981     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
7982
7983     qstatus = GetQueueStatus(qs_all_input);
7984     ok(qstatus == MAKELONG(0, QS_KEY),
7985        "wrong qstatus %08x\n", qstatus);
7986
7987     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
7988
7989     qstatus = GetQueueStatus(qs_all_input);
7990     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
7991        "wrong qstatus %08x\n", qstatus);
7992
7993     trace("signalling to send message\n");
7994     SetEvent(info.hevent[EV_SENDMSG]);
7995     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
7996
7997     qstatus = GetQueueStatus(qs_all_input);
7998     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
7999        "wrong qstatus %08x\n", qstatus);
8000
8001     msg.message = 0;
8002     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8003     ok(!ret,
8004        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8005         msg.message);
8006     ok_sequence(WmUser, "WmUser", FALSE);
8007
8008     qstatus = GetQueueStatus(qs_all_input);
8009     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8010        "wrong qstatus %08x\n", qstatus);
8011
8012     msg.message = 0;
8013     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8014         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8015     else /* workaround for a missing QS_RAWINPUT support */
8016         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8017     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8018        "got %d and %04x wParam %08x instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8019        ret, msg.message, msg.wParam);
8020     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8021
8022     qstatus = GetQueueStatus(qs_all_input);
8023     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8024        "wrong qstatus %08x\n", qstatus);
8025
8026     msg.message = 0;
8027     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8028         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8029     else /* workaround for a missing QS_RAWINPUT support */
8030         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8031     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8032        "got %d and %04x wParam %08x instead of TRUE and WM_KEYUP wParam 'N'\n",
8033        ret, msg.message, msg.wParam);
8034     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8035
8036     qstatus = GetQueueStatus(qs_all_input);
8037     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8038        "wrong qstatus %08x\n", qstatus);
8039
8040     msg.message = 0;
8041     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8042     ok(!ret,
8043        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8044         msg.message);
8045     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8046
8047     qstatus = GetQueueStatus(qs_all_input);
8048     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8049        "wrong qstatus %08x\n", qstatus);
8050
8051     msg.message = 0;
8052     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8053     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8054        "got %d and %04x wParam %08x instead of TRUE and WM_CHAR wParam 'z'\n",
8055        ret, msg.message, msg.wParam);
8056     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8057
8058     qstatus = GetQueueStatus(qs_all_input);
8059     ok(qstatus == 0,
8060        "wrong qstatus %08x\n", qstatus);
8061
8062     msg.message = 0;
8063     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8064     ok(!ret,
8065        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8066         msg.message);
8067     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8068
8069     qstatus = GetQueueStatus(qs_all_input);
8070     ok(qstatus == 0,
8071        "wrong qstatus %08x\n", qstatus);
8072
8073     /* test whether presence of the quit flag in the queue affects
8074      * the queue state
8075      */
8076     PostQuitMessage(0x1234abcd);
8077
8078     qstatus = GetQueueStatus(qs_all_input);
8079     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8080        "wrong qstatus %08x\n", qstatus);
8081
8082     PostMessageA(info.hwnd, WM_USER, 0, 0);
8083
8084     qstatus = GetQueueStatus(qs_all_input);
8085     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8086        "wrong qstatus %08x\n", qstatus);
8087
8088     msg.message = 0;
8089     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8090     ok(ret && msg.message == WM_USER,
8091        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8092     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8093
8094     qstatus = GetQueueStatus(qs_all_input);
8095     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8096        "wrong qstatus %08x\n", qstatus);
8097
8098     msg.message = 0;
8099     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8100     ok(ret && msg.message == WM_QUIT,
8101        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8102     ok(msg.wParam == 0x1234abcd, "got wParam %08x instead of 0x1234abcd\n", msg.wParam);
8103     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8104     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8105
8106     qstatus = GetQueueStatus(qs_all_input);
8107 todo_wine {
8108     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8109        "wrong qstatus %08x\n", qstatus);
8110 }
8111
8112     msg.message = 0;
8113     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8114     ok(!ret,
8115        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8116         msg.message);
8117     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8118
8119     qstatus = GetQueueStatus(qs_all_input);
8120     ok(qstatus == 0,
8121        "wrong qstatus %08x\n", qstatus);
8122
8123     trace("signalling to exit\n");
8124     SetEvent(info.hevent[EV_START_STOP]);
8125
8126     WaitForSingleObject(hthread, INFINITE);
8127
8128     CloseHandle(hthread);
8129     CloseHandle(info.hevent[0]);
8130     CloseHandle(info.hevent[1]);
8131     CloseHandle(info.hevent[2]);
8132
8133     DestroyWindow(info.hwnd);
8134 }
8135
8136
8137 static void test_quit_message(void)
8138 {
8139     MSG msg;
8140     BOOL ret;
8141
8142     /* test using PostQuitMessage */
8143     PostQuitMessage(0xbeef);
8144
8145     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8146     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8147     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8148     ok(msg.wParam == 0xbeef, "wParam was 0x%x instead of 0xbeef\n", msg.wParam);
8149
8150     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8151     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8152
8153     ret = GetMessage(&msg, NULL, 0, 0);
8154     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8155     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8156
8157     /* note: WM_QUIT message received after WM_USER message */
8158     ret = GetMessage(&msg, NULL, 0, 0);
8159     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8160     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8161     ok(msg.wParam == 0xbeef, "wParam was 0x%x instead of 0xbeef\n", msg.wParam);
8162
8163     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8164     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8165
8166     /* now test with PostThreadMessage - different behaviour! */
8167     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8168
8169     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8170     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8171     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8172     ok(msg.wParam == 0xdead, "wParam was 0x%x instead of 0xdead\n", msg.wParam);
8173
8174     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8175     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8176
8177     /* note: we receive the WM_QUIT message first this time */
8178     ret = GetMessage(&msg, NULL, 0, 0);
8179     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8180     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8181     ok(msg.wParam == 0xdead, "wParam was 0x%x instead of 0xdead\n", msg.wParam);
8182
8183     ret = GetMessage(&msg, NULL, 0, 0);
8184     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8185     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8186 }
8187
8188 static const struct message WmMouseHoverSeq[] = {
8189     { WM_TIMER, sent|optional }, /* XP sends it */
8190     { WM_SYSTIMER, sent },
8191     { WM_MOUSEHOVER, sent|wparam, 0 },
8192     { 0 }
8193 };
8194
8195 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8196 {
8197     MSG msg;
8198     DWORD start_ticks, end_ticks;
8199
8200     start_ticks = GetTickCount();
8201     /* add some deviation (5%) to cover not expected delays */
8202     start_ticks += timeout / 20;
8203
8204     do
8205     {
8206         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8207         {
8208             /* Timer proc messages are not dispatched to the window proc,
8209              * and therefore not logged.
8210              */
8211             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8212             {
8213                 struct message s_msg;
8214
8215                 s_msg.message = msg.message;
8216                 s_msg.flags = sent|wparam|lparam;
8217                 s_msg.wParam = msg.wParam;
8218                 s_msg.lParam = msg.lParam;
8219                 add_message(&s_msg);
8220             }
8221             DispatchMessage(&msg);
8222         }
8223
8224         end_ticks = GetTickCount();
8225
8226         /* inject WM_MOUSEMOVE to see how it changes tracking */
8227         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
8228         {
8229             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8230             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8231
8232             inject_mouse_move = FALSE;
8233         }
8234     } while (start_ticks + timeout >= end_ticks);
8235 }
8236
8237 static void test_TrackMouseEvent(void)
8238 {
8239     MSG msg;
8240     TRACKMOUSEEVENT tme;
8241     BOOL ret;
8242     HWND hwnd, hchild;
8243     RECT rc_parent, rc_child;
8244     UINT default_hover_time, hover_width = 0, hover_height = 0;
8245
8246 #define track_hover(track_hwnd, track_hover_time) \
8247     tme.cbSize = sizeof(tme); \
8248     tme.dwFlags = TME_HOVER; \
8249     tme.hwndTrack = track_hwnd; \
8250     tme.dwHoverTime = track_hover_time; \
8251     SetLastError(0xdeadbeef); \
8252     ret = TrackMouseEvent(&tme); \
8253     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
8254
8255 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
8256     tme.cbSize = sizeof(tme); \
8257     tme.dwFlags = TME_QUERY; \
8258     tme.hwndTrack = (HWND)0xdeadbeef; \
8259     tme.dwHoverTime = 0xdeadbeef; \
8260     SetLastError(0xdeadbeef); \
8261     ret = TrackMouseEvent(&tme); \
8262     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
8263     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
8264     ok(tme.dwFlags == (expected_track_flags), \
8265        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
8266     ok(tme.hwndTrack == (expected_track_hwnd), \
8267        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
8268     ok(tme.dwHoverTime == (expected_hover_time), \
8269        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
8270
8271 #define track_hover_cancel(track_hwnd) \
8272     tme.cbSize = sizeof(tme); \
8273     tme.dwFlags = TME_HOVER | TME_CANCEL; \
8274     tme.hwndTrack = track_hwnd; \
8275     tme.dwHoverTime = 0xdeadbeef; \
8276     SetLastError(0xdeadbeef); \
8277     ret = TrackMouseEvent(&tme); \
8278     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
8279
8280     default_hover_time = 0xdeadbeef;
8281     SetLastError(0xdeadbeef);
8282     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
8283     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
8284     if (!ret) default_hover_time = 400;
8285     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
8286
8287     SetLastError(0xdeadbeef);
8288     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
8289     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
8290     if (!ret) hover_width = 4;
8291     SetLastError(0xdeadbeef);
8292     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
8293     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
8294     if (!ret) hover_height = 4;
8295     trace("hover rect is %u x %d\n", hover_width, hover_height);
8296
8297     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
8298                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8299                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8300                           NULL, NULL, 0);
8301     assert(hwnd);
8302
8303     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
8304                           WS_CHILD | WS_BORDER | WS_VISIBLE,
8305                           50, 50, 200, 200, hwnd,
8306                           NULL, NULL, 0);
8307     assert(hchild);
8308
8309     flush_events();
8310     flush_sequence();
8311
8312     tme.cbSize = 0;
8313     tme.dwFlags = TME_QUERY;
8314     tme.hwndTrack = (HWND)0xdeadbeef;
8315     tme.dwHoverTime = 0xdeadbeef;
8316     SetLastError(0xdeadbeef);
8317     ret = TrackMouseEvent(&tme);
8318     ok(!ret, "TrackMouseEvent should fail\n");
8319     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
8320
8321     tme.cbSize = sizeof(tme);
8322     tme.dwFlags = TME_HOVER;
8323     tme.hwndTrack = (HWND)0xdeadbeef;
8324     tme.dwHoverTime = 0xdeadbeef;
8325     SetLastError(0xdeadbeef);
8326     ret = TrackMouseEvent(&tme);
8327     ok(!ret, "TrackMouseEvent should fail\n");
8328     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8329
8330     tme.cbSize = sizeof(tme);
8331     tme.dwFlags = TME_HOVER | TME_CANCEL;
8332     tme.hwndTrack = (HWND)0xdeadbeef;
8333     tme.dwHoverTime = 0xdeadbeef;
8334     SetLastError(0xdeadbeef);
8335     ret = TrackMouseEvent(&tme);
8336     ok(!ret, "TrackMouseEvent should fail\n");
8337     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8338
8339     GetWindowRect(hwnd, &rc_parent);
8340     GetWindowRect(hchild, &rc_child);
8341     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
8342
8343     /* Process messages so that the system updates its internal current
8344      * window and hittest, otherwise TrackMouseEvent calls don't have any
8345      * effect.
8346      */
8347     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8348     flush_sequence();
8349
8350     track_query(0, NULL, 0);
8351     track_hover(hchild, 0);
8352     track_query(0, NULL, 0);
8353
8354     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8355     flush_sequence();
8356
8357     track_hover(hwnd, 0);
8358     track_query(TME_HOVER, hwnd, default_hover_time);
8359
8360     pump_msg_loop_timeout(default_hover_time, FALSE);
8361     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8362
8363     track_query(0, NULL, 0);
8364
8365     track_hover(hwnd, HOVER_DEFAULT);
8366     track_query(TME_HOVER, hwnd, default_hover_time);
8367
8368     Sleep(default_hover_time / 2);
8369     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8370     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8371
8372     track_query(TME_HOVER, hwnd, default_hover_time);
8373
8374     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
8375     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8376
8377     track_query(0, NULL, 0);
8378
8379     track_hover(hwnd, HOVER_DEFAULT);
8380     track_query(TME_HOVER, hwnd, default_hover_time);
8381
8382     pump_msg_loop_timeout(default_hover_time, TRUE);
8383     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8384
8385     track_query(0, NULL, 0);
8386
8387     track_hover(hwnd, HOVER_DEFAULT);
8388     track_query(TME_HOVER, hwnd, default_hover_time);
8389     track_hover_cancel(hwnd);
8390
8391     DestroyWindow(hwnd);
8392
8393 #undef track_hover
8394 #undef track_query
8395 #undef track_hover_cancel
8396 }
8397
8398
8399 static const struct message WmSetWindowRgn[] = {
8400     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8401     { WM_NCCALCSIZE, sent|wparam, 1 },
8402     { WM_NCPAINT, sent }, /* wparam != 1 */
8403     { WM_GETTEXT, sent|defwinproc|optional },
8404     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8405     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8406     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8407     { 0 }
8408 };
8409
8410 static const struct message WmSetWindowRgn_no_redraw[] = {
8411     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8412     { WM_NCCALCSIZE, sent|wparam, 1 },
8413     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8414     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8415     { 0 }
8416 };
8417
8418 static const struct message WmSetWindowRgn_clear[] = {
8419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8420     { WM_NCCALCSIZE, sent|wparam, 1 },
8421     { WM_NCPAINT, sent }, /* wparam != 1 */
8422     { WM_GETTEXT, sent|defwinproc|optional },
8423     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8424     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8425     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
8426     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
8427     { WM_GETTEXT, sent|defwinproc|optional },
8428     { WM_ERASEBKGND, sent|optional },
8429     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8430     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8431     { 0 }
8432 };
8433
8434 static void test_SetWindowRgn(void)
8435 {
8436     HRGN hrgn;
8437     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8438                                 100, 100, 200, 200, 0, 0, 0, NULL);
8439     ok( hwnd != 0, "Failed to create overlapped window\n" );
8440
8441     ShowWindow( hwnd, SW_SHOW );
8442     UpdateWindow( hwnd );
8443     flush_events();
8444     flush_sequence();
8445
8446     trace("testing SetWindowRgn\n");
8447     hrgn = CreateRectRgn( 0, 0, 150, 150 );
8448     SetWindowRgn( hwnd, hrgn, TRUE );
8449     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
8450
8451     hrgn = CreateRectRgn( 30, 30, 160, 160 );
8452     SetWindowRgn( hwnd, hrgn, FALSE );
8453     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
8454
8455     hrgn = CreateRectRgn( 0, 0, 180, 180 );
8456     SetWindowRgn( hwnd, hrgn, TRUE );
8457     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
8458
8459     SetWindowRgn( hwnd, 0, TRUE );
8460     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
8461
8462     DestroyWindow( hwnd );
8463 }
8464
8465 /*************************** ShowWindow() test ******************************/
8466 static const struct message WmShowNormal[] = {
8467     { WM_SHOWWINDOW, sent|wparam, 1 },
8468     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8469     { HCBT_ACTIVATE, hook },
8470     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8471     { HCBT_SETFOCUS, hook },
8472     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8473     { 0 }
8474 };
8475 static const struct message WmShow[] = {
8476     { WM_SHOWWINDOW, sent|wparam, 1 },
8477     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8478     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8479     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8480     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8481     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8482     { 0 }
8483 };
8484 static const struct message WmShowNoActivate_1[] = {
8485     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8486     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8487     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8488     { WM_MOVE, sent|defwinproc },
8489     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8490     { 0 }
8491 };
8492 static const struct message WmShowNoActivate_2[] = {
8493     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8494     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8495     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8496     { WM_MOVE, sent|defwinproc },
8497     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8498     { HCBT_SETFOCUS, hook },
8499     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8500     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8501     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8502     { 0 }
8503 };
8504 static const struct message WmShowNA_1[] = {
8505     { WM_SHOWWINDOW, sent|wparam, 1 },
8506     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8507     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8508     { 0 }
8509 };
8510 static const struct message WmShowNA_2[] = {
8511     { WM_SHOWWINDOW, sent|wparam, 1 },
8512     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8513     { 0 }
8514 };
8515 static const struct message WmRestore_1[] = {
8516     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8517     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8518     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8519     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8520     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8521     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8522     { WM_MOVE, sent|defwinproc },
8523     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8524     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8525     { 0 }
8526 };
8527 static const struct message WmRestore_2[] = {
8528     { WM_SHOWWINDOW, sent|wparam, 1 },
8529     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8530     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8531     { 0 }
8532 };
8533 static const struct message WmRestore_3[] = {
8534     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8535     { WM_GETMINMAXINFO, sent },
8536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8537     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8538     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8539     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8540     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8541     { WM_MOVE, sent|defwinproc },
8542     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8543     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8544     { 0 }
8545 };
8546 static const struct message WmRestore_4[] = {
8547     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8548     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8549     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8550     { WM_MOVE, sent|defwinproc },
8551     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8552     { 0 }
8553 };
8554 static const struct message WmRestore_5[] = {
8555     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
8556     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8557     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8558     { WM_MOVE, sent|defwinproc },
8559     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8560     { 0 }
8561 };
8562 static const struct message WmHide_1[] = {
8563     { WM_SHOWWINDOW, sent|wparam, 0 },
8564     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8565     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8566     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8567     { 0 }
8568 };
8569 static const struct message WmHide_2[] = {
8570     { WM_SHOWWINDOW, sent|wparam, 0 },
8571     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8572     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8573     { 0 }
8574 };
8575 static const struct message WmHide_3[] = {
8576     { WM_SHOWWINDOW, sent|wparam, 0 },
8577     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8578     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8579     { HCBT_SETFOCUS, hook },
8580     { 0 }
8581 };
8582 static const struct message WmShowMinimized_1[] = {
8583     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8584     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8585     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8586     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8587     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8588     { WM_MOVE, sent|defwinproc },
8589     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8590     { 0 }
8591 };
8592 static const struct message WmMinimize_1[] = {
8593     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8594     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8595     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8596     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8597     { WM_MOVE, sent|defwinproc },
8598     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8599     { 0 }
8600 };
8601 static const struct message WmMinimize_2[] = {
8602     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8603     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8604     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8605     { WM_MOVE, sent|defwinproc },
8606     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8607     { 0 }
8608 };
8609 static const struct message WmMinimize_3[] = {
8610     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8611     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8612     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8613     { WM_MOVE, sent|defwinproc },
8614     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8615     { 0 }
8616 };
8617 static const struct message WmShowMinNoActivate[] = {
8618     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8619     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8620     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8621     { 0 }
8622 };
8623 static const struct message WmMinMax_1[] = {
8624     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8625     { 0 }
8626 };
8627 static const struct message WmMinMax_2[] = {
8628     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8629     { 0 }
8630 };
8631 static const struct message WmMinMax_3[] = {
8632     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8633     { 0 }
8634 };
8635 static const struct message WmMinMax_4[] = {
8636     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8637     { 0 }
8638 };
8639 static const struct message WmShowMaximized_1[] = {
8640     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8641     { WM_GETMINMAXINFO, sent },
8642     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8643     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8644     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8645     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8646     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8647     { WM_MOVE, sent|defwinproc },
8648     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8649     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8650     { 0 }
8651 };
8652 static const struct message WmShowMaximized_2[] = {
8653     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8654     { WM_GETMINMAXINFO, sent },
8655     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
8656     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8657     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
8658     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
8659     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8660     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8661     { WM_MOVE, sent|defwinproc },
8662     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8663     { HCBT_SETFOCUS, hook },
8664     { 0 }
8665 };
8666 static const struct message WmShowMaximized_3[] = {
8667     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8668     { WM_GETMINMAXINFO, sent },
8669     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8670     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8671     { WM_MOVE, sent|defwinproc },
8672     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8673     { 0 }
8674 };
8675
8676 static void test_ShowWindow(void)
8677 {
8678     /* ShowWindow commands in random order */
8679     static const struct
8680     {
8681         INT cmd; /* ShowWindow command */
8682         LPARAM ret; /* ShowWindow return value */
8683         DWORD style; /* window style after the command */
8684         const struct message *msg; /* message sequence the command produces */
8685         BOOL todo_msg; /* message sequence doesn't match what Wine does */
8686     } sw[] =
8687     {
8688 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
8689 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8690 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
8691 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8692 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
8693 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
8694 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
8695 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8696 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
8697 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
8698 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
8699 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
8700 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
8701 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8702 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
8703 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8704 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
8705 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8706 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
8707 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8708 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8709 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
8710 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
8711 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8712 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8713 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
8714 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
8715 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8716 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8717 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
8718 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8719 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
8720 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8721 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE }, /* what does this mean?! */
8722 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE },
8723 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8724 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
8725 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8726 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8727 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, TRUE },
8728 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8729 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
8730 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
8731 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
8732 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8733 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
8734 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
8735 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
8736 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
8737 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
8738 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8739 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
8740 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8741 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, TRUE },
8742 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8743 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
8744 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
8745     };
8746     HWND hwnd;
8747     DWORD style;
8748     LPARAM ret;
8749     INT i;
8750
8751 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
8752     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
8753                           120, 120, 90, 90,
8754                           0, 0, 0, NULL);
8755     assert(hwnd);
8756
8757     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
8758     ok(style == 0, "expected style 0, got %08x\n", style);
8759
8760     flush_events();
8761     flush_sequence();
8762
8763     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
8764     {
8765         static const char * const sw_cmd_name[13] =
8766         {
8767             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
8768             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
8769             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
8770             "SW_NORMALNA" /* 0xCC */
8771         };
8772         char comment[64];
8773         INT idx; /* index into the above array of names */
8774
8775         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
8776
8777         style = GetWindowLong(hwnd, GWL_STYLE);
8778         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
8779         ret = ShowWindow(hwnd, sw[i].cmd);
8780         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
8781         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
8782         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
8783
8784         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
8785         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
8786
8787         flush_events();
8788         flush_sequence();
8789     }
8790
8791     DestroyWindow(hwnd);
8792 }
8793
8794 static const struct message WmDefDlgSetFocus_1[] = {
8795     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
8796     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
8797     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
8798     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
8799     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
8800     { HCBT_SETFOCUS, hook },
8801     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8802     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8803     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8804     { WM_SETFOCUS, sent|wparam, 0 },
8805     { WM_CTLCOLOREDIT, sent },
8806     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8807     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8808     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8809     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
8810     { 0 }
8811 };
8812 static const struct message WmDefDlgSetFocus_2[] = {
8813     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
8814     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
8815     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
8816     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
8817     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
8818     { 0 }
8819 };
8820
8821 static void test_dialog_messages(void)
8822 {
8823     HWND hdlg, hedit1, hedit2, hfocus;
8824     LRESULT ret;
8825
8826 #define set_selection(hctl, start, end) \
8827     ret = SendMessage(hctl, EM_SETSEL, start, end); \
8828     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
8829
8830 #define check_selection(hctl, start, end) \
8831     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
8832     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
8833
8834     subclass_edit();
8835
8836     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
8837                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
8838                           0, 0, 100, 100, 0, 0, 0, NULL);
8839     ok(hdlg != 0, "Failed to create custom dialog window\n");
8840
8841     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
8842                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
8843                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
8844     ok(hedit1 != 0, "Failed to create edit control\n");
8845     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
8846                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
8847                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
8848     ok(hedit2 != 0, "Failed to create edit control\n");
8849
8850     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
8851     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
8852
8853     hfocus = GetFocus();
8854     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
8855
8856     SetFocus(hedit2);
8857     hfocus = GetFocus();
8858     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
8859
8860     check_selection(hedit1, 0, 0);
8861     check_selection(hedit2, 0, 0);
8862
8863     set_selection(hedit2, 0, -1);
8864     check_selection(hedit2, 0, 3);
8865
8866     SetFocus(0);
8867     hfocus = GetFocus();
8868     ok(hfocus == 0, "wrong focus %p\n", hfocus);
8869
8870     flush_sequence();
8871     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
8872     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
8873     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
8874
8875     hfocus = GetFocus();
8876     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
8877
8878     check_selection(hedit1, 0, 5);
8879     check_selection(hedit2, 0, 3);
8880
8881     flush_sequence();
8882     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
8883     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
8884     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
8885
8886     hfocus = GetFocus();
8887     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
8888
8889     check_selection(hedit1, 0, 5);
8890     check_selection(hedit2, 0, 3);
8891
8892     EndDialog(hdlg, 0);
8893
8894 #undef set_selection
8895 #undef check_selection
8896 }
8897
8898 static void test_nullCallback(void)
8899 {
8900     HWND hwnd;
8901     MSG msg;
8902
8903     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8904                            100, 100, 200, 200, 0, 0, 0, NULL);
8905     ok (hwnd != 0, "Failed to create overlapped window\n");
8906
8907     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
8908     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8909     DestroyWindow(hwnd);
8910 }
8911
8912 START_TEST(msg)
8913 {
8914     BOOL ret;
8915     HMODULE user32 = GetModuleHandleA("user32.dll");
8916     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
8917     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
8918     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
8919     pGetAncestor = (void*) GetProcAddress(user32, "GetAncestor");
8920
8921     if (!RegisterWindowClasses()) assert(0);
8922
8923     if (pSetWinEventHook)
8924     {
8925         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8926                                                       GetModuleHandleA(0),
8927                                                       win_event_proc,
8928                                                       0,
8929                                                       GetCurrentThreadId(),
8930                                                       WINEVENT_INCONTEXT);
8931         assert(hEvent_hook);
8932
8933         if (pIsWinEventHookInstalled)
8934         {
8935             UINT event;
8936             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
8937                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
8938         }
8939     }
8940
8941     cbt_hook_thread_id = GetCurrentThreadId();
8942     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
8943     assert(hCBT_hook);
8944
8945     test_winevents();
8946
8947     /* Fix message sequences before removing 4 lines below */
8948 #if 1
8949     if (pUnhookWinEvent && hEvent_hook)
8950     {
8951         ret = pUnhookWinEvent(hEvent_hook);
8952         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8953         pUnhookWinEvent = 0;
8954     }
8955     hEvent_hook = 0;
8956 #endif
8957
8958     test_ShowWindow();
8959     test_PeekMessage();
8960     test_scrollwindowex();
8961     test_messages();
8962     test_showwindow();
8963     invisible_parent_tests();
8964     test_mdi_messages();
8965     test_button_messages();
8966     test_static_messages();
8967     test_paint_messages();
8968     test_interthread_messages();
8969     test_message_conversion();
8970     test_accelerators();
8971     test_timers();
8972     test_set_hook();
8973     test_DestroyWindow();
8974     test_DispatchMessage();
8975     test_SendMessageTimeout();
8976     test_edit_messages();
8977     test_quit_message();
8978     test_TrackMouseEvent();
8979     test_SetWindowRgn();
8980     test_sys_menu();
8981     test_dialog_messages();
8982     test_nullCallback();
8983
8984     UnhookWindowsHookEx(hCBT_hook);
8985     if (pUnhookWinEvent)
8986     {
8987         ret = pUnhookWinEvent(hEvent_hook);
8988         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8989         SetLastError(0xdeadbeef);
8990         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
8991         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8992            GetLastError() == 0xdeadbeef, /* Win9x */
8993            "unexpected error %d\n", GetLastError());
8994     }
8995 }