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