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