msi: Set all folders' source paths to the root directory if the source type is compre...
[wine] / dlls / user32 / tests / msg.c
1 /*
2  * Unit tests for window message handling
3  *
4  * Copyright 1999 Ove Kaaven
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2004, 2005 Dmitry Timoshkov
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42 #define SWP_STATECHANGED        0x8000
43
44 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
45
46 #ifndef WM_KEYF1
47 #define WM_KEYF1 0x004d
48 #endif
49
50 #ifndef WM_SYSTIMER
51 #define WM_SYSTIMER         0x0118
52 #endif
53
54 #define WND_PARENT_ID           1
55 #define WND_POPUP_ID            2
56 #define WND_CHILD_ID            3
57
58 #ifndef WM_LBTRACKPOINT
59 #define WM_LBTRACKPOINT  0x0131
60 #endif
61
62 /* encoded DRAWITEMSTRUCT into an LPARAM */
63 typedef struct
64 {
65     union
66     {
67         struct
68         {
69             UINT type    : 4;  /* ODT_* flags */
70             UINT ctl_id  : 4;  /* Control ID */
71             UINT item_id : 4;  /* Menu item ID */
72             UINT action  : 4;  /* ODA_* flags */
73             UINT state   : 16; /* ODS_* flags */
74         } item;
75         LPARAM lp;
76     } u;
77 } DRAW_ITEM_STRUCT;
78
79 static BOOL test_DestroyWindow_flag;
80 static HWINEVENTHOOK hEvent_hook;
81
82 static void dump_winpos_flags(UINT flags);
83
84 static const WCHAR testWindowClassW[] =
85 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
86
87 /*
88 FIXME: add tests for these
89 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
90  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
91  WS_THICKFRAME: thick border
92  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
93  WS_BORDER (default for overlapped windows): single black border
94  none (default for child (and popup?) windows): no border
95 */
96
97 typedef enum {
98     sent=0x1,
99     posted=0x2,
100     parent=0x4,
101     wparam=0x8,
102     lparam=0x10,
103     defwinproc=0x20,
104     beginpaint=0x40,
105     optional=0x80,
106     hook=0x100,
107     winevent_hook=0x200
108 } msg_flags_t;
109
110 struct message {
111     UINT message;          /* the WM_* code */
112     msg_flags_t flags;     /* message props */
113     WPARAM wParam;         /* expected value of wParam */
114     LPARAM lParam;         /* expected value of lParam */
115 };
116
117 /* Empty message sequence */
118 static const struct message WmEmptySeq[] =
119 {
120     { 0 }
121 };
122 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
123 static const struct message WmCreateOverlappedSeq[] = {
124     { HCBT_CREATEWND, hook },
125     { WM_GETMINMAXINFO, sent },
126     { WM_NCCREATE, sent },
127     { WM_NCCALCSIZE, sent|wparam, 0 },
128     { 0x0093, sent|defwinproc|optional },
129     { 0x0094, sent|defwinproc|optional },
130     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
131     { WM_CREATE, sent },
132     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
133     { 0 }
134 };
135 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
136  * for a not visible overlapped window.
137  */
138 static const struct message WmSWP_ShowOverlappedSeq[] = {
139     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
140     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
141     { WM_NCPAINT, sent|wparam|optional, 1 },
142     { WM_GETTEXT, sent|defwinproc|optional },
143     { WM_ERASEBKGND, sent|optional },
144     { HCBT_ACTIVATE, hook },
145     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
146     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
147     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
148     { WM_ACTIVATEAPP, sent|wparam, 1 },
149     { WM_NCACTIVATE, sent|wparam, 1 },
150     { WM_GETTEXT, sent|defwinproc|optional },
151     { WM_ACTIVATE, sent|wparam, 1 },
152     { HCBT_SETFOCUS, hook },
153     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
154     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
155     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
156     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
157     { WM_NCPAINT, sent|wparam|optional, 1 },
158     { WM_GETTEXT, sent|defwinproc|optional },
159     { WM_ERASEBKGND, sent|optional },
160     /* Win9x adds SWP_NOZORDER below */
161     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
162     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
163     { WM_NCPAINT, sent|wparam|optional, 1 },
164     { WM_ERASEBKGND, sent|optional },
165     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
166     { 0 }
167 };
168 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
169  * for a visible overlapped window.
170  */
171 static const struct message WmSWP_HideOverlappedSeq[] = {
172     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
173     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
174     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
175     { 0 }
176 };
177
178 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
179  * for a visible overlapped window.
180  */
181 static const struct message WmSWP_ResizeSeq[] = {
182     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
183     { WM_GETMINMAXINFO, sent|defwinproc },
184     { WM_NCCALCSIZE, sent|wparam, TRUE },
185     { WM_NCPAINT, sent|optional },
186     { WM_GETTEXT, sent|defwinproc|optional },
187     { WM_ERASEBKGND, sent|optional },
188     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
189     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
190     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
191     { WM_NCPAINT, sent|optional },
192     { WM_GETTEXT, sent|defwinproc|optional },
193     { WM_ERASEBKGND, sent|optional },
194     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
195     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
196     { 0 }
197 };
198
199 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
200  * for a visible popup window.
201  */
202 static const struct message WmSWP_ResizePopupSeq[] = {
203     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
204     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
205     { WM_NCCALCSIZE, sent|wparam, TRUE },
206     { WM_NCPAINT, sent|optional },
207     { WM_GETTEXT, sent|defwinproc|optional },
208     { WM_ERASEBKGND, sent|optional },
209     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
210     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
211     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
212     { WM_NCPAINT, sent|optional },
213     { WM_GETTEXT, sent|defwinproc|optional },
214     { WM_ERASEBKGND, sent|optional },
215     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
216     { 0 }
217 };
218
219 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
220  * for a visible overlapped window.
221  */
222 static const struct message WmSWP_MoveSeq[] = {
223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
224     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
225     { WM_MOVE, sent|defwinproc|wparam, 0 },
226     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
227     { 0 }
228 };
229 /* Resize with SetWindowPos(SWP_NOZORDER)
230  * for a visible overlapped window
231  * SWP_NOZORDER is stripped by the logging code
232  */
233 static const struct message WmSWP_ResizeNoZOrder[] = {
234     { WM_WINDOWPOSCHANGING, sent|wparam, 0/*SWP_NOZORDER*/ },
235     { WM_GETMINMAXINFO, sent|defwinproc },
236     { WM_NCCALCSIZE, sent|wparam, 1 },
237     { WM_NCPAINT, sent },
238     { WM_GETTEXT, sent|defwinproc|optional },
239     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
240     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE },
241     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
242     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
243     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
244     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
245     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
246     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
247     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
248     { 0 }
249 };
250
251 /* Switch visible mdi children */
252 static const struct message WmSwitchChild[] = {
253     /* Switch MDI child */
254     { WM_MDIACTIVATE, sent },/* in the MDI client */
255     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
256     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
257     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
258     /* Deactivate 2nd MDI child */
259     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
260     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
261     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
262     /* Preparing for maximize and maximaze the 1st MDI child */
263     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
264     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
265     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
266     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
267     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
268     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
269     /* Lock redraw 2nd MDI child */
270     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
271     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
272     /* Restore 2nd MDI child */
273     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
274     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
275     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
276     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
277     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
278     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
279     /* Redraw 2nd MDI child */
280     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
281     /* Redraw MDI frame */
282     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
283     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
284     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
285     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
286     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
287     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
288     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
289     { HCBT_SETFOCUS, hook },
290     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
291     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
292     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
293     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
294     { WM_SETFOCUS, sent },/* in the MDI client */
295     { HCBT_SETFOCUS, hook },
296     { WM_KILLFOCUS, sent },/* in the MDI client */
297     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
298     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
299     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
300     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
301     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
302     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
303     { 0 }
304 };
305
306 /* Switch visible not maximized mdi children */
307 static const struct message WmSwitchNotMaximizedChild[] = {
308     /* Switch not maximized MDI child */
309     { WM_MDIACTIVATE, sent },/* in the MDI client */
310     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
311     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
312     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
313     /* Deactivate 1st MDI child */
314     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
315     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
316     /* Activate 2nd MDI child */
317     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
318     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
319     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
320     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
321     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
322     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
323     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
324     { HCBT_SETFOCUS, hook },
325     { WM_KILLFOCUS, sent }, /* in the  MDI client */
326     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
327     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
328     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
329     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
330     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
331     { 0 }
332 };
333
334
335 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
336                 SWP_NOZORDER|SWP_FRAMECHANGED)
337  * for a visible overlapped window with WS_CLIPCHILDREN style set.
338  */
339 static const struct message WmSWP_FrameChanged_clip[] = {
340     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
341     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
342     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
343     { WM_GETTEXT, sent|parent|defwinproc|optional },
344     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
345     { WM_NCPAINT, sent }, /* wparam != 1 */
346     { WM_ERASEBKGND, sent },
347     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
348     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
349     { WM_PAINT, sent },
350     { 0 }
351 };
352 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
353                 SWP_NOZORDER|SWP_FRAMECHANGED)
354  * for a visible overlapped window.
355  */
356 static const struct message WmSWP_FrameChangedDeferErase[] = {
357     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
358     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
359     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
360     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
361     { WM_PAINT, sent|parent },
362     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
363     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
364     { WM_PAINT, sent },
365     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
366     { WM_ERASEBKGND, sent|beginpaint },
367     { 0 }
368 };
369
370 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
371                 SWP_NOZORDER|SWP_FRAMECHANGED)
372  * for a visible overlapped window without WS_CLIPCHILDREN style set.
373  */
374 static const struct message WmSWP_FrameChanged_noclip[] = {
375     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
376     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
377     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
378     { WM_GETTEXT, sent|parent|defwinproc|optional },
379     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
380     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
382     { WM_PAINT, sent },
383     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
384     { WM_ERASEBKGND, sent|beginpaint },
385     { 0 }
386 };
387
388 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
389 static const struct message WmShowOverlappedSeq[] = {
390     { WM_SHOWWINDOW, sent|wparam, 1 },
391     { WM_NCPAINT, sent|wparam|optional, 1 },
392     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
393     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
394     { WM_NCPAINT, sent|wparam|optional, 1 },
395     { WM_GETTEXT, sent|defwinproc|optional },
396     { WM_ERASEBKGND, sent|optional },
397     { HCBT_ACTIVATE, hook },
398     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
399     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
400     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
401     { WM_NCPAINT, sent|wparam|optional, 1 },
402     { WM_ACTIVATEAPP, sent|wparam, 1 },
403     { WM_NCACTIVATE, sent|wparam, 1 },
404     { WM_GETTEXT, sent|defwinproc|optional },
405     { WM_ACTIVATE, sent|wparam, 1 },
406     { HCBT_SETFOCUS, hook },
407     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
408     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
409     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
410     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
411     { WM_NCPAINT, sent|wparam|optional, 1 },
412     { WM_GETTEXT, sent|defwinproc|optional },
413     { WM_ERASEBKGND, sent|optional },
414     /* Win9x adds SWP_NOZORDER below */
415     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
416     { WM_NCCALCSIZE, sent|optional },
417     { WM_NCPAINT, sent|optional },
418     { WM_ERASEBKGND, sent|optional },
419 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
420        * messages. Does that mean that CreateWindow doesn't set initial
421        * window dimensions for overlapped windows?
422        */
423     { WM_SIZE, sent },
424     { WM_MOVE, sent },
425 #endif
426     { 0 }
427 };
428 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
429 static const struct message WmShowMaxOverlappedSeq[] = {
430     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
431     { WM_GETMINMAXINFO, sent },
432     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
433     { WM_GETMINMAXINFO, sent|defwinproc },
434     { WM_NCCALCSIZE, sent|wparam, TRUE },
435     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
436     { HCBT_ACTIVATE, hook },
437     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
438     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
439     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
440     { WM_ACTIVATEAPP, sent|wparam, 1 },
441     { WM_NCACTIVATE, sent|wparam, 1 },
442     { WM_GETTEXT, sent|defwinproc|optional },
443     { WM_ACTIVATE, sent|wparam, 1 },
444     { HCBT_SETFOCUS, hook },
445     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
446     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
447     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
448     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
449     { WM_NCPAINT, sent|wparam|optional, 1 },
450     { WM_GETTEXT, sent|defwinproc|optional },
451     { WM_ERASEBKGND, sent|optional },
452     /* Win9x adds SWP_NOZORDER below */
453     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
454     { WM_MOVE, sent|defwinproc },
455     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
456     { WM_NCCALCSIZE, sent|optional },
457     { WM_NCPAINT, sent|optional },
458     { WM_ERASEBKGND, sent|optional },
459     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
460     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
461     { 0 }
462 };
463 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
464 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
465     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
466     { WM_GETTEXT, sent|optional },
467     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
468     { WM_GETMINMAXINFO, sent|defwinproc },
469     { WM_NCCALCSIZE, sent|wparam, TRUE },
470     { WM_NCPAINT, sent|wparam|optional, 1 },
471     { WM_GETTEXT, sent|defwinproc|optional },
472     { WM_ERASEBKGND, sent },
473     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
474     { WM_MOVE, sent|defwinproc },
475     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
476     { 0 }
477 };
478 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
479 static const struct message WmShowRestoreMinOverlappedSeq[] = {
480     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
481     { WM_QUERYOPEN, sent|optional },
482     { WM_GETTEXT, sent|optional },
483     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
484     { WM_GETMINMAXINFO, sent|defwinproc },
485     { WM_NCCALCSIZE, sent|wparam, TRUE },
486     { HCBT_ACTIVATE, hook },
487     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
488     { WM_ACTIVATEAPP, sent|wparam, 1 },
489     { WM_NCACTIVATE, sent|wparam, 1 },
490     { WM_GETTEXT, sent|defwinproc|optional },
491     { WM_ACTIVATE, sent|wparam, 1 },
492     { HCBT_SETFOCUS, hook },
493     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
494     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
495     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
496     { WM_NCPAINT, sent|wparam|optional, 1 },
497     { WM_GETTEXT, sent|defwinproc|optional },
498     { WM_ERASEBKGND, sent },
499     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
500     { WM_MOVE, sent|defwinproc },
501     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
502     { WM_ACTIVATE, sent|wparam, 1 },
503     { 0 }
504 };
505 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
506 static const struct message WmShowMinOverlappedSeq[] = {
507     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
508     { HCBT_SETFOCUS, hook },
509     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
510     { WM_KILLFOCUS, sent },
511     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
512     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
513     { WM_GETTEXT, sent|optional },
514     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
515     { WM_GETMINMAXINFO, sent|defwinproc },
516     { WM_NCCALCSIZE, sent|wparam, TRUE },
517     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
518     { WM_NCPAINT, sent },
519     { WM_GETTEXT, sent|defwinproc|optional },
520     { WM_WINDOWPOSCHANGED, sent },
521     { WM_MOVE, sent|defwinproc },
522     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
523     { WM_NCCALCSIZE, sent|optional },
524     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
525     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
526     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
527     { WM_NCACTIVATE, sent|wparam, 0 },
528     { WM_GETTEXT, sent|defwinproc|optional },
529     { WM_ACTIVATE, sent },
530     { WM_ACTIVATEAPP, sent|wparam, 0 },
531     { 0 }
532 };
533 /* ShowWindow(SW_HIDE) for a visible overlapped window */
534 static const struct message WmHideOverlappedSeq[] = {
535     { WM_SHOWWINDOW, sent|wparam, 0 },
536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
537     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
538     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
539     { WM_SIZE, sent|optional }, /* XP doesn't send it */
540     { WM_MOVE, sent|optional }, /* XP doesn't send it */
541     { WM_NCACTIVATE, sent|wparam, 0 },
542     { WM_ACTIVATE, sent|wparam, 0 },
543     { WM_ACTIVATEAPP, sent|wparam, 0 },
544     { WM_KILLFOCUS, sent|wparam, 0 },
545     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
546     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
547     { 0 }
548 };
549 /* DestroyWindow for a visible overlapped window */
550 static const struct message WmDestroyOverlappedSeq[] = {
551     { HCBT_DESTROYWND, hook },
552     { 0x0090, sent|optional },
553     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
554     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
555     { 0x0090, sent|optional },
556     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
557     { WM_NCACTIVATE, sent|wparam, 0 },
558     { WM_ACTIVATE, sent|wparam, 0 },
559     { WM_ACTIVATEAPP, sent|wparam, 0 },
560     { WM_KILLFOCUS, sent|wparam, 0 },
561     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
562     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
563     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
564     { WM_DESTROY, sent },
565     { WM_NCDESTROY, sent },
566     { 0 }
567 };
568 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
569 static const struct message WmCreateMaxPopupSeq[] = {
570     { HCBT_CREATEWND, hook },
571     { WM_NCCREATE, sent },
572     { WM_NCCALCSIZE, sent|wparam, 0 },
573     { WM_CREATE, sent },
574     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
575     { WM_SIZE, sent|wparam, SIZE_RESTORED },
576     { WM_MOVE, sent },
577     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
578     { WM_GETMINMAXINFO, sent },
579     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
580     { WM_NCCALCSIZE, sent|wparam, TRUE },
581     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
582     { WM_MOVE, sent|defwinproc },
583     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
584     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
585     { WM_SHOWWINDOW, sent|wparam, 1 },
586     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
587     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
588     { HCBT_ACTIVATE, hook },
589     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
590     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
591     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
592     { WM_ACTIVATEAPP, sent|wparam, 1 },
593     { WM_NCACTIVATE, sent|wparam, 1 },
594     { WM_ACTIVATE, sent|wparam, 1 },
595     { HCBT_SETFOCUS, hook },
596     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
597     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
598     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
599     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
600     { WM_SYNCPAINT, sent|wparam|optional, 4 },
601     { WM_NCPAINT, sent|wparam|optional, 1 },
602     { WM_ERASEBKGND, sent|optional },
603     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
604     { 0 }
605 };
606 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
607 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
608     { HCBT_CREATEWND, hook },
609     { WM_NCCREATE, sent },
610     { WM_NCCALCSIZE, sent|wparam, 0 },
611     { WM_CREATE, sent },
612     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
613     { WM_SIZE, sent|wparam, SIZE_RESTORED },
614     { WM_MOVE, sent },
615     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
616     { WM_GETMINMAXINFO, sent },
617     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
618     { WM_NCCALCSIZE, sent|wparam, TRUE },
619     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
620     { WM_MOVE, sent|defwinproc },
621     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
622     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
623     { 0 }
624 };
625 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
626 static const struct message WmShowMaxPopupResizedSeq[] = {
627     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
628     { WM_GETMINMAXINFO, sent },
629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
630     { WM_NCCALCSIZE, sent|wparam, TRUE },
631     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
632     { HCBT_ACTIVATE, hook },
633     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
634     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
635     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
636     { WM_ACTIVATEAPP, sent|wparam, 1 },
637     { WM_NCACTIVATE, sent|wparam, 1 },
638     { WM_ACTIVATE, sent|wparam, 1 },
639     { HCBT_SETFOCUS, hook },
640     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
641     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
642     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
643     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
644     { WM_NCPAINT, sent|wparam|optional, 1 },
645     { WM_ERASEBKGND, sent|optional },
646     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
647     /* WinNT4.0 sends WM_MOVE */
648     { WM_MOVE, sent|defwinproc|optional },
649     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
650     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
651     { 0 }
652 };
653 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
654 static const struct message WmShowMaxPopupSeq[] = {
655     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
656     { WM_GETMINMAXINFO, sent },
657     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
658     { WM_NCCALCSIZE, sent|wparam, TRUE },
659     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
660     { HCBT_ACTIVATE, hook },
661     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
662     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
663     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
664     { WM_ACTIVATEAPP, sent|wparam, 1 },
665     { WM_NCACTIVATE, sent|wparam, 1 },
666     { WM_ACTIVATE, sent|wparam, 1 },
667     { HCBT_SETFOCUS, hook },
668     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
669     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
670     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
671     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
672     { WM_SYNCPAINT, sent|wparam|optional, 4 },
673     { WM_NCPAINT, sent|wparam|optional, 1 },
674     { WM_ERASEBKGND, sent|optional },
675     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
676     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
677     { 0 }
678 };
679 /* CreateWindow(WS_VISIBLE) for popup window */
680 static const struct message WmCreatePopupSeq[] = {
681     { HCBT_CREATEWND, hook },
682     { WM_NCCREATE, sent },
683     { WM_NCCALCSIZE, sent|wparam, 0 },
684     { WM_CREATE, sent },
685     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
686     { WM_SIZE, sent|wparam, SIZE_RESTORED },
687     { WM_MOVE, sent },
688     { WM_SHOWWINDOW, sent|wparam, 1 },
689     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
690     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
691     { HCBT_ACTIVATE, hook },
692     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
693     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
694     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
695     { WM_NCPAINT, sent|wparam|optional, 1 },
696     { WM_ERASEBKGND, sent|optional },
697     { WM_ACTIVATEAPP, sent|wparam, 1 },
698     { WM_NCACTIVATE, sent|wparam, 1 },
699     { WM_ACTIVATE, sent|wparam, 1 },
700     { HCBT_SETFOCUS, hook },
701     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
702     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
703     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
704     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
705     { WM_SYNCPAINT, sent|wparam|optional, 4 },
706     { WM_NCPAINT, sent|wparam|optional, 1 },
707     { WM_ERASEBKGND, sent|optional },
708     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
709     { 0 }
710 };
711 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
712 static const struct message WmShowVisMaxPopupSeq[] = {
713     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
714     { WM_GETMINMAXINFO, sent },
715     { WM_GETTEXT, sent|optional },
716     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
717     { WM_NCCALCSIZE, sent|wparam, TRUE },
718     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
719     { WM_NCPAINT, sent|wparam|optional, 1 },
720     { WM_ERASEBKGND, sent|optional },
721     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
722     { WM_MOVE, sent|defwinproc },
723     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
724     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
725     { 0 }
726 };
727 /* CreateWindow (for a child popup window, not initially visible) */
728 static const struct message WmCreateChildPopupSeq[] = {
729     { HCBT_CREATEWND, hook },
730     { WM_NCCREATE, sent }, 
731     { WM_NCCALCSIZE, sent|wparam, 0 },
732     { WM_CREATE, sent },
733     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
734     { WM_SIZE, sent|wparam, SIZE_RESTORED },
735     { WM_MOVE, sent },
736     { 0 }
737 };
738 /* CreateWindow (for a popup window, not initially visible,
739  * which sets WS_VISIBLE in WM_CREATE handler)
740  */
741 static const struct message WmCreateInvisiblePopupSeq[] = {
742     { HCBT_CREATEWND, hook },
743     { WM_NCCREATE, sent }, 
744     { WM_NCCALCSIZE, sent|wparam, 0 },
745     { WM_CREATE, sent },
746     { WM_STYLECHANGING, sent },
747     { WM_STYLECHANGED, sent },
748     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
749     { WM_SIZE, sent|wparam, SIZE_RESTORED },
750     { WM_MOVE, sent },
751     { 0 }
752 };
753 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
754  * for a popup window with WS_VISIBLE style set
755  */
756 static const struct message WmShowVisiblePopupSeq_2[] = {
757     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
758     { 0 }
759 };
760 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
761  * for a popup window with WS_VISIBLE style set
762  */
763 static const struct message WmShowVisiblePopupSeq_3[] = {
764     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
765     { HCBT_ACTIVATE, hook },
766     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
767     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
768     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
769     { WM_NCACTIVATE, sent|wparam, 1 },
770     { WM_ACTIVATE, sent|wparam, 1 },
771     { HCBT_SETFOCUS, hook },
772     { WM_KILLFOCUS, sent|parent },
773     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
774     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
775     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
776     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
777     { WM_SETFOCUS, sent|defwinproc },
778     { 0 }
779 };
780 /* CreateWindow (for child window, not initially visible) */
781 static const struct message WmCreateChildSeq[] = {
782     { HCBT_CREATEWND, hook },
783     { WM_NCCREATE, sent }, 
784     /* child is inserted into parent's child list after WM_NCCREATE returns */
785     { WM_NCCALCSIZE, sent|wparam, 0 },
786     { WM_CREATE, sent },
787     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
788     { WM_SIZE, sent|wparam, SIZE_RESTORED },
789     { WM_MOVE, sent },
790     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
791     { 0 }
792 };
793 /* CreateWindow (for maximized child window, not initially visible) */
794 static const struct message WmCreateMaximizedChildSeq[] = {
795     { HCBT_CREATEWND, hook },
796     { WM_NCCREATE, sent }, 
797     { WM_NCCALCSIZE, sent|wparam, 0 },
798     { WM_CREATE, sent },
799     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
800     { WM_SIZE, sent|wparam, SIZE_RESTORED },
801     { WM_MOVE, sent },
802     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
803     { WM_GETMINMAXINFO, sent },
804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
805     { WM_NCCALCSIZE, sent|wparam, 1 },
806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
807     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
808     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
809     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
810     { 0 }
811 };
812 /* CreateWindow (for a child window, initially visible) */
813 static const struct message WmCreateVisibleChildSeq[] = {
814     { HCBT_CREATEWND, hook },
815     { WM_NCCREATE, sent }, 
816     /* child is inserted into parent's child list after WM_NCCREATE returns */
817     { WM_NCCALCSIZE, sent|wparam, 0 },
818     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
819     { WM_CREATE, sent },
820     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
821     { WM_SIZE, sent|wparam, SIZE_RESTORED },
822     { WM_MOVE, sent },
823     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
824     { WM_SHOWWINDOW, sent|wparam, 1 },
825     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
826     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
827     { WM_ERASEBKGND, sent|parent|optional },
828     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
829     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
830     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
831     { 0 }
832 };
833 /* ShowWindow(SW_SHOW) for a not visible child window */
834 static const struct message WmShowChildSeq[] = {
835     { WM_SHOWWINDOW, sent|wparam, 1 },
836     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
837     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
838     { WM_ERASEBKGND, sent|parent|optional },
839     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
840     { 0 }
841 };
842 /* ShowWindow(SW_HIDE) for a visible child window */
843 static const struct message WmHideChildSeq[] = {
844     { WM_SHOWWINDOW, sent|wparam, 0 },
845     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
846     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
847     { WM_ERASEBKGND, sent|parent|optional },
848     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
849     { 0 }
850 };
851 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
852 static const struct message WmHideChildSeq2[] = {
853     { WM_SHOWWINDOW, sent|wparam, 0 },
854     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
855     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
856     { WM_ERASEBKGND, sent|parent },
857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
858     { 0 }
859 };
860 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
861  * for a not visible child window
862  */
863 static const struct message WmShowChildSeq_2[] = {
864     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
865     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
866     { WM_CHILDACTIVATE, sent },
867     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
868     { 0 }
869 };
870 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
871  * for a not visible child window
872  */
873 static const struct message WmShowChildSeq_3[] = {
874     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
875     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
876     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
877     { 0 }
878 };
879 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
880  * for a visible child window with a caption
881  */
882 static const struct message WmShowChildSeq_4[] = {
883     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
884     { WM_CHILDACTIVATE, sent },
885     { 0 }
886 };
887 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
888 static const struct message WmShowChildInvisibleParentSeq_1[] = {
889     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
890     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
891     { WM_NCCALCSIZE, sent|wparam, 1 },
892     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
893     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
894     { WM_MOVE, sent|defwinproc },
895     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
896     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
897     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
898     /* FIXME: Wine creates an icon/title window while Windows doesn't */
899     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
900     { WM_GETTEXT, sent|optional },
901     { 0 }
902 };
903 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
904 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
905     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
906     { 0 }
907 };
908 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
909 static const struct message WmShowChildInvisibleParentSeq_2[] = {
910     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
911     { WM_GETMINMAXINFO, sent },
912     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
913     { WM_NCCALCSIZE, sent|wparam, 1 },
914     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
915     { WM_CHILDACTIVATE, sent },
916     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
917     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
918     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
919     { 0 }
920 };
921 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
922 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
923     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
924     { 0 }
925 };
926 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
927 static const struct message WmShowChildInvisibleParentSeq_3[] = {
928     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
930     { WM_NCCALCSIZE, sent|wparam, 1 },
931     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
932     { WM_CHILDACTIVATE, sent },
933     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
934     { WM_MOVE, sent|defwinproc },
935     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
936     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
937     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
938     /* FIXME: Wine creates an icon/title window while Windows doesn't */
939     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
940     { WM_GETTEXT, sent|optional },
941     { 0 }
942 };
943 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
944 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
945     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
946     { 0 }
947 };
948 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
949 static const struct message WmShowChildInvisibleParentSeq_4[] = {
950     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
952     { WM_NCCALCSIZE, sent|wparam, 1 },
953     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
954     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
955     { WM_MOVE, sent|defwinproc },
956     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
957     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
958     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
959     /* FIXME: Wine creates an icon/title window while Windows doesn't */
960     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
961     { WM_GETTEXT, sent|optional },
962     { 0 }
963 };
964 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
965 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
966     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
967     { 0 }
968 };
969 /* ShowWindow(SW_SHOW) for child with invisible parent */
970 static const struct message WmShowChildInvisibleParentSeq_5[] = {
971     { WM_SHOWWINDOW, sent|wparam, 1 },
972     { 0 }
973 };
974 /* ShowWindow(SW_HIDE) for child with invisible parent */
975 static const struct message WmHideChildInvisibleParentSeq[] = {
976     { WM_SHOWWINDOW, sent|wparam, 0 },
977     { 0 }
978 };
979 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
980 static const struct message WmShowChildInvisibleParentSeq_6[] = {
981     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
982     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
983     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
984     { 0 }
985 };
986 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
987 static const struct message WmHideChildInvisibleParentSeq_2[] = {
988     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
989     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
990     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
991     { 0 }
992 };
993 /* DestroyWindow for a visible child window */
994 static const struct message WmDestroyChildSeq[] = {
995     { HCBT_DESTROYWND, hook },
996     { 0x0090, sent|optional },
997     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
998     { WM_SHOWWINDOW, sent|wparam, 0 },
999     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1000     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1001     { WM_ERASEBKGND, sent|parent|optional },
1002     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1003     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1004     { WM_KILLFOCUS, sent },
1005     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1006     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1007     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1008     { WM_SETFOCUS, sent|parent },
1009     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1010     { WM_DESTROY, sent },
1011     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1012     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1013     { WM_NCDESTROY, sent },
1014     { 0 }
1015 };
1016 /* DestroyWindow for a visible child window with invisible parent */
1017 static const struct message WmDestroyInvisibleChildSeq[] = {
1018     { HCBT_DESTROYWND, hook },
1019     { 0x0090, sent|optional },
1020     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1021     { WM_SHOWWINDOW, sent|wparam, 0 },
1022     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1023     { WM_DESTROY, sent },
1024     { WM_NCDESTROY, sent },
1025     { 0 }
1026 };
1027 /* Moving the mouse in nonclient area */
1028 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1029     { WM_NCHITTEST, sent },
1030     { WM_SETCURSOR, sent },
1031     { WM_NCMOUSEMOVE, posted },
1032     { 0 }
1033 };
1034 /* Moving the mouse in client area */
1035 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1036     { WM_NCHITTEST, sent },
1037     { WM_SETCURSOR, sent },
1038     { WM_MOUSEMOVE, posted },
1039     { 0 }
1040 };
1041 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1042 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1043     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1044     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1045     { WM_GETMINMAXINFO, sent|defwinproc },
1046     { WM_ENTERSIZEMOVE, sent|defwinproc },
1047     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1048     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1049     { WM_MOVE, sent|defwinproc },
1050     { WM_EXITSIZEMOVE, sent|defwinproc },
1051     { 0 }
1052 };
1053 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1054 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1055     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1056     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1057     { WM_GETMINMAXINFO, sent|defwinproc },
1058     { WM_ENTERSIZEMOVE, sent|defwinproc },
1059     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1060     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1061     { WM_GETMINMAXINFO, sent|defwinproc },
1062     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1063     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1064     { WM_GETTEXT, sent|defwinproc },
1065     { WM_ERASEBKGND, sent|defwinproc },
1066     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1067     { WM_MOVE, sent|defwinproc },
1068     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1069     { WM_EXITSIZEMOVE, sent|defwinproc },
1070     { 0 }
1071 };
1072 /* Resizing child window with MoveWindow (32) */
1073 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1074     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1075     { WM_NCCALCSIZE, sent|wparam, 1 },
1076     { WM_ERASEBKGND, sent|parent|optional },
1077     { WM_ERASEBKGND, sent|optional },
1078     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1079     { WM_MOVE, sent|defwinproc },
1080     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1081     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1082     { 0 }
1083 };
1084 /* Clicking on inactive button */
1085 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1086     { WM_NCHITTEST, sent },
1087     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1088     { WM_MOUSEACTIVATE, sent },
1089     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1090     { WM_SETCURSOR, sent },
1091     { WM_SETCURSOR, sent|parent|defwinproc },
1092     { WM_LBUTTONDOWN, posted },
1093     { WM_KILLFOCUS, posted|parent },
1094     { WM_SETFOCUS, posted },
1095     { WM_CTLCOLORBTN, posted|parent },
1096     { BM_SETSTATE, posted },
1097     { WM_CTLCOLORBTN, posted|parent },
1098     { WM_LBUTTONUP, posted },
1099     { BM_SETSTATE, posted },
1100     { WM_CTLCOLORBTN, posted|parent },
1101     { WM_COMMAND, posted|parent },
1102     { 0 }
1103 };
1104 /* Reparenting a button (16/32) */
1105 /* The last child (button) reparented gets topmost for its new parent. */
1106 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1107     { WM_SHOWWINDOW, sent|wparam, 0 },
1108     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1109     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1110     { WM_ERASEBKGND, sent|parent },
1111     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1113     { WM_CHILDACTIVATE, sent },
1114     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1115     { WM_MOVE, sent|defwinproc },
1116     { WM_SHOWWINDOW, sent|wparam, 1 },
1117     { 0 }
1118 };
1119 /* Creation of a custom dialog (32) */
1120 static const struct message WmCreateCustomDialogSeq[] = {
1121     { HCBT_CREATEWND, hook },
1122     { WM_GETMINMAXINFO, sent },
1123     { WM_NCCREATE, sent },
1124     { WM_NCCALCSIZE, sent|wparam, 0 },
1125     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1126     { WM_CREATE, sent },
1127     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1128     { WM_SHOWWINDOW, sent|wparam, 1 },
1129     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1130     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1131     { HCBT_ACTIVATE, hook },
1132     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1133
1134
1135     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1136
1137     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1138
1139     { WM_NCACTIVATE, sent|wparam, 1 },
1140     { WM_GETTEXT, sent|optional|defwinproc },
1141     { WM_GETTEXT, sent|optional|defwinproc },
1142     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1143     { WM_ACTIVATE, sent|wparam, 1 },
1144     { WM_KILLFOCUS, sent|parent },
1145     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1146     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1147     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1148     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1149     { WM_SETFOCUS, sent },
1150     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1151     { WM_NCPAINT, sent|wparam, 1 },
1152     { WM_GETTEXT, sent|optional|defwinproc },
1153     { WM_GETTEXT, sent|optional|defwinproc },
1154     { WM_ERASEBKGND, sent },
1155     { WM_CTLCOLORDLG, sent|defwinproc },
1156     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1157     { WM_GETTEXT, sent|optional },
1158     { WM_GETTEXT, sent|optional },
1159     { WM_NCCALCSIZE, sent|optional },
1160     { WM_NCPAINT, sent|optional },
1161     { WM_GETTEXT, sent|optional|defwinproc },
1162     { WM_GETTEXT, sent|optional|defwinproc },
1163     { WM_ERASEBKGND, sent|optional },
1164     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1165     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1166     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1167     { WM_MOVE, sent },
1168     { 0 }
1169 };
1170 /* Calling EndDialog for a custom dialog (32) */
1171 static const struct message WmEndCustomDialogSeq[] = {
1172     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1173     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1174     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1175     { WM_GETTEXT, sent|optional },
1176     { HCBT_ACTIVATE, hook },
1177     { WM_NCACTIVATE, sent|wparam, 0 },
1178     { WM_GETTEXT, sent|optional|defwinproc },
1179     { WM_GETTEXT, sent|optional|defwinproc },
1180     { WM_ACTIVATE, sent|wparam, 0 },
1181     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1182     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1183     { HCBT_SETFOCUS, hook },
1184     { WM_KILLFOCUS, sent },
1185     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1186     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1187     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1188     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1189     { WM_SETFOCUS, sent|parent|defwinproc },
1190     { 0 }
1191 };
1192 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1193 static const struct message WmShowCustomDialogSeq[] = {
1194     { WM_SHOWWINDOW, sent|wparam, 1 },
1195     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1196     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1197     { HCBT_ACTIVATE, hook },
1198     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1199
1200     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1201
1202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1203     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1204     { WM_NCACTIVATE, sent|wparam, 1 },
1205     { WM_ACTIVATE, sent|wparam, 1 },
1206
1207     { WM_KILLFOCUS, sent|parent },
1208     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1209     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1210     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1211     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1212     { WM_SETFOCUS, sent },
1213     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1214     { WM_NCPAINT, sent|wparam, 1 },
1215     { WM_ERASEBKGND, sent },
1216     { WM_CTLCOLORDLG, sent|defwinproc },
1217     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1218     { 0 }
1219 };
1220 /* Creation and destruction of a modal dialog (32) */
1221 static const struct message WmModalDialogSeq[] = {
1222     { WM_CANCELMODE, sent|parent },
1223     { HCBT_SETFOCUS, hook },
1224     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1225     { WM_KILLFOCUS, sent|parent },
1226     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1227     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1228     { WM_ENABLE, sent|parent|wparam, 0 },
1229     { HCBT_CREATEWND, hook },
1230     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1231     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1232     { WM_SETFONT, sent },
1233     { WM_INITDIALOG, sent },
1234     { WM_CHANGEUISTATE, sent|optional },
1235     { WM_UPDATEUISTATE, sent|optional },
1236     { WM_SHOWWINDOW, sent },
1237     { HCBT_ACTIVATE, hook },
1238     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1239     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1240     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1241     { WM_NCACTIVATE, sent|wparam, 1 },
1242     { WM_GETTEXT, sent|optional },
1243     { WM_ACTIVATE, sent|wparam, 1 },
1244     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1245     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1246     { WM_NCPAINT, sent },
1247     { WM_GETTEXT, sent|optional },
1248     { WM_ERASEBKGND, sent },
1249     { WM_CTLCOLORDLG, sent },
1250     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1251     { WM_GETTEXT, sent|optional },
1252     { WM_NCCALCSIZE, sent|optional },
1253     { WM_NCPAINT, sent|optional },
1254     { WM_GETTEXT, sent|optional },
1255     { WM_ERASEBKGND, sent|optional },
1256     { WM_CTLCOLORDLG, sent|optional },
1257     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1258     { WM_PAINT, sent|optional },
1259     { WM_CTLCOLORBTN, sent },
1260     { WM_ENTERIDLE, sent|parent|optional },
1261     { WM_ENTERIDLE, sent|parent|optional },
1262     { WM_ENTERIDLE, sent|parent|optional },
1263     { WM_ENTERIDLE, sent|parent|optional },
1264     { WM_ENTERIDLE, sent|parent|optional },
1265     { WM_ENTERIDLE, sent|parent|optional },
1266     { WM_ENTERIDLE, sent|parent|optional },
1267     { WM_ENTERIDLE, sent|parent|optional },
1268     { WM_ENTERIDLE, sent|parent|optional },
1269     { WM_ENTERIDLE, sent|parent|optional },
1270     { WM_ENTERIDLE, sent|parent|optional },
1271     { WM_ENTERIDLE, sent|parent|optional },
1272     { WM_ENTERIDLE, sent|parent|optional },
1273     { WM_ENTERIDLE, sent|parent|optional },
1274     { WM_ENTERIDLE, sent|parent|optional },
1275     { WM_ENTERIDLE, sent|parent|optional },
1276     { WM_ENTERIDLE, sent|parent|optional },
1277     { WM_ENTERIDLE, sent|parent|optional },
1278     { WM_ENTERIDLE, sent|parent|optional },
1279     { WM_ENTERIDLE, sent|parent|optional },
1280     { WM_TIMER, sent },
1281     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1282     { WM_ENABLE, sent|parent|wparam, 1 },
1283     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1284     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1285     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1286     { WM_GETTEXT, sent|optional },
1287     { HCBT_ACTIVATE, hook },
1288     { WM_NCACTIVATE, sent|wparam, 0 },
1289     { WM_GETTEXT, sent|optional },
1290     { WM_ACTIVATE, sent|wparam, 0 },
1291     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1292     { WM_WINDOWPOSCHANGING, sent|optional },
1293     { HCBT_SETFOCUS, hook },
1294     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1295     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1296     { WM_SETFOCUS, sent|parent|defwinproc },
1297     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1298     { HCBT_DESTROYWND, hook },
1299     { 0x0090, sent|optional },
1300     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1301     { WM_DESTROY, sent },
1302     { WM_NCDESTROY, sent },
1303     { 0 }
1304 };
1305 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1306 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1307     /* (inside dialog proc, handling WM_INITDIALOG) */
1308     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1309     { WM_NCCALCSIZE, sent },
1310     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1311     { WM_GETTEXT, sent|defwinproc },
1312     { WM_ACTIVATE, sent|parent|wparam, 0 },
1313     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1314     { WM_WINDOWPOSCHANGING, sent|parent },
1315     { WM_NCACTIVATE, sent|wparam, 1 },
1316     { WM_ACTIVATE, sent|wparam, 1 },
1317     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1318     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1319     /* (setting focus) */
1320     { WM_SHOWWINDOW, sent|wparam, 1 },
1321     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1322     { WM_NCPAINT, sent },
1323     { WM_GETTEXT, sent|defwinproc },
1324     { WM_ERASEBKGND, sent },
1325     { WM_CTLCOLORDLG, sent|defwinproc },
1326     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1327     { WM_PAINT, sent },
1328     /* (bunch of WM_CTLCOLOR* for each control) */
1329     { WM_PAINT, sent|parent },
1330     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1331     { WM_SETCURSOR, sent|parent },
1332     { 0 }
1333 };
1334 /* SetMenu for NonVisible windows with size change*/
1335 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1336     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1337     { WM_NCCALCSIZE, sent|wparam, 1 },
1338     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1339     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1340     { WM_MOVE, sent|defwinproc },
1341     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1342     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1343     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1344     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1345     { WM_GETTEXT, sent|optional },
1346     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1347     { 0 }
1348 };
1349 /* SetMenu for NonVisible windows with no size change */
1350 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1351     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1352     { WM_NCCALCSIZE, sent|wparam, 1 },
1353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1354     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1355     { 0 }
1356 };
1357 /* SetMenu for Visible windows with size change */
1358 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1359     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1360     { WM_NCCALCSIZE, sent|wparam, 1 },
1361     { 0x0093, sent|defwinproc|optional },
1362     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1363     { WM_NCPAINT, sent }, /* wparam != 1 */
1364     { 0x0093, sent|defwinproc|optional },
1365     { 0x0093, sent|defwinproc|optional },
1366     { 0x0091, sent|defwinproc|optional },
1367     { 0x0092, sent|defwinproc|optional },
1368     { WM_GETTEXT, sent|defwinproc|optional },
1369     { WM_ERASEBKGND, sent|optional },
1370     { WM_ACTIVATE, sent|optional },
1371     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1372     { WM_MOVE, sent|defwinproc },
1373     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1374     { 0x0093, sent|optional },
1375     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1376     { 0x0093, sent|defwinproc|optional },
1377     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1378     { 0x0093, sent|defwinproc|optional },
1379     { 0x0093, sent|defwinproc|optional },
1380     { 0x0091, sent|defwinproc|optional },
1381     { 0x0092, sent|defwinproc|optional },
1382     { WM_ERASEBKGND, sent|optional },
1383     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1384     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1385     { 0 }
1386 };
1387 /* SetMenu for Visible windows with no size change */
1388 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1389     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1390     { WM_NCCALCSIZE, sent|wparam, 1 },
1391     { WM_NCPAINT, sent }, /* wparam != 1 */
1392     { WM_GETTEXT, sent|defwinproc|optional },
1393     { WM_ERASEBKGND, sent|optional },
1394     { WM_ACTIVATE, sent|optional },
1395     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1396     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1397     { 0 }
1398 };
1399 /* DrawMenuBar for a visible window */
1400 static const struct message WmDrawMenuBarSeq[] =
1401 {
1402     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1403     { WM_NCCALCSIZE, sent|wparam, 1 },
1404     { 0x0093, sent|defwinproc|optional },
1405     { WM_NCPAINT, sent }, /* wparam != 1 */
1406     { 0x0093, sent|defwinproc|optional },
1407     { 0x0093, sent|defwinproc|optional },
1408     { 0x0091, sent|defwinproc|optional },
1409     { 0x0092, sent|defwinproc|optional },
1410     { WM_GETTEXT, sent|defwinproc|optional },
1411     { WM_ERASEBKGND, sent|optional },
1412     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1413     { 0x0093, sent|optional },
1414     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1415     { 0 }
1416 };
1417
1418 static const struct message WmSetRedrawFalseSeq[] =
1419 {
1420     { WM_SETREDRAW, sent|wparam, 0 },
1421     { 0 }
1422 };
1423
1424 static const struct message WmSetRedrawTrueSeq[] =
1425 {
1426     { WM_SETREDRAW, sent|wparam, 1 },
1427     { 0 }
1428 };
1429
1430 static const struct message WmEnableWindowSeq_1[] =
1431 {
1432     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1433     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1434     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1435     { 0 }
1436 };
1437
1438 static const struct message WmEnableWindowSeq_2[] =
1439 {
1440     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1441     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1442     { 0 }
1443 };
1444
1445 static const struct message WmGetScrollRangeSeq[] =
1446 {
1447     { SBM_GETRANGE, sent },
1448     { 0 }
1449 };
1450 static const struct message WmGetScrollInfoSeq[] =
1451 {
1452     { SBM_GETSCROLLINFO, sent },
1453     { 0 }
1454 };
1455 static const struct message WmSetScrollRangeSeq[] =
1456 {
1457     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1458        sends SBM_SETSCROLLINFO.
1459      */
1460     { SBM_SETSCROLLINFO, sent },
1461     { 0 }
1462 };
1463 /* SetScrollRange for a window without a non-client area */
1464 static const struct message WmSetScrollRangeHSeq_empty[] =
1465 {
1466     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1467     { 0 }
1468 };
1469 static const struct message WmSetScrollRangeVSeq_empty[] =
1470 {
1471     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1472     { 0 }
1473 };
1474 static const struct message WmSetScrollRangeHVSeq[] =
1475 {
1476     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1477     { WM_NCCALCSIZE, sent|wparam, 1 },
1478     { WM_GETTEXT, sent|defwinproc|optional },
1479     { WM_ERASEBKGND, sent|optional },
1480     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1481     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1482     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1483     { 0 }
1484 };
1485 /* SetScrollRange for a window with a non-client area */
1486 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1487 {
1488     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1489     { WM_NCCALCSIZE, sent|wparam, 1 },
1490     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1491     { WM_NCPAINT, sent|optional },
1492     { WM_STYLECHANGING, sent|defwinproc|optional },
1493     { WM_STYLECHANGED, sent|defwinproc|optional },
1494     { WM_STYLECHANGING, sent|defwinproc|optional },
1495     { WM_STYLECHANGED, sent|defwinproc|optional },
1496     { WM_STYLECHANGING, sent|defwinproc|optional },
1497     { WM_STYLECHANGED, sent|defwinproc|optional },
1498     { WM_STYLECHANGING, sent|defwinproc|optional },
1499     { WM_STYLECHANGED, sent|defwinproc|optional },
1500     { WM_GETTEXT, sent|defwinproc|optional },
1501     { WM_GETTEXT, sent|defwinproc|optional },
1502     { WM_ERASEBKGND, sent|optional },
1503     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1504     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1505     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1506     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1507     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1508     { WM_GETTEXT, sent|optional },
1509     { WM_GETTEXT, sent|optional },
1510     { WM_GETTEXT, sent|optional },
1511     { WM_GETTEXT, sent|optional },
1512     { 0 }
1513 };
1514 /* test if we receive the right sequence of messages */
1515 /* after calling ShowWindow( SW_SHOWNA) */
1516 static const struct message WmSHOWNAChildInvisParInvis[] = {
1517     { WM_SHOWWINDOW, sent|wparam, 1 },
1518     { 0 }
1519 };
1520 static const struct message WmSHOWNAChildVisParInvis[] = {
1521     { WM_SHOWWINDOW, sent|wparam, 1 },
1522     { 0 }
1523 };
1524 static const struct message WmSHOWNAChildVisParVis[] = {
1525     { WM_SHOWWINDOW, sent|wparam, 1 },
1526     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1527     { 0 }
1528 };
1529 static const struct message WmSHOWNAChildInvisParVis[] = {
1530     { WM_SHOWWINDOW, sent|wparam, 1 },
1531     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1532     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1533     { WM_ERASEBKGND, sent|optional },
1534     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1535     { 0 }
1536 };
1537 static const struct message WmSHOWNATopVisible[] = {
1538     { WM_SHOWWINDOW, sent|wparam, 1 },
1539     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1540     { 0 }
1541 };
1542 static const struct message WmSHOWNATopInvisible[] = {
1543     { WM_SHOWWINDOW, sent|wparam, 1 },
1544     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1545     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1546     { WM_NCPAINT, sent|wparam, 1 },
1547     { WM_GETTEXT, sent|defwinproc|optional },
1548     { WM_ERASEBKGND, sent|optional },
1549     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1550     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1551     { WM_NCPAINT, sent|wparam|optional, 1 },
1552     { WM_ERASEBKGND, sent|optional },
1553     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1554     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1555     { WM_MOVE, sent },
1556     { 0 }
1557 };
1558
1559 static int after_end_dialog, test_def_id;
1560 static int sequence_cnt, sequence_size;
1561 static struct message* sequence;
1562 static int log_all_parent_messages;
1563
1564 /* user32 functions */
1565 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1566 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1567 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1568 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1569 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1570 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1571 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1572 /* kernel32 functions */
1573 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1574
1575 static void init_procs(void)
1576 {
1577     HMODULE user32 = GetModuleHandleA("user32.dll");
1578     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1579
1580 #define GET_PROC(dll, func) \
1581     p ## func = (void*)GetProcAddress(dll, #func); \
1582     if(!p ## func) { \
1583       trace("GetProcAddress(%s) failed\n", #func); \
1584     }
1585
1586     GET_PROC(user32, GetAncestor)
1587     GET_PROC(user32, GetMenuInfo)
1588     GET_PROC(user32, NotifyWinEvent)
1589     GET_PROC(user32, SetMenuInfo)
1590     GET_PROC(user32, SetWinEventHook)
1591     GET_PROC(user32, TrackMouseEvent)
1592     GET_PROC(user32, UnhookWinEvent)
1593
1594     GET_PROC(kernel32, GetCPInfoExA)
1595
1596 #undef GET_PROC
1597 }
1598
1599 static void add_message(const struct message *msg)
1600 {
1601     if (!sequence) 
1602     {
1603         sequence_size = 10;
1604         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1605     }
1606     if (sequence_cnt == sequence_size) 
1607     {
1608         sequence_size *= 2;
1609         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1610     }
1611     assert(sequence);
1612
1613     sequence[sequence_cnt].message = msg->message;
1614     sequence[sequence_cnt].flags = msg->flags;
1615     sequence[sequence_cnt].wParam = msg->wParam;
1616     sequence[sequence_cnt].lParam = msg->lParam;
1617
1618     sequence_cnt++;
1619 }
1620
1621 /* try to make sure pending X events have been processed before continuing */
1622 static void flush_events(void)
1623 {
1624     MSG msg;
1625     int diff = 200;
1626     int min_timeout = 50;
1627     DWORD time = GetTickCount() + diff;
1628
1629     while (diff > 0)
1630     {
1631         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1632         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1633         diff = time - GetTickCount();
1634         min_timeout = 10;
1635     }
1636 }
1637
1638 static void flush_sequence(void)
1639 {
1640     HeapFree(GetProcessHeap(), 0, sequence);
1641     sequence = 0;
1642     sequence_cnt = sequence_size = 0;
1643 }
1644
1645 #define ok_sequence( exp, contx, todo) \
1646         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1647
1648
1649 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1650         const char *file, int line)
1651 {
1652     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1653     const struct message *actual;
1654     int failcount = 0;
1655     
1656     add_message(&end_of_sequence);
1657
1658     actual = sequence;
1659
1660     while (expected->message && actual->message)
1661     {
1662         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1663
1664         if (expected->message == actual->message)
1665         {
1666             if (expected->flags & wparam)
1667             {
1668                 if (expected->wParam != actual->wParam && todo)
1669                 {
1670                     todo_wine {
1671                         failcount ++;
1672                         ok_( file, line) (FALSE,
1673                             "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1674                             context, expected->message, expected->wParam, actual->wParam);
1675                     }
1676                 }
1677                 else
1678                 ok_( file, line) (expected->wParam == actual->wParam,
1679                      "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1680                      context, expected->message, expected->wParam, actual->wParam);
1681             }
1682             if (expected->flags & lparam)
1683             {
1684                 if (expected->lParam != actual->lParam && todo)
1685                 {
1686                     todo_wine {
1687                         failcount ++;
1688                         ok_( file, line) (FALSE,
1689                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1690                             context, expected->message, expected->lParam, actual->lParam);
1691                     }
1692                 }
1693                 else
1694                  ok_( file, line) (expected->lParam == actual->lParam,
1695                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1696                      context, expected->message, expected->lParam, actual->lParam);
1697             }
1698             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1699             {
1700                     todo_wine {
1701                         failcount ++;
1702                         ok_( file, line) (FALSE,
1703                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1704                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1705                     }
1706             }
1707             else
1708                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1709                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1710                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1711             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1712                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1713                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1714             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1715                 "%s: the msg 0x%04x should have been %s\n",
1716                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1717             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1718                 "%s: the msg 0x%04x was expected in %s\n",
1719                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1720             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1721                 "%s: the msg 0x%04x should have been sent by a hook\n",
1722                 context, expected->message);
1723             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1724                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1725                 context, expected->message);
1726             expected++;
1727             actual++;
1728         }
1729         /* silently drop winevent messages if there is no support for them */
1730         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1731             expected++;
1732         else if (todo)
1733         {
1734             failcount++;
1735             todo_wine {
1736                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1737                     context, expected->message, actual->message);
1738             }
1739             flush_sequence();
1740             return;
1741         }
1742         else
1743         {
1744             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1745                 context, expected->message, actual->message);
1746             expected++;
1747             actual++;
1748         }
1749     }
1750
1751     /* skip all optional trailing messages */
1752     while (expected->message && ((expected->flags & optional) ||
1753             ((expected->flags & winevent_hook) && !hEvent_hook)))
1754         expected++;
1755
1756     if (todo)
1757     {
1758         todo_wine {
1759             if (expected->message || actual->message) {
1760                 failcount++;
1761                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1762                     context, expected->message, actual->message);
1763             }
1764         }
1765     }
1766     else
1767     {
1768         if (expected->message || actual->message)
1769             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1770                 context, expected->message, actual->message);
1771     }
1772     if( todo && !failcount) /* succeeded yet marked todo */
1773         todo_wine {
1774             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1775         }
1776
1777     flush_sequence();
1778 }
1779
1780 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
1781
1782 /******************************** MDI test **********************************/
1783
1784 /* CreateWindow for MDI frame window, initially visible */
1785 static const struct message WmCreateMDIframeSeq[] = {
1786     { HCBT_CREATEWND, hook },
1787     { WM_GETMINMAXINFO, sent },
1788     { WM_NCCREATE, sent },
1789     { WM_NCCALCSIZE, sent|wparam, 0 },
1790     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1791     { WM_CREATE, sent },
1792     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1793     { WM_SHOWWINDOW, sent|wparam, 1 },
1794     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1795     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1796     { HCBT_ACTIVATE, hook },
1797     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1798     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1799     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1800     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1801     { WM_NCACTIVATE, sent|wparam, 1 },
1802     { WM_GETTEXT, sent|defwinproc|optional },
1803     { WM_ACTIVATE, sent|wparam, 1 },
1804     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1805     { HCBT_SETFOCUS, hook },
1806     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1807     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1808     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1809     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1810     /* Win9x adds SWP_NOZORDER below */
1811     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1812     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1813     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1814     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1815     { WM_MOVE, sent },
1816     { 0 }
1817 };
1818 /* DestroyWindow for MDI frame window, initially visible */
1819 static const struct message WmDestroyMDIframeSeq[] = {
1820     { HCBT_DESTROYWND, hook },
1821     { 0x0090, sent|optional },
1822     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1823     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1824     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1825     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1826     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1827     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1828     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1829     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1830     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1831     { WM_DESTROY, sent },
1832     { WM_NCDESTROY, sent },
1833     { 0 }
1834 };
1835 /* CreateWindow for MDI client window, initially visible */
1836 static const struct message WmCreateMDIclientSeq[] = {
1837     { HCBT_CREATEWND, hook },
1838     { WM_NCCREATE, sent },
1839     { WM_NCCALCSIZE, sent|wparam, 0 },
1840     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1841     { WM_CREATE, sent },
1842     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1843     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1844     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1845     { WM_MOVE, sent },
1846     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1847     { WM_SHOWWINDOW, sent|wparam, 1 },
1848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1849     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1850     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1851     { 0 }
1852 };
1853 /* ShowWindow(SW_SHOW) for MDI client window */
1854 static const struct message WmShowMDIclientSeq[] = {
1855     { WM_SHOWWINDOW, sent|wparam, 1 },
1856     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1857     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1858     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1859     { 0 }
1860 };
1861 /* ShowWindow(SW_HIDE) for MDI client window */
1862 static const struct message WmHideMDIclientSeq[] = {
1863     { WM_SHOWWINDOW, sent|wparam, 0 },
1864     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1865     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1866     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1867     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1868     { 0 }
1869 };
1870 /* DestroyWindow for MDI client window, initially visible */
1871 static const struct message WmDestroyMDIclientSeq[] = {
1872     { HCBT_DESTROYWND, hook },
1873     { 0x0090, sent|optional },
1874     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1875     { WM_SHOWWINDOW, sent|wparam, 0 },
1876     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1877     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1878     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1879     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1880     { WM_DESTROY, sent },
1881     { WM_NCDESTROY, sent },
1882     { 0 }
1883 };
1884 /* CreateWindow for MDI child window, initially visible */
1885 static const struct message WmCreateMDIchildVisibleSeq[] = {
1886     { HCBT_CREATEWND, hook },
1887     { WM_NCCREATE, sent }, 
1888     { WM_NCCALCSIZE, sent|wparam, 0 },
1889     { WM_CREATE, sent },
1890     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1891     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1892     { WM_MOVE, sent },
1893     /* Win2k sends wparam set to
1894      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1895      * while Win9x doesn't bother to set child window id according to
1896      * CLIENTCREATESTRUCT.idFirstChild
1897      */
1898     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1899     { WM_SHOWWINDOW, sent|wparam, 1 },
1900     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1901     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1902     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1903     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1904     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1905     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1906     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1907
1908     /* Win9x: message sequence terminates here. */
1909
1910     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1911     { HCBT_SETFOCUS, hook }, /* in MDI client */
1912     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1913     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1914     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1915     { WM_SETFOCUS, sent }, /* in MDI client */
1916     { HCBT_SETFOCUS, hook },
1917     { WM_KILLFOCUS, sent }, /* in MDI client */
1918     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1919     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1920     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1921     { WM_SETFOCUS, sent|defwinproc },
1922     { WM_MDIACTIVATE, sent|defwinproc },
1923     { 0 }
1924 };
1925 /* CreateWindow for MDI child window with invisible parent */
1926 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1927     { HCBT_CREATEWND, hook },
1928     { WM_GETMINMAXINFO, sent },
1929     { WM_NCCREATE, sent }, 
1930     { WM_NCCALCSIZE, sent|wparam, 0 },
1931     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1932     { WM_CREATE, sent },
1933     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1934     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1935     { WM_MOVE, sent },
1936     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1937     { WM_SHOWWINDOW, sent|wparam, 1 },
1938     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1940     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1941     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1942
1943     /* Win9x: message sequence terminates here. */
1944
1945     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1946     { HCBT_SETFOCUS, hook }, /* in MDI client */
1947     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1948     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1949     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1950     { WM_SETFOCUS, sent }, /* in MDI client */
1951     { HCBT_SETFOCUS, hook },
1952     { WM_KILLFOCUS, sent }, /* in MDI client */
1953     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1954     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1955     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1956     { WM_SETFOCUS, sent|defwinproc },
1957     { WM_MDIACTIVATE, sent|defwinproc },
1958     { 0 }
1959 };
1960 /* DestroyWindow for MDI child window, initially visible */
1961 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1962     { HCBT_DESTROYWND, hook },
1963     /* Win2k sends wparam set to
1964      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1965      * while Win9x doesn't bother to set child window id according to
1966      * CLIENTCREATESTRUCT.idFirstChild
1967      */
1968     { 0x0090, sent|optional },
1969     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1970     { WM_SHOWWINDOW, sent|wparam, 0 },
1971     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1972     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1973     { WM_ERASEBKGND, sent|parent|optional },
1974     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1975
1976     /* { WM_DESTROY, sent }
1977      * Win9x: message sequence terminates here.
1978      */
1979
1980     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1981     { WM_KILLFOCUS, sent },
1982     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1983     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1984     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1985     { WM_SETFOCUS, sent }, /* in MDI client */
1986
1987     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1988     { WM_KILLFOCUS, sent }, /* in MDI client */
1989     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1990     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1991     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1992     { WM_SETFOCUS, sent }, /* in MDI client */
1993
1994     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1995
1996     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1997     { WM_KILLFOCUS, sent },
1998     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1999     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2000     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2001     { WM_SETFOCUS, sent }, /* in MDI client */
2002
2003     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2004     { WM_KILLFOCUS, sent }, /* in MDI client */
2005     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2006     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2007     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2008     { WM_SETFOCUS, sent }, /* in MDI client */
2009
2010     { WM_DESTROY, sent },
2011
2012     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2013     { WM_KILLFOCUS, sent },
2014     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2015     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2016     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2017     { WM_SETFOCUS, sent }, /* in MDI client */
2018
2019     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2020     { WM_KILLFOCUS, sent }, /* in MDI client */
2021     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2022     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2023     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2024     { WM_SETFOCUS, sent }, /* in MDI client */
2025
2026     { WM_NCDESTROY, sent },
2027     { 0 }
2028 };
2029 /* CreateWindow for MDI child window, initially invisible */
2030 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2031     { HCBT_CREATEWND, hook },
2032     { WM_NCCREATE, sent }, 
2033     { WM_NCCALCSIZE, sent|wparam, 0 },
2034     { WM_CREATE, sent },
2035     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2036     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2037     { WM_MOVE, sent },
2038     /* Win2k sends wparam set to
2039      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2040      * while Win9x doesn't bother to set child window id according to
2041      * CLIENTCREATESTRUCT.idFirstChild
2042      */
2043     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2044     { 0 }
2045 };
2046 /* DestroyWindow for MDI child window, initially invisible */
2047 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2048     { HCBT_DESTROYWND, hook },
2049     /* Win2k sends wparam set to
2050      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2051      * while Win9x doesn't bother to set child window id according to
2052      * CLIENTCREATESTRUCT.idFirstChild
2053      */
2054     { 0x0090, sent|optional },
2055     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2056     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2057     { WM_DESTROY, sent },
2058     { WM_NCDESTROY, sent },
2059     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2060     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2061     { 0 }
2062 };
2063 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2064 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2065     { HCBT_CREATEWND, hook },
2066     { WM_NCCREATE, sent }, 
2067     { WM_NCCALCSIZE, sent|wparam, 0 },
2068     { WM_CREATE, sent },
2069     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2070     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2071     { WM_MOVE, sent },
2072     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2073     { WM_GETMINMAXINFO, sent },
2074     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2075     { WM_NCCALCSIZE, sent|wparam, 1 },
2076     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2077     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2078      /* in MDI frame */
2079     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2080     { WM_NCCALCSIZE, sent|wparam, 1 },
2081     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2082     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2083     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2084     /* Win2k sends wparam set to
2085      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2086      * while Win9x doesn't bother to set child window id according to
2087      * CLIENTCREATESTRUCT.idFirstChild
2088      */
2089     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2090     { WM_SHOWWINDOW, sent|wparam, 1 },
2091     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2092     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2093     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2094     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2096     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2097     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2098
2099     /* Win9x: message sequence terminates here. */
2100
2101     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2102     { HCBT_SETFOCUS, hook }, /* in MDI client */
2103     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2104     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2105     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2106     { WM_SETFOCUS, sent }, /* in MDI client */
2107     { HCBT_SETFOCUS, hook },
2108     { WM_KILLFOCUS, sent }, /* in MDI client */
2109     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2110     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2111     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2112     { WM_SETFOCUS, sent|defwinproc },
2113     { WM_MDIACTIVATE, sent|defwinproc },
2114      /* in MDI frame */
2115     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2116     { WM_NCCALCSIZE, sent|wparam, 1 },
2117     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2118     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2119     { 0 }
2120 };
2121 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2122 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2123     /* restore the 1st MDI child */
2124     { WM_SETREDRAW, sent|wparam, 0 },
2125     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2126     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2127     { WM_NCCALCSIZE, sent|wparam, 1 },
2128     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2129     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2130     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2131      /* in MDI frame */
2132     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2133     { WM_NCCALCSIZE, sent|wparam, 1 },
2134     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2135     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2136     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2137     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2138     /* create the 2nd MDI child */
2139     { HCBT_CREATEWND, hook },
2140     { WM_NCCREATE, sent }, 
2141     { WM_NCCALCSIZE, sent|wparam, 0 },
2142     { WM_CREATE, sent },
2143     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2144     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2145     { WM_MOVE, sent },
2146     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2147     { WM_GETMINMAXINFO, sent },
2148     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2149     { WM_NCCALCSIZE, sent|wparam, 1 },
2150     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2151     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2152     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2153      /* in MDI frame */
2154     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2155     { WM_NCCALCSIZE, sent|wparam, 1 },
2156     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2157     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2158     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2159     /* Win2k sends wparam set to
2160      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2161      * while Win9x doesn't bother to set child window id according to
2162      * CLIENTCREATESTRUCT.idFirstChild
2163      */
2164     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2165     { WM_SHOWWINDOW, sent|wparam, 1 },
2166     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2167     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2168     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2169     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2170     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2171     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2172
2173     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2174     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2175
2176     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2177
2178     /* Win9x: message sequence terminates here. */
2179
2180     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2181     { HCBT_SETFOCUS, hook },
2182     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
2183     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2184     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2185     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2186     { WM_SETFOCUS, sent }, /* in MDI client */
2187     { HCBT_SETFOCUS, hook },
2188     { WM_KILLFOCUS, sent }, /* in MDI client */
2189     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2190     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2191     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2192     { WM_SETFOCUS, sent|defwinproc },
2193
2194     { WM_MDIACTIVATE, sent|defwinproc },
2195      /* in MDI frame */
2196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2197     { WM_NCCALCSIZE, sent|wparam, 1 },
2198     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2199     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2200     { 0 }
2201 };
2202 /* WM_MDICREATE MDI child window, initially visible and maximized */
2203 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2204     { WM_MDICREATE, sent },
2205     { HCBT_CREATEWND, hook },
2206     { WM_NCCREATE, sent }, 
2207     { WM_NCCALCSIZE, sent|wparam, 0 },
2208     { WM_CREATE, sent },
2209     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2210     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2211     { WM_MOVE, sent },
2212     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2213     { WM_GETMINMAXINFO, sent },
2214     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2215     { WM_NCCALCSIZE, sent|wparam, 1 },
2216     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2217     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2218
2219      /* in MDI frame */
2220     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2221     { WM_NCCALCSIZE, sent|wparam, 1 },
2222     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2223     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2224     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2225
2226     /* Win2k sends wparam set to
2227      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2228      * while Win9x doesn't bother to set child window id according to
2229      * CLIENTCREATESTRUCT.idFirstChild
2230      */
2231     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2232     { WM_SHOWWINDOW, sent|wparam, 1 },
2233     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2234
2235     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2236
2237     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2238     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2239     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2240
2241     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2242     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2243
2244     /* Win9x: message sequence terminates here. */
2245
2246     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2247     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2248     { HCBT_SETFOCUS, hook }, /* in MDI client */
2249     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2250     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2251     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2252     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2253     { HCBT_SETFOCUS, hook|optional },
2254     { WM_KILLFOCUS, sent }, /* in MDI client */
2255     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2256     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2257     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2258     { WM_SETFOCUS, sent|defwinproc },
2259
2260     { WM_MDIACTIVATE, sent|defwinproc },
2261
2262      /* in MDI child */
2263     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2264     { WM_NCCALCSIZE, sent|wparam, 1 },
2265     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2266     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2267
2268      /* in MDI frame */
2269     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2270     { WM_NCCALCSIZE, sent|wparam, 1 },
2271     { 0x0093, sent|defwinproc|optional },
2272     { 0x0093, sent|defwinproc|optional },
2273     { 0x0093, sent|defwinproc|optional },
2274     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2275     { WM_MOVE, sent|defwinproc },
2276     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2277
2278      /* in MDI client */
2279     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2280     { WM_NCCALCSIZE, sent|wparam, 1 },
2281     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2282     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2283
2284      /* in MDI child */
2285     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2286     { WM_NCCALCSIZE, sent|wparam, 1 },
2287     { 0x0093, sent|optional },
2288     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2289     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2290
2291     { 0x0093, sent|optional },
2292     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2293     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2294     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2295     { 0x0093, sent|defwinproc|optional },
2296     { 0x0093, sent|defwinproc|optional },
2297     { 0x0093, sent|defwinproc|optional },
2298     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2299     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2300
2301     { 0 }
2302 };
2303 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2304 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2305     { HCBT_CREATEWND, hook },
2306     { WM_GETMINMAXINFO, sent },
2307     { WM_NCCREATE, sent }, 
2308     { WM_NCCALCSIZE, sent|wparam, 0 },
2309     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2310     { WM_CREATE, sent },
2311     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2312     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2313     { WM_MOVE, sent },
2314     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2315     { WM_GETMINMAXINFO, sent },
2316     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2317     { WM_GETMINMAXINFO, sent|defwinproc },
2318     { WM_NCCALCSIZE, sent|wparam, 1 },
2319     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2320     { WM_MOVE, sent|defwinproc },
2321     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2322      /* in MDI frame */
2323     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2324     { WM_NCCALCSIZE, sent|wparam, 1 },
2325     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2326     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2327     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2328     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2329     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2330     /* Win2k sends wparam set to
2331      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2332      * while Win9x doesn't bother to set child window id according to
2333      * CLIENTCREATESTRUCT.idFirstChild
2334      */
2335     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2336     { 0 }
2337 };
2338 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2339 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2340     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2341     { HCBT_SYSCOMMAND, hook },
2342     { WM_CLOSE, sent|defwinproc },
2343     { WM_MDIDESTROY, sent }, /* in MDI client */
2344
2345     /* bring the 1st MDI child to top */
2346     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2347     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2348
2349     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2350
2351     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2352     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2353     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2354
2355     /* maximize the 1st MDI child */
2356     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2357     { WM_GETMINMAXINFO, sent|defwinproc },
2358     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2359     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2360     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2361     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2362     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2363
2364     /* restore the 2nd MDI child */
2365     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2366     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2367     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2368     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2369
2370     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2371
2372     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2373     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2374
2375     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2376
2377     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2378      /* in MDI frame */
2379     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2380     { WM_NCCALCSIZE, sent|wparam, 1 },
2381     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2382     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2383     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2384
2385     /* bring the 1st MDI child to top */
2386     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2387     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2388     { HCBT_SETFOCUS, hook },
2389     { WM_KILLFOCUS, sent|defwinproc },
2390     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2391     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2392     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2393     { WM_SETFOCUS, sent }, /* in MDI client */
2394     { HCBT_SETFOCUS, hook },
2395     { WM_KILLFOCUS, sent }, /* in MDI client */
2396     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2397     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2398     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2399     { WM_SETFOCUS, sent|defwinproc },
2400     { WM_MDIACTIVATE, sent|defwinproc },
2401     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2402
2403     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2404     { WM_SHOWWINDOW, sent|wparam, 1 },
2405     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2406     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2407     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2408     { WM_MDIREFRESHMENU, sent },
2409
2410     { HCBT_DESTROYWND, hook },
2411     /* Win2k sends wparam set to
2412      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2413      * while Win9x doesn't bother to set child window id according to
2414      * CLIENTCREATESTRUCT.idFirstChild
2415      */
2416     { 0x0090, sent|defwinproc|optional },
2417     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2418     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2419     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2420     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2421     { WM_ERASEBKGND, sent|parent|optional },
2422     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2423
2424     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2425     { WM_DESTROY, sent|defwinproc },
2426     { WM_NCDESTROY, sent|defwinproc },
2427     { 0 }
2428 };
2429 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2430 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2431     { WM_MDIDESTROY, sent }, /* in MDI client */
2432     { WM_SHOWWINDOW, sent|wparam, 0 },
2433     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2434     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2435     { WM_ERASEBKGND, sent|parent|optional },
2436     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2437
2438     { HCBT_SETFOCUS, hook },
2439     { WM_KILLFOCUS, sent },
2440     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2441     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2442     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2443     { WM_SETFOCUS, sent }, /* in MDI client */
2444     { HCBT_SETFOCUS, hook },
2445     { WM_KILLFOCUS, sent }, /* in MDI client */
2446     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2447     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2448     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2449     { WM_SETFOCUS, sent },
2450
2451      /* in MDI child */
2452     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2453     { WM_NCCALCSIZE, sent|wparam, 1 },
2454     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2455     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2456
2457      /* in MDI frame */
2458     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2459     { WM_NCCALCSIZE, sent|wparam, 1 },
2460     { 0x0093, sent|defwinproc|optional },
2461     { 0x0093, sent|defwinproc|optional },
2462     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2463     { WM_MOVE, sent|defwinproc },
2464     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2465
2466      /* in MDI client */
2467     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2468     { WM_NCCALCSIZE, sent|wparam, 1 },
2469     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2470     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2471
2472      /* in MDI child */
2473     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2474     { WM_NCCALCSIZE, sent|wparam, 1 },
2475     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2476     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2477
2478      /* in MDI child */
2479     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2480     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2481     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2482     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2483
2484      /* in MDI frame */
2485     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2486     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2487     { 0x0093, sent|defwinproc|optional },
2488     { 0x0093, sent|defwinproc|optional },
2489     { 0x0093, sent|defwinproc|optional },
2490     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2491     { WM_MOVE, sent|defwinproc },
2492     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2493
2494      /* in MDI client */
2495     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2496     { WM_NCCALCSIZE, sent|wparam, 1 },
2497     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2498     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2499
2500      /* in MDI child */
2501     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2502     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2503     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2504     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2505     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2506     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2507
2508     { 0x0093, sent|defwinproc|optional },
2509     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2510     { 0x0093, sent|defwinproc|optional },
2511     { 0x0093, sent|defwinproc|optional },
2512     { 0x0093, sent|defwinproc|optional },
2513     { 0x0093, sent|optional },
2514
2515     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2516     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2517     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2518     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2519     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2520
2521      /* in MDI frame */
2522     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2523     { WM_NCCALCSIZE, sent|wparam, 1 },
2524     { 0x0093, sent|defwinproc|optional },
2525     { 0x0093, sent|defwinproc|optional },
2526     { 0x0093, sent|defwinproc|optional },
2527     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2528     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2529     { 0x0093, sent|optional },
2530
2531     { WM_NCACTIVATE, sent|wparam, 0 },
2532     { WM_MDIACTIVATE, sent },
2533
2534     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2535     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2536     { WM_NCCALCSIZE, sent|wparam, 1 },
2537
2538     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2539
2540     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2541     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2542     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2543
2544      /* in MDI child */
2545     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2546     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2547     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2548     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2549
2550      /* in MDI frame */
2551     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2552     { WM_NCCALCSIZE, sent|wparam, 1 },
2553     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2554     { WM_MOVE, sent|defwinproc },
2555     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2556
2557      /* in MDI client */
2558     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2559     { WM_NCCALCSIZE, sent|wparam, 1 },
2560     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2561     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2562     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2563     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2564     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2565     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2566     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2567
2568     { HCBT_SETFOCUS, hook },
2569     { WM_KILLFOCUS, sent },
2570     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2571     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2572     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2573     { WM_SETFOCUS, sent }, /* in MDI client */
2574
2575     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2576
2577     { HCBT_DESTROYWND, hook },
2578     /* Win2k sends wparam set to
2579      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2580      * while Win9x doesn't bother to set child window id according to
2581      * CLIENTCREATESTRUCT.idFirstChild
2582      */
2583     { 0x0090, sent|optional },
2584     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2585
2586     { WM_SHOWWINDOW, sent|wparam, 0 },
2587     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2588     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2589     { WM_ERASEBKGND, sent|parent|optional },
2590     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2591
2592     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2593     { WM_DESTROY, sent },
2594     { WM_NCDESTROY, sent },
2595     { 0 }
2596 };
2597 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2598 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2599     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2600     { WM_GETMINMAXINFO, sent },
2601     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2602     { WM_NCCALCSIZE, sent|wparam, 1 },
2603     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2604     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2605
2606     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2607     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2608     { HCBT_SETFOCUS, hook },
2609     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2610     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2611     { WM_SETFOCUS, sent }, /* in MDI client */
2612     { HCBT_SETFOCUS, hook },
2613     { WM_KILLFOCUS, sent }, /* in MDI client */
2614     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2615     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2616     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2617     { WM_SETFOCUS, sent|defwinproc },
2618     { WM_MDIACTIVATE, sent|defwinproc },
2619     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2620     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2621      /* in MDI frame */
2622     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2623     { WM_NCCALCSIZE, sent|wparam, 1 },
2624     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2625     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2626     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2627     { 0 }
2628 };
2629 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2630 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2631     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2632     { WM_GETMINMAXINFO, sent },
2633     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2634     { WM_GETMINMAXINFO, sent|defwinproc },
2635     { WM_NCCALCSIZE, sent|wparam, 1 },
2636     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2637     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2638
2639     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2640     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2641     { HCBT_SETFOCUS, hook },
2642     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2643     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2644     { WM_SETFOCUS, sent }, /* in MDI client */
2645     { HCBT_SETFOCUS, hook },
2646     { WM_KILLFOCUS, sent }, /* in MDI client */
2647     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2648     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2649     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2650     { WM_SETFOCUS, sent|defwinproc },
2651     { WM_MDIACTIVATE, sent|defwinproc },
2652     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2653     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2654     { 0 }
2655 };
2656 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2657 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2658     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2659     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2660     { WM_GETMINMAXINFO, sent },
2661     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2662     { WM_GETMINMAXINFO, sent|defwinproc },
2663     { WM_NCCALCSIZE, sent|wparam, 1 },
2664     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2665     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2666     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2667     { WM_MOVE, sent|defwinproc },
2668     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2669
2670     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2671     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2672     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2673     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2674     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2675     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2676      /* in MDI frame */
2677     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2678     { WM_NCCALCSIZE, sent|wparam, 1 },
2679     { 0x0093, sent|defwinproc|optional },
2680     { 0x0094, sent|defwinproc|optional },
2681     { 0x0094, sent|defwinproc|optional },
2682     { 0x0094, sent|defwinproc|optional },
2683     { 0x0094, sent|defwinproc|optional },
2684     { 0x0093, sent|defwinproc|optional },
2685     { 0x0093, sent|defwinproc|optional },
2686     { 0x0091, sent|defwinproc|optional },
2687     { 0x0092, sent|defwinproc|optional },
2688     { 0x0092, sent|defwinproc|optional },
2689     { 0x0092, sent|defwinproc|optional },
2690     { 0x0092, sent|defwinproc|optional },
2691     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2692     { WM_MOVE, sent|defwinproc },
2693     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2694     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2695      /* in MDI client */
2696     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2697     { WM_NCCALCSIZE, sent|wparam, 1 },
2698     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2699     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2700      /* in MDI child */
2701     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2702     { WM_GETMINMAXINFO, sent|defwinproc },
2703     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2704     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2705     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2706     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2707     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2708     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2709     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2710     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2711      /* in MDI frame */
2712     { 0x0093, sent|optional },
2713     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2714     { 0x0093, sent|defwinproc|optional },
2715     { 0x0093, sent|defwinproc|optional },
2716     { 0x0093, sent|defwinproc|optional },
2717     { 0x0091, sent|defwinproc|optional },
2718     { 0x0092, sent|defwinproc|optional },
2719     { 0x0092, sent|defwinproc|optional },
2720     { 0x0092, sent|defwinproc|optional },
2721     { 0x0092, sent|defwinproc|optional },
2722     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2723     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2724     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2725     { 0 }
2726 };
2727 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2728 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2729     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2730     { WM_GETMINMAXINFO, sent },
2731     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2732     { WM_NCCALCSIZE, sent|wparam, 1 },
2733     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2734     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2735     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2736      /* in MDI frame */
2737     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2738     { WM_NCCALCSIZE, sent|wparam, 1 },
2739     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2740     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2741     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2742     { 0 }
2743 };
2744 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2745 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2746     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2747     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2748     { WM_NCCALCSIZE, sent|wparam, 1 },
2749     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2750     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2751     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2752      /* in MDI frame */
2753     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2754     { WM_NCCALCSIZE, sent|wparam, 1 },
2755     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2756     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2757     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2758     { 0 }
2759 };
2760 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2761 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2762     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2763     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2764     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
2765     { WM_NCCALCSIZE, sent|wparam, 1 },
2766     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2767     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2768     { WM_MOVE, sent|defwinproc },
2769     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2770     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2771     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2772     { HCBT_SETFOCUS, hook },
2773     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2774     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2775     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2776     { WM_SETFOCUS, sent },
2777     { 0 }
2778 };
2779 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2780 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2781     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2782     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
2783     { WM_NCCALCSIZE, sent|wparam, 1 },
2784     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2785     { WM_MOVE, sent|defwinproc },
2786     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2787     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2788     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2789     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2790     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2791     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2792     { 0 }
2793 };
2794 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2795 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2796     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2797     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
2798     { WM_NCCALCSIZE, sent|wparam, 1 },
2799     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2800     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2801     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2802     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2803      /* in MDI frame */
2804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2805     { WM_NCCALCSIZE, sent|wparam, 1 },
2806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2807     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2808     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2809     { 0 }
2810 };
2811
2812 static HWND mdi_client;
2813 static WNDPROC old_mdi_client_proc;
2814
2815 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2816 {
2817     struct message msg;
2818
2819     /* do not log painting messages */
2820     if (message != WM_PAINT &&
2821         message != WM_NCPAINT &&
2822         message != WM_SYNCPAINT &&
2823         message != WM_ERASEBKGND &&
2824         message != WM_NCHITTEST &&
2825         message != WM_GETTEXT &&
2826         message != WM_MDIGETACTIVE &&
2827         message != WM_GETICON &&
2828         message != WM_DEVICECHANGE)
2829     {
2830         trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2831
2832         switch (message)
2833         {
2834             case WM_WINDOWPOSCHANGING:
2835             case WM_WINDOWPOSCHANGED:
2836             {
2837                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2838
2839                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2840                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
2841                       winpos->hwnd, winpos->hwndInsertAfter,
2842                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2843                 dump_winpos_flags(winpos->flags);
2844
2845                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2846                  * in the high word for internal purposes
2847                  */
2848                 wParam = winpos->flags & 0xffff;
2849                 /* We are not interested in the flags that don't match under XP and Win9x */
2850                 wParam &= ~(SWP_NOZORDER);
2851                 break;
2852             }
2853         }
2854
2855         msg.message = message;
2856         msg.flags = sent|wparam|lparam;
2857         msg.wParam = wParam;
2858         msg.lParam = lParam;
2859         add_message(&msg);
2860     }
2861
2862     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2863 }
2864
2865 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2866 {
2867     static long defwndproc_counter = 0;
2868     LRESULT ret;
2869     struct message msg;
2870
2871     /* do not log painting messages */
2872     if (message != WM_PAINT &&
2873         message != WM_NCPAINT &&
2874         message != WM_SYNCPAINT &&
2875         message != WM_ERASEBKGND &&
2876         message != WM_NCHITTEST &&
2877         message != WM_GETTEXT &&
2878         message != WM_GETICON &&
2879         message != WM_DEVICECHANGE)
2880     {
2881         trace("mdi child: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2882
2883         switch (message)
2884         {
2885             case WM_WINDOWPOSCHANGING:
2886             case WM_WINDOWPOSCHANGED:
2887             {
2888                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2889
2890                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2891                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
2892                       winpos->hwnd, winpos->hwndInsertAfter,
2893                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2894                 dump_winpos_flags(winpos->flags);
2895
2896                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2897                  * in the high word for internal purposes
2898                  */
2899                 wParam = winpos->flags & 0xffff;
2900                 /* We are not interested in the flags that don't match under XP and Win9x */
2901                 wParam &= ~(SWP_NOZORDER);
2902                 break;
2903             }
2904
2905             case WM_MDIACTIVATE:
2906             {
2907                 HWND active, client = GetParent(hwnd);
2908
2909                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2910
2911                 if (hwnd == (HWND)lParam) /* if we are being activated */
2912                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2913                 else
2914                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2915                 break;
2916             }
2917         }
2918
2919         msg.message = message;
2920         msg.flags = sent|wparam|lparam;
2921         if (defwndproc_counter) msg.flags |= defwinproc;
2922         msg.wParam = wParam;
2923         msg.lParam = lParam;
2924         add_message(&msg);
2925     }
2926
2927     defwndproc_counter++;
2928     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2929     defwndproc_counter--;
2930
2931     return ret;
2932 }
2933
2934 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2935 {
2936     static long defwndproc_counter = 0;
2937     LRESULT ret;
2938     struct message msg;
2939
2940     /* do not log painting messages */
2941     if (message != WM_PAINT &&
2942         message != WM_NCPAINT &&
2943         message != WM_SYNCPAINT &&
2944         message != WM_ERASEBKGND &&
2945         message != WM_NCHITTEST &&
2946         message != WM_GETTEXT &&
2947         message != WM_GETICON &&
2948         message != WM_DEVICECHANGE)
2949     {
2950         trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2951
2952         switch (message)
2953         {
2954             case WM_WINDOWPOSCHANGING:
2955             case WM_WINDOWPOSCHANGED:
2956             {
2957                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2958
2959                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2960                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
2961                       winpos->hwnd, winpos->hwndInsertAfter,
2962                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2963                 dump_winpos_flags(winpos->flags);
2964
2965                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2966                  * in the high word for internal purposes
2967                  */
2968                 wParam = winpos->flags & 0xffff;
2969                 /* We are not interested in the flags that don't match under XP and Win9x */
2970                 wParam &= ~(SWP_NOZORDER);
2971                 break;
2972             }
2973         }
2974
2975         msg.message = message;
2976         msg.flags = sent|wparam|lparam;
2977         if (defwndproc_counter) msg.flags |= defwinproc;
2978         msg.wParam = wParam;
2979         msg.lParam = lParam;
2980         add_message(&msg);
2981     }
2982
2983     defwndproc_counter++;
2984     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2985     defwndproc_counter--;
2986
2987     return ret;
2988 }
2989
2990 static BOOL mdi_RegisterWindowClasses(void)
2991 {
2992     WNDCLASSA cls;
2993
2994     cls.style = 0;
2995     cls.lpfnWndProc = mdi_frame_wnd_proc;
2996     cls.cbClsExtra = 0;
2997     cls.cbWndExtra = 0;
2998     cls.hInstance = GetModuleHandleA(0);
2999     cls.hIcon = 0;
3000     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3001     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3002     cls.lpszMenuName = NULL;
3003     cls.lpszClassName = "MDI_frame_class";
3004     if (!RegisterClassA(&cls)) return FALSE;
3005
3006     cls.lpfnWndProc = mdi_child_wnd_proc;
3007     cls.lpszClassName = "MDI_child_class";
3008     if (!RegisterClassA(&cls)) return FALSE;
3009
3010     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3011     old_mdi_client_proc = cls.lpfnWndProc;
3012     cls.hInstance = GetModuleHandleA(0);
3013     cls.lpfnWndProc = mdi_client_hook_proc;
3014     cls.lpszClassName = "MDI_client_class";
3015     if (!RegisterClassA(&cls)) assert(0);
3016
3017     return TRUE;
3018 }
3019
3020 static void test_mdi_messages(void)
3021 {
3022     MDICREATESTRUCTA mdi_cs;
3023     CLIENTCREATESTRUCT client_cs;
3024     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3025     BOOL zoomed;
3026     HMENU hMenu = CreateMenu();
3027
3028     assert(mdi_RegisterWindowClasses());
3029
3030     flush_sequence();
3031
3032     trace("creating MDI frame window\n");
3033     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3034                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3035                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3036                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3037                                 GetDesktopWindow(), hMenu,
3038                                 GetModuleHandleA(0), NULL);
3039     assert(mdi_frame);
3040     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3041
3042     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3043     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3044
3045     trace("creating MDI client window\n");
3046     client_cs.hWindowMenu = 0;
3047     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3048     mdi_client = CreateWindowExA(0, "MDI_client_class",
3049                                  NULL,
3050                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3051                                  0, 0, 0, 0,
3052                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3053     assert(mdi_client);
3054     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3055
3056     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3057     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3058
3059     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3060     ok(!active_child, "wrong active MDI child %p\n", active_child);
3061     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3062
3063     SetFocus(0);
3064     flush_sequence();
3065
3066     trace("creating invisible MDI child window\n");
3067     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3068                                 WS_CHILD,
3069                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3070                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3071     assert(mdi_child);
3072
3073     flush_sequence();
3074     ShowWindow(mdi_child, SW_SHOWNORMAL);
3075     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3076
3077     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3078     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3079
3080     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3081     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3082
3083     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3084     ok(!active_child, "wrong active MDI child %p\n", active_child);
3085     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3086
3087     ShowWindow(mdi_child, SW_HIDE);
3088     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3089     flush_sequence();
3090
3091     ShowWindow(mdi_child, SW_SHOW);
3092     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3093
3094     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3095     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3096
3097     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3098     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3099
3100     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3101     ok(!active_child, "wrong active MDI child %p\n", active_child);
3102     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3103
3104     DestroyWindow(mdi_child);
3105     flush_sequence();
3106
3107     trace("creating visible MDI child window\n");
3108     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3109                                 WS_CHILD | WS_VISIBLE,
3110                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3111                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3112     assert(mdi_child);
3113     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3114
3115     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3116     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3117
3118     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3119     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3120
3121     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3122     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3123     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3124     flush_sequence();
3125
3126     DestroyWindow(mdi_child);
3127     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3128
3129     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3130     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3131
3132     /* Win2k: MDI client still returns a just destroyed child as active
3133      * Win9x: MDI client returns 0
3134      */
3135     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3136     ok(active_child == mdi_child || /* win2k */
3137        !active_child, /* win9x */
3138        "wrong active MDI child %p\n", active_child);
3139     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3140
3141     flush_sequence();
3142
3143     trace("creating invisible MDI child window\n");
3144     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3145                                 WS_CHILD,
3146                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3147                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3148     assert(mdi_child2);
3149     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3150
3151     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3152     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3153
3154     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3155     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3156
3157     /* Win2k: MDI client still returns a just destroyed child as active
3158      * Win9x: MDI client returns mdi_child2
3159      */
3160     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3161     ok(active_child == mdi_child || /* win2k */
3162        active_child == mdi_child2, /* win9x */
3163        "wrong active MDI child %p\n", active_child);
3164     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3165     flush_sequence();
3166
3167     ShowWindow(mdi_child2, SW_MAXIMIZE);
3168     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3169
3170     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3171     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3172
3173     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3174     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3175     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3176     flush_sequence();
3177
3178     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3179     ok(GetFocus() == mdi_child2 || /* win2k */
3180        GetFocus() == 0, /* win9x */
3181        "wrong focus window %p\n", GetFocus());
3182
3183     SetFocus(0);
3184     flush_sequence();
3185
3186     ShowWindow(mdi_child2, SW_HIDE);
3187     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3188
3189     ShowWindow(mdi_child2, SW_RESTORE);
3190     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3191     flush_sequence();
3192
3193     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3194     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3195
3196     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3197     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3198     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3199     flush_sequence();
3200
3201     SetFocus(0);
3202     flush_sequence();
3203
3204     ShowWindow(mdi_child2, SW_HIDE);
3205     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3206
3207     ShowWindow(mdi_child2, SW_SHOW);
3208     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3209
3210     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3211     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3212
3213     ShowWindow(mdi_child2, SW_MAXIMIZE);
3214     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3215
3216     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3217     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3218
3219     ShowWindow(mdi_child2, SW_RESTORE);
3220     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3221
3222     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3223     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3224
3225     ShowWindow(mdi_child2, SW_MINIMIZE);
3226     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3227
3228     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3229     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3230
3231     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3232     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3233     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3234     flush_sequence();
3235
3236     ShowWindow(mdi_child2, SW_RESTORE);
3237     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3238
3239     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3240     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3241
3242     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3243     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3244     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3245     flush_sequence();
3246
3247     SetFocus(0);
3248     flush_sequence();
3249
3250     ShowWindow(mdi_child2, SW_HIDE);
3251     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3252
3253     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3254     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3255
3256     DestroyWindow(mdi_child2);
3257     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3258
3259     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3260     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3261
3262     /* test for maximized MDI children */
3263     trace("creating maximized visible MDI child window 1\n");
3264     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3265                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3266                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3267                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3268     assert(mdi_child);
3269     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3270     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3271
3272     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3273     ok(GetFocus() == mdi_child || /* win2k */
3274        GetFocus() == 0, /* win9x */
3275        "wrong focus window %p\n", GetFocus());
3276
3277     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3278     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3279     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3280     flush_sequence();
3281
3282     trace("creating maximized visible MDI child window 2\n");
3283     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3284                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3285                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3286                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3287     assert(mdi_child2);
3288     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3289     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3290     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3291
3292     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3293     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3294
3295     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3296     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3297     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3298     flush_sequence();
3299
3300     trace("destroying maximized visible MDI child window 2\n");
3301     DestroyWindow(mdi_child2);
3302     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3303
3304     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3305
3306     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3307     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3308
3309     /* Win2k: MDI client still returns a just destroyed child as active
3310      * Win9x: MDI client returns 0
3311      */
3312     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3313     ok(active_child == mdi_child2 || /* win2k */
3314        !active_child, /* win9x */
3315        "wrong active MDI child %p\n", active_child);
3316     flush_sequence();
3317
3318     ShowWindow(mdi_child, SW_MAXIMIZE);
3319     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3320     flush_sequence();
3321
3322     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3323     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3324
3325     trace("re-creating maximized visible MDI child window 2\n");
3326     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3327                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3328                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3329                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3330     assert(mdi_child2);
3331     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3332     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3333     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3334
3335     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3336     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3337
3338     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3339     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3340     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3341     flush_sequence();
3342
3343     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3344     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3345     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3346
3347     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3348     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3349     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3350
3351     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3352     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3353     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3354     flush_sequence();
3355
3356     DestroyWindow(mdi_child);
3357     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3358
3359     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3360     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3361
3362     /* Win2k: MDI client still returns a just destroyed child as active
3363      * Win9x: MDI client returns 0
3364      */
3365     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3366     ok(active_child == mdi_child || /* win2k */
3367        !active_child, /* win9x */
3368        "wrong active MDI child %p\n", active_child);
3369     flush_sequence();
3370
3371     trace("creating maximized invisible MDI child window\n");
3372     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3373                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3374                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3375                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3376     assert(mdi_child2);
3377     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3378     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3379     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3380     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3381
3382     /* Win2k: MDI client still returns a just destroyed child as active
3383      * Win9x: MDI client returns 0
3384      */
3385     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3386     ok(active_child == mdi_child || /* win2k */
3387        !active_child, /* win9x */
3388        "wrong active MDI child %p\n", active_child);
3389     flush_sequence();
3390
3391     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3392     ShowWindow(mdi_child2, SW_MAXIMIZE);
3393     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3394     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3395     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3396     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3397
3398     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3399     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3400     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3401     flush_sequence();
3402
3403     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3404     flush_sequence();
3405
3406     /* end of test for maximized MDI children */
3407     SetFocus(0);
3408     flush_sequence();
3409     trace("creating maximized visible MDI child window 1(Switch test)\n");
3410     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3411                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3412                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3413                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3414     assert(mdi_child);
3415     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3416     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3417
3418     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3419     ok(GetFocus() == mdi_child || /* win2k */
3420        GetFocus() == 0, /* win9x */
3421        "wrong focus window %p(Switch test)\n", GetFocus());
3422
3423     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3424     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3425     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3426     flush_sequence();
3427
3428     trace("creating maximized visible MDI child window 2(Switch test)\n");
3429     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3430                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3431                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3432                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3433     assert(mdi_child2);
3434     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3435
3436     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3437     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3438
3439     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3440     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3441
3442     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3443     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3444     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3445     flush_sequence();
3446
3447     trace("Switch child window.\n");
3448     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3449     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3450     trace("end of test for switch maximized MDI children\n");
3451     flush_sequence();
3452
3453     /* Prepare for switching test of not maximized MDI children  */
3454     ShowWindow( mdi_child, SW_NORMAL );
3455     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3456     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3457     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3458     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3459     flush_sequence();
3460
3461     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3462     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3463     trace("end of test for switch not maximized MDI children\n");
3464     flush_sequence();
3465
3466     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3467     flush_sequence();
3468
3469     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3470     flush_sequence();
3471
3472     SetFocus(0);
3473     flush_sequence();
3474     /* end of tests for switch maximized/not maximized MDI children */
3475
3476     mdi_cs.szClass = "MDI_child_Class";
3477     mdi_cs.szTitle = "MDI child";
3478     mdi_cs.hOwner = GetModuleHandleA(0);
3479     mdi_cs.x = 0;
3480     mdi_cs.y = 0;
3481     mdi_cs.cx = CW_USEDEFAULT;
3482     mdi_cs.cy = CW_USEDEFAULT;
3483     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3484     mdi_cs.lParam = 0;
3485     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3486     ok(mdi_child != 0, "MDI child creation failed\n");
3487     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3488
3489     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3490
3491     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3492     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3493
3494     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3495     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3496     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3497
3498     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3499     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3500     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3501     flush_sequence();
3502
3503     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3504     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3505
3506     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3507     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3508     ok(!active_child, "wrong active MDI child %p\n", active_child);
3509
3510     SetFocus(0);
3511     flush_sequence();
3512
3513     DestroyWindow(mdi_client);
3514     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3515
3516     /* test maximization of MDI child with invisible parent */
3517     client_cs.hWindowMenu = 0;
3518     mdi_client = CreateWindow("MDI_client_class",
3519                                  NULL,
3520                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3521                                  0, 0, 660, 430,
3522                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3523     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3524
3525     ShowWindow(mdi_client, SW_HIDE);
3526     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3527
3528     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3529                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3530                                 0, 0, 650, 440,
3531                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3532     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3533
3534     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3535     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3536     zoomed = IsZoomed(mdi_child);
3537     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3538     
3539     ShowWindow(mdi_client, SW_SHOW);
3540     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3541
3542     DestroyWindow(mdi_child);
3543     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3544
3545     /* end of test for maximization of MDI child with invisible parent */
3546
3547     DestroyWindow(mdi_client);
3548     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3549
3550     DestroyWindow(mdi_frame);
3551     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3552 }
3553 /************************* End of MDI test **********************************/
3554
3555 static void test_WM_SETREDRAW(HWND hwnd)
3556 {
3557     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3558
3559     flush_sequence();
3560
3561     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3562     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3563
3564     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3565     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3566
3567     flush_sequence();
3568     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3569     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3570
3571     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3572     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3573
3574     /* restore original WS_VISIBLE state */
3575     SetWindowLongA(hwnd, GWL_STYLE, style);
3576
3577     flush_sequence();
3578 }
3579
3580 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3581 {
3582     struct message msg;
3583
3584     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3585
3586     /* explicitly ignore WM_GETICON message */
3587     if (message == WM_GETICON) return 0;
3588
3589     switch (message)
3590     {
3591         /* ignore */
3592         case WM_MOUSEMOVE:
3593         case WM_SETCURSOR:
3594         case WM_DEVICECHANGE:
3595             return 0;
3596         case WM_NCHITTEST:
3597             return HTCLIENT;
3598
3599         case WM_WINDOWPOSCHANGING:
3600         case WM_WINDOWPOSCHANGED:
3601         {
3602             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3603
3604             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3605             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
3606                   winpos->hwnd, winpos->hwndInsertAfter,
3607                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3608             dump_winpos_flags(winpos->flags);
3609
3610             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3611              * in the high word for internal purposes
3612              */
3613             wParam = winpos->flags & 0xffff;
3614             /* We are not interested in the flags that don't match under XP and Win9x */
3615             wParam &= ~(SWP_NOZORDER);
3616             break;
3617         }
3618     }
3619
3620     msg.message = message;
3621     msg.flags = sent|wparam|lparam;
3622     msg.wParam = wParam;
3623     msg.lParam = lParam;
3624     add_message(&msg);
3625
3626     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3627     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3628     return 0;
3629 }
3630
3631 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3632 {
3633     DWORD style, exstyle;
3634     INT xmin, xmax;
3635     BOOL ret;
3636
3637     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3638     style = GetWindowLongA(hwnd, GWL_STYLE);
3639     /* do not be confused by WS_DLGFRAME set */
3640     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3641
3642     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3643     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3644
3645     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3646     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3647     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3648         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3649     else
3650         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3651
3652     style = GetWindowLongA(hwnd, GWL_STYLE);
3653     if (set) ok(style & set, "style %08x should be set\n", set);
3654     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3655
3656     /* a subsequent call should do nothing */
3657     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3658     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3659     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3660
3661     xmin = 0xdeadbeef;
3662     xmax = 0xdeadbeef;
3663     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3664     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3665     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3666     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3667     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3668     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3669 }
3670
3671 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3672 {
3673     DWORD style, exstyle;
3674     SCROLLINFO si;
3675     BOOL ret;
3676
3677     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3678     style = GetWindowLongA(hwnd, GWL_STYLE);
3679     /* do not be confused by WS_DLGFRAME set */
3680     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3681
3682     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3683     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3684
3685     si.cbSize = sizeof(si);
3686     si.fMask = SIF_RANGE;
3687     si.nMin = min;
3688     si.nMax = max;
3689     SetScrollInfo(hwnd, ctl, &si, TRUE);
3690     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3691         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3692     else
3693         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3694
3695     style = GetWindowLongA(hwnd, GWL_STYLE);
3696     if (set) ok(style & set, "style %08x should be set\n", set);
3697     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3698
3699     /* a subsequent call should do nothing */
3700     SetScrollInfo(hwnd, ctl, &si, TRUE);
3701     if (style & WS_HSCROLL)
3702         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3703     else if (style & WS_VSCROLL)
3704         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3705     else
3706         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3707
3708     si.fMask = SIF_PAGE;
3709     si.nPage = 5;
3710     SetScrollInfo(hwnd, ctl, &si, FALSE);
3711     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3712
3713     si.fMask = SIF_POS;
3714     si.nPos = max - 1;
3715     SetScrollInfo(hwnd, ctl, &si, FALSE);
3716     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3717
3718     si.fMask = SIF_RANGE;
3719     si.nMin = 0xdeadbeef;
3720     si.nMax = 0xdeadbeef;
3721     ret = GetScrollInfo(hwnd, ctl, &si);
3722     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3723     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3724     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3725     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3726 }
3727
3728 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3729 static void test_scroll_messages(HWND hwnd)
3730 {
3731     SCROLLINFO si;
3732     INT min, max;
3733     BOOL ret;
3734
3735     min = 0xdeadbeef;
3736     max = 0xdeadbeef;
3737     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3738     ok( ret, "GetScrollRange error %d\n", GetLastError());
3739     if (sequence->message != WmGetScrollRangeSeq[0].message)
3740         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3741     /* values of min and max are undefined */
3742     flush_sequence();
3743
3744     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3745     ok( ret, "SetScrollRange error %d\n", GetLastError());
3746     if (sequence->message != WmSetScrollRangeSeq[0].message)
3747         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3748     flush_sequence();
3749
3750     min = 0xdeadbeef;
3751     max = 0xdeadbeef;
3752     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3753     ok( ret, "GetScrollRange error %d\n", GetLastError());
3754     if (sequence->message != WmGetScrollRangeSeq[0].message)
3755         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3756     /* values of min and max are undefined */
3757     flush_sequence();
3758
3759     si.cbSize = sizeof(si);
3760     si.fMask = SIF_RANGE;
3761     si.nMin = 20;
3762     si.nMax = 160;
3763     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3764     if (sequence->message != WmSetScrollRangeSeq[0].message)
3765         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3766     flush_sequence();
3767
3768     si.fMask = SIF_PAGE;
3769     si.nPage = 10;
3770     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3771     if (sequence->message != WmSetScrollRangeSeq[0].message)
3772         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3773     flush_sequence();
3774
3775     si.fMask = SIF_POS;
3776     si.nPos = 20;
3777     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3778     if (sequence->message != WmSetScrollRangeSeq[0].message)
3779         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3780     flush_sequence();
3781
3782     si.fMask = SIF_RANGE;
3783     si.nMin = 0xdeadbeef;
3784     si.nMax = 0xdeadbeef;
3785     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3786     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3787     if (sequence->message != WmGetScrollInfoSeq[0].message)
3788         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3789     /* values of min and max are undefined */
3790     flush_sequence();
3791
3792     /* set WS_HSCROLL */
3793     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3794     /* clear WS_HSCROLL */
3795     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3796
3797     /* set WS_HSCROLL */
3798     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3799     /* clear WS_HSCROLL */
3800     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3801
3802     /* set WS_VSCROLL */
3803     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3804     /* clear WS_VSCROLL */
3805     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3806
3807     /* set WS_VSCROLL */
3808     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3809     /* clear WS_VSCROLL */
3810     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3811 }
3812
3813 static void test_showwindow(void)
3814 {
3815     HWND hwnd, hchild;
3816     RECT rc;
3817
3818     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3819                            100, 100, 200, 200, 0, 0, 0, NULL);
3820     ok (hwnd != 0, "Failed to create overlapped window\n");
3821     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3822                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3823     ok (hchild != 0, "Failed to create child\n");
3824     flush_sequence();
3825
3826     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3827     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3828     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3829     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3830     trace("done\n");
3831
3832     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3833     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3834     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3835     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3836     trace("done\n");
3837     /* back to invisible */
3838     ShowWindow(hchild, SW_HIDE);
3839     ShowWindow(hwnd, SW_HIDE);
3840     flush_sequence();
3841     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3842     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3843     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3844     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3845     trace("done\n");
3846     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3847     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3848     flush_sequence();
3849     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3850     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3851     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3852     trace("done\n");
3853     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3854     ShowWindow( hwnd, SW_SHOW);
3855     flush_sequence();
3856     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3857     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3858     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3859     trace("done\n");
3860
3861     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3862     ShowWindow( hchild, SW_HIDE);
3863     flush_sequence();
3864     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3865     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3866     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3867     trace("done\n");
3868
3869     SetCapture(hchild);
3870     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3871     DestroyWindow(hchild);
3872     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3873
3874     DestroyWindow(hwnd);
3875     flush_sequence();
3876
3877     /* Popup windows */
3878     /* Test 1:
3879      * 1. Create invisible maximized popup window.
3880      * 2. Move and resize it.
3881      * 3. Show it maximized.
3882      */
3883     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3884     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3885                            100, 100, 200, 200, 0, 0, 0, NULL);
3886     ok (hwnd != 0, "Failed to create popup window\n");
3887     ok(IsZoomed(hwnd), "window should be maximized\n");
3888     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3889     trace("done\n");
3890
3891     GetWindowRect(hwnd, &rc);
3892     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3893         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3894         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3895         rc.left, rc.top, rc.right, rc.bottom);
3896     /* Reset window's size & position */
3897     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3898     ok(IsZoomed(hwnd), "window should be maximized\n");
3899     flush_sequence();
3900
3901     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3902     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3903     ok(IsZoomed(hwnd), "window should be maximized\n");
3904     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3905     trace("done\n");
3906
3907     GetWindowRect(hwnd, &rc);
3908     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3909         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3910         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3911         rc.left, rc.top, rc.right, rc.bottom);
3912     DestroyWindow(hwnd);
3913     flush_sequence();
3914
3915     /* Test 2:
3916      * 1. Create invisible maximized popup window.
3917      * 2. Show it maximized.
3918      */
3919     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3920     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3921                            100, 100, 200, 200, 0, 0, 0, NULL);
3922     ok (hwnd != 0, "Failed to create popup window\n");
3923     ok(IsZoomed(hwnd), "window should be maximized\n");
3924     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3925     trace("done\n");
3926
3927     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3928     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3929     ok(IsZoomed(hwnd), "window should be maximized\n");
3930     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3931     trace("done\n");
3932     DestroyWindow(hwnd);
3933     flush_sequence();
3934
3935     /* Test 3:
3936      * 1. Create visible maximized popup window.
3937      */
3938     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3939     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3940                            100, 100, 200, 200, 0, 0, 0, NULL);
3941     ok (hwnd != 0, "Failed to create popup window\n");
3942     ok(IsZoomed(hwnd), "window should be maximized\n");
3943     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3944     trace("done\n");
3945     DestroyWindow(hwnd);
3946     flush_sequence();
3947
3948     /* Test 4:
3949      * 1. Create visible popup window.
3950      * 2. Maximize it.
3951      */
3952     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3953     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3954                            100, 100, 200, 200, 0, 0, 0, NULL);
3955     ok (hwnd != 0, "Failed to create popup window\n");
3956     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3957     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
3958     trace("done\n");
3959
3960     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3961     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3962     ok(IsZoomed(hwnd), "window should be maximized\n");
3963     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3964     trace("done\n");
3965     DestroyWindow(hwnd);
3966     flush_sequence();
3967 }
3968
3969 static void test_sys_menu(void)
3970 {
3971     HWND hwnd;
3972     HMENU hmenu;
3973     UINT state;
3974
3975     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3976                            100, 100, 200, 200, 0, 0, 0, NULL);
3977     ok (hwnd != 0, "Failed to create overlapped window\n");
3978
3979     flush_sequence();
3980
3981     /* test existing window without CS_NOCLOSE style */
3982     hmenu = GetSystemMenu(hwnd, FALSE);
3983     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3984
3985     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3986     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3987     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3988
3989     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3990     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3991
3992     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3993     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3994     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3995
3996     EnableMenuItem(hmenu, SC_CLOSE, 0);
3997     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3998
3999     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4000     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4001     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4002
4003     /* test whether removing WS_SYSMENU destroys a system menu */
4004     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4005     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4006     flush_sequence();
4007     hmenu = GetSystemMenu(hwnd, FALSE);
4008     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4009
4010     DestroyWindow(hwnd);
4011
4012     /* test new window with CS_NOCLOSE style */
4013     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4014                            100, 100, 200, 200, 0, 0, 0, NULL);
4015     ok (hwnd != 0, "Failed to create overlapped window\n");
4016
4017     hmenu = GetSystemMenu(hwnd, FALSE);
4018     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4019
4020     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4021     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4022
4023     DestroyWindow(hwnd);
4024
4025     /* test new window without WS_SYSMENU style */
4026     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4027                            100, 100, 200, 200, 0, 0, 0, NULL);
4028     ok(hwnd != 0, "Failed to create overlapped window\n");
4029
4030     hmenu = GetSystemMenu(hwnd, FALSE);
4031     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4032
4033     DestroyWindow(hwnd);
4034 }
4035
4036 /* For shown WS_OVERLAPPEDWINDOW */
4037 static const struct message WmSetIcon_1[] = {
4038     { WM_SETICON, sent },
4039     { 0x00AE, sent|defwinproc|optional }, /* XP */
4040     { WM_GETTEXT, sent|defwinproc|optional },
4041     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4042     { 0 }
4043 };
4044
4045 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4046 static const struct message WmSetIcon_2[] = {
4047     { WM_SETICON, sent },
4048     { 0 }
4049 };
4050
4051 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4052 static const struct message WmInitEndSession[] = {
4053     { 0x003B, sent },
4054     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4055     { 0 }
4056 };
4057
4058 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4059 static const struct message WmInitEndSession_2[] = {
4060     { 0x003B, sent },
4061     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4062     { 0 }
4063 };
4064
4065 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4066 static const struct message WmInitEndSession_3[] = {
4067     { 0x003B, sent },
4068     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4069     { 0 }
4070 };
4071
4072 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4073 static const struct message WmInitEndSession_4[] = {
4074     { 0x003B, sent },
4075     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4076     { 0 }
4077 };
4078
4079 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4080 static const struct message WmInitEndSession_5[] = {
4081     { 0x003B, sent },
4082     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 1, ENDSESSION_LOGOFF },
4083     { 0 }
4084 };
4085
4086 static const struct message WmZOrder[] = {
4087     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4088     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4089     { HCBT_ACTIVATE, hook },
4090     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4091     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4092     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4093     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4094     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4095     { HCBT_SETFOCUS, hook },
4096     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4097     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4098     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4099     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4100     { 0 }
4101 };
4102
4103 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4104 {
4105     DWORD ret;
4106     MSG msg;
4107
4108     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4109     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4110
4111     PostMessageA(hwnd, WM_USER, 0, 0);
4112
4113     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4114     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4115
4116     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4117     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4118
4119     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4120     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4121
4122     PostMessageA(hwnd, WM_USER, 0, 0);
4123
4124     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4125     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4126
4127     ok(PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4128     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4129
4130     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4131     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4132     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4133
4134     PostMessageA(hwnd, WM_USER, 0, 0);
4135
4136     /* new incoming message causes it to become signaled again */
4137     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4138     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4139
4140     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4141     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4142     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4143     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4144 }
4145
4146 /* test if we receive the right sequence of messages */
4147 static void test_messages(void)
4148 {
4149     HWND hwnd, hparent, hchild;
4150     HWND hchild2, hbutton;
4151     HMENU hmenu;
4152     MSG msg;
4153     LRESULT res;
4154
4155     flush_sequence();
4156
4157     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4158                            100, 100, 200, 200, 0, 0, 0, NULL);
4159     ok (hwnd != 0, "Failed to create overlapped window\n");
4160     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4161
4162     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4163     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4164     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4165
4166     /* test WM_SETREDRAW on a not visible top level window */
4167     test_WM_SETREDRAW(hwnd);
4168
4169     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4170     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4171     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4172
4173     ok(GetActiveWindow() == hwnd, "window should be active\n");
4174     ok(GetFocus() == hwnd, "window should have input focus\n");
4175     ShowWindow(hwnd, SW_HIDE);
4176     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4177
4178     ShowWindow(hwnd, SW_SHOW);
4179     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4180
4181     ShowWindow(hwnd, SW_HIDE);
4182     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4183
4184     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4185     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4186
4187     ShowWindow(hwnd, SW_RESTORE);
4188     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4189     flush_sequence();
4190
4191     ShowWindow(hwnd, SW_MINIMIZE);
4192     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4193     flush_sequence();
4194
4195     ShowWindow(hwnd, SW_RESTORE);
4196     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4197     flush_sequence();
4198
4199     ShowWindow(hwnd, SW_SHOW);
4200     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4201
4202     ok(GetActiveWindow() == hwnd, "window should be active\n");
4203     ok(GetFocus() == hwnd, "window should have input focus\n");
4204     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4205     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4206     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4207     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4208
4209     /* test WM_SETREDRAW on a visible top level window */
4210     ShowWindow(hwnd, SW_SHOW);
4211     test_WM_SETREDRAW(hwnd);
4212
4213     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4214     test_scroll_messages(hwnd);
4215
4216     /* test resizing and moving */
4217     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4218     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4219     flush_events();
4220     flush_sequence();
4221     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4222     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4223     flush_events();
4224     flush_sequence();
4225     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER );
4226     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4227     flush_events();
4228     flush_sequence();
4229
4230     /* popups don't get WM_GETMINMAXINFO */
4231     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4232     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4233     flush_sequence();
4234     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4235     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4236
4237     DestroyWindow(hwnd);
4238     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4239
4240     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4241                               100, 100, 200, 200, 0, 0, 0, NULL);
4242     ok (hparent != 0, "Failed to create parent window\n");
4243     flush_sequence();
4244
4245     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4246                              0, 0, 10, 10, hparent, 0, 0, NULL);
4247     ok (hchild != 0, "Failed to create child window\n");
4248     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4249     DestroyWindow(hchild);
4250     flush_sequence();
4251
4252     /* visible child window with a caption */
4253     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4254                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4255                              0, 0, 10, 10, hparent, 0, 0, NULL);
4256     ok (hchild != 0, "Failed to create child window\n");
4257     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4258
4259     trace("testing scroll APIs on a visible child window %p\n", hchild);
4260     test_scroll_messages(hchild);
4261
4262     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4263     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4264
4265     DestroyWindow(hchild);
4266     flush_sequence();
4267
4268     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4269                              0, 0, 10, 10, hparent, 0, 0, NULL);
4270     ok (hchild != 0, "Failed to create child window\n");
4271     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4272     
4273     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4274                                100, 100, 50, 50, hparent, 0, 0, NULL);
4275     ok (hchild2 != 0, "Failed to create child2 window\n");
4276     flush_sequence();
4277
4278     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4279                               0, 100, 50, 50, hchild, 0, 0, NULL);
4280     ok (hbutton != 0, "Failed to create button window\n");
4281
4282     /* test WM_SETREDRAW on a not visible child window */
4283     test_WM_SETREDRAW(hchild);
4284
4285     ShowWindow(hchild, SW_SHOW);
4286     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4287
4288     /* check parent messages too */
4289     log_all_parent_messages++;
4290     ShowWindow(hchild, SW_HIDE);
4291     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4292     log_all_parent_messages--;
4293
4294     ShowWindow(hchild, SW_SHOW);
4295     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4296
4297     ShowWindow(hchild, SW_HIDE);
4298     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4299
4300     ShowWindow(hchild, SW_SHOW);
4301     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4302
4303     /* test WM_SETREDRAW on a visible child window */
4304     test_WM_SETREDRAW(hchild);
4305
4306     log_all_parent_messages++;
4307     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4308     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4309     log_all_parent_messages--;
4310
4311     ShowWindow(hchild, SW_HIDE);
4312     flush_sequence();
4313     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4314     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4315
4316     ShowWindow(hchild, SW_HIDE);
4317     flush_sequence();
4318     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4319     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4320
4321     /* DestroyWindow sequence below expects that a child has focus */
4322     SetFocus(hchild);
4323     flush_sequence();
4324
4325     DestroyWindow(hchild);
4326     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4327     DestroyWindow(hchild2);
4328     DestroyWindow(hbutton);
4329
4330     flush_sequence();
4331     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4332                              0, 0, 100, 100, hparent, 0, 0, NULL);
4333     ok (hchild != 0, "Failed to create child popup window\n");
4334     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4335     DestroyWindow(hchild);
4336
4337     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4338     flush_sequence();
4339     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4340                              0, 0, 100, 100, hparent, 0, 0, NULL);
4341     ok (hchild != 0, "Failed to create popup window\n");
4342     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4343     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4344     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4345     flush_sequence();
4346     ShowWindow(hchild, SW_SHOW);
4347     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4348     flush_sequence();
4349     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4350     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4351     flush_sequence();
4352     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4353     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", TRUE);
4354     DestroyWindow(hchild);
4355
4356     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4357      * changes nothing in message sequences.
4358      */
4359     flush_sequence();
4360     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4361                              0, 0, 100, 100, hparent, 0, 0, NULL);
4362     ok (hchild != 0, "Failed to create popup window\n");
4363     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4364     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4365     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4366     flush_sequence();
4367     ShowWindow(hchild, SW_SHOW);
4368     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4369     flush_sequence();
4370     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4371     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4372     DestroyWindow(hchild);
4373
4374     flush_sequence();
4375     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4376                            0, 0, 100, 100, hparent, 0, 0, NULL);
4377     ok(hwnd != 0, "Failed to create custom dialog window\n");
4378     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4379
4380     /*
4381     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4382     test_scroll_messages(hwnd);
4383     */
4384
4385     flush_sequence();
4386
4387     test_def_id = 1;
4388     SendMessage(hwnd, WM_NULL, 0, 0);
4389
4390     flush_sequence();
4391     after_end_dialog = 1;
4392     EndDialog( hwnd, 0 );
4393     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4394
4395     DestroyWindow(hwnd);
4396     after_end_dialog = 0;
4397     test_def_id = 0;
4398
4399     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4400                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4401     ok(hwnd != 0, "Failed to create custom dialog window\n");
4402     flush_sequence();
4403     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4404     ShowWindow(hwnd, SW_SHOW);
4405     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4406     DestroyWindow(hwnd);
4407
4408     flush_sequence();
4409     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4410     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4411
4412     DestroyWindow(hparent);
4413     flush_sequence();
4414
4415     /* Message sequence for SetMenu */
4416     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4417     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4418
4419     hmenu = CreateMenu();
4420     ok (hmenu != 0, "Failed to create menu\n");
4421     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4422     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4423                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4424     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4425     ok (SetMenu(hwnd, 0), "SetMenu\n");
4426     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4427     ok (SetMenu(hwnd, 0), "SetMenu\n");
4428     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4429     ShowWindow(hwnd, SW_SHOW);
4430     UpdateWindow( hwnd );
4431     flush_events();
4432     flush_sequence();
4433     ok (SetMenu(hwnd, 0), "SetMenu\n");
4434     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4435     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4436     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4437
4438     UpdateWindow( hwnd );
4439     flush_events();
4440     flush_sequence();
4441     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4442     flush_events();
4443     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4444
4445     DestroyWindow(hwnd);
4446     flush_sequence();
4447
4448     /* Message sequence for EnableWindow */
4449     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4450                               100, 100, 200, 200, 0, 0, 0, NULL);
4451     ok (hparent != 0, "Failed to create parent window\n");
4452     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4453                              0, 0, 10, 10, hparent, 0, 0, NULL);
4454     ok (hchild != 0, "Failed to create child window\n");
4455
4456     SetFocus(hchild);
4457     flush_events();
4458     flush_sequence();
4459
4460     EnableWindow(hparent, FALSE);
4461     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4462
4463     EnableWindow(hparent, TRUE);
4464     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4465
4466     flush_events();
4467     flush_sequence();
4468
4469     test_MsgWaitForMultipleObjects(hparent);
4470
4471     /* the following test causes an exception in user.exe under win9x */
4472     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4473     {
4474         DestroyWindow(hparent);
4475         flush_sequence();
4476         return;
4477     }
4478     PostMessageW( hparent, WM_USER+1, 0, 0 );
4479     /* PeekMessage(NULL) fails, but still removes the message */
4480     SetLastError(0xdeadbeef);
4481     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4482     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4483         GetLastError() == 0xdeadbeef, /* NT4 */
4484         "last error is %d\n", GetLastError() );
4485     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4486     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4487
4488     DestroyWindow(hchild);
4489     DestroyWindow(hparent);
4490     flush_sequence();
4491
4492     /* Message sequences for WM_SETICON */
4493     trace("testing WM_SETICON\n");
4494     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4495                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4496                            NULL, NULL, 0);
4497     ShowWindow(hwnd, SW_SHOW);
4498     UpdateWindow(hwnd);
4499     flush_events();
4500     flush_sequence();
4501     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4502     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4503
4504     ShowWindow(hwnd, SW_HIDE);
4505     flush_events();
4506     flush_sequence();
4507     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4508     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4509     DestroyWindow(hwnd);
4510     flush_sequence();
4511
4512     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4513                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4514                            NULL, NULL, 0);
4515     ShowWindow(hwnd, SW_SHOW);
4516     UpdateWindow(hwnd);
4517     flush_events();
4518     flush_sequence();
4519     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4520     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4521
4522     ShowWindow(hwnd, SW_HIDE);
4523     flush_events();
4524     flush_sequence();
4525     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4526     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4527
4528     flush_sequence();
4529     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4530     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4531     todo_wine
4532     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4533     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4534     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4535     todo_wine
4536     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4537     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4538     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4539     todo_wine
4540     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4541
4542     flush_sequence();
4543     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4544     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4545     todo_wine
4546     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4547     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4548     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4549     todo_wine
4550     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4551
4552     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4553     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4554     todo_wine
4555     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4556
4557     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4558     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4559     todo_wine
4560     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4561
4562     DestroyWindow(hwnd);
4563     flush_sequence();
4564 }
4565
4566 static void test_setwindowpos(void)
4567 {
4568     HWND hwnd;
4569     RECT rc;
4570     LRESULT res;
4571     const INT winX = 100;
4572     const INT winY = 100;
4573     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4574
4575     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4576                            0, 0, winX, winY, 0,
4577                            NULL, NULL, 0);
4578
4579     GetWindowRect(hwnd, &rc);
4580     expect(sysX, rc.right);
4581     expect(winY, rc.bottom);
4582     GetClientRect(hwnd, &rc);
4583     expect(sysX - 6, rc.right);
4584     expect(winY - 25, rc.bottom);
4585
4586     flush_events();
4587     flush_sequence();
4588     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4589     ok_sequence(WmZOrder, "Z-Order", TRUE);
4590     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4591
4592     GetWindowRect(hwnd, &rc);
4593     expect(sysX, rc.right);
4594     expect(winY, rc.bottom);
4595     GetClientRect(hwnd, &rc);
4596     expect(sysX - 6, rc.right);
4597     expect(winY - 25, rc.bottom);
4598
4599     DestroyWindow(hwnd);
4600 }
4601
4602 static void invisible_parent_tests(void)
4603 {
4604     HWND hparent, hchild;
4605
4606     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4607                               100, 100, 200, 200, 0, 0, 0, NULL);
4608     ok (hparent != 0, "Failed to create parent window\n");
4609     flush_sequence();
4610
4611     /* test showing child with hidden parent */
4612
4613     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4614                              0, 0, 10, 10, hparent, 0, 0, NULL);
4615     ok (hchild != 0, "Failed to create child window\n");
4616     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4617
4618     ShowWindow( hchild, SW_MINIMIZE );
4619     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4620     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4621     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4622
4623     /* repeat */
4624     flush_events();
4625     flush_sequence();
4626     ShowWindow( hchild, SW_MINIMIZE );
4627     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4628
4629     DestroyWindow(hchild);
4630     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4631                              0, 0, 10, 10, hparent, 0, 0, NULL);
4632     flush_sequence();
4633
4634     ShowWindow( hchild, SW_MAXIMIZE );
4635     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4636     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4637     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4638
4639     /* repeat */
4640     flush_events();
4641     flush_sequence();
4642     ShowWindow( hchild, SW_MAXIMIZE );
4643     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4644
4645     DestroyWindow(hchild);
4646     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4647                              0, 0, 10, 10, hparent, 0, 0, NULL);
4648     flush_sequence();
4649
4650     ShowWindow( hchild, SW_RESTORE );
4651     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4652     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4653     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4654
4655     DestroyWindow(hchild);
4656     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4657                              0, 0, 10, 10, hparent, 0, 0, NULL);
4658     flush_sequence();
4659
4660     ShowWindow( hchild, SW_SHOWMINIMIZED );
4661     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4662     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4663     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4664
4665     /* repeat */
4666     flush_events();
4667     flush_sequence();
4668     ShowWindow( hchild, SW_SHOWMINIMIZED );
4669     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4670
4671     DestroyWindow(hchild);
4672     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4673                              0, 0, 10, 10, hparent, 0, 0, NULL);
4674     flush_sequence();
4675
4676     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4677     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4678     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4679     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4680     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4681
4682     DestroyWindow(hchild);
4683     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4684                              0, 0, 10, 10, hparent, 0, 0, NULL);
4685     flush_sequence();
4686
4687     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4688     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4689     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4690     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4691
4692     /* repeat */
4693     flush_events();
4694     flush_sequence();
4695     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4696     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4697
4698     DestroyWindow(hchild);
4699     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4700                              0, 0, 10, 10, hparent, 0, 0, NULL);
4701     flush_sequence();
4702
4703     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4704     ShowWindow( hchild, SW_FORCEMINIMIZE );
4705     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4706 todo_wine {
4707     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4708 }
4709     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4710
4711     DestroyWindow(hchild);
4712     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4713                              0, 0, 10, 10, hparent, 0, 0, NULL);
4714     flush_sequence();
4715
4716     ShowWindow( hchild, SW_SHOWNA );
4717     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4718     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4719     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4720
4721     /* repeat */
4722     flush_events();
4723     flush_sequence();
4724     ShowWindow( hchild, SW_SHOWNA );
4725     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4726
4727     DestroyWindow(hchild);
4728     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4729                              0, 0, 10, 10, hparent, 0, 0, NULL);
4730     flush_sequence();
4731
4732     ShowWindow( hchild, SW_SHOW );
4733     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4734     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4735     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4736
4737     /* repeat */
4738     flush_events();
4739     flush_sequence();
4740     ShowWindow( hchild, SW_SHOW );
4741     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4742
4743     ShowWindow( hchild, SW_HIDE );
4744     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4745     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4746     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4747
4748     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4749     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4750     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4751     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4752
4753     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4754     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4755     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4756     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4757
4758     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4759     flush_sequence();
4760     DestroyWindow(hchild);
4761     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4762
4763     DestroyWindow(hparent);
4764     flush_sequence();
4765 }
4766
4767 /****************** button message test *************************/
4768 static const struct message WmSetFocusButtonSeq[] =
4769 {
4770     { HCBT_SETFOCUS, hook },
4771     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4772     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4773     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4774     { WM_SETFOCUS, sent|wparam, 0 },
4775     { WM_CTLCOLORBTN, sent|defwinproc },
4776     { 0 }
4777 };
4778 static const struct message WmKillFocusButtonSeq[] =
4779 {
4780     { HCBT_SETFOCUS, hook },
4781     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4782     { WM_KILLFOCUS, sent|wparam, 0 },
4783     { WM_CTLCOLORBTN, sent|defwinproc },
4784     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4785     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4786     { 0 }
4787 };
4788 static const struct message WmSetFocusStaticSeq[] =
4789 {
4790     { HCBT_SETFOCUS, hook },
4791     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4792     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4793     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4794     { WM_SETFOCUS, sent|wparam, 0 },
4795     { WM_CTLCOLORSTATIC, sent|defwinproc },
4796     { 0 }
4797 };
4798 static const struct message WmKillFocusStaticSeq[] =
4799 {
4800     { HCBT_SETFOCUS, hook },
4801     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4802     { WM_KILLFOCUS, sent|wparam, 0 },
4803     { WM_CTLCOLORSTATIC, sent|defwinproc },
4804     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4805     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4806     { 0 }
4807 };
4808 static const struct message WmLButtonDownSeq[] =
4809 {
4810     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4811     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4812     { HCBT_SETFOCUS, hook },
4813     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4814     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4815     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4816     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4817     { WM_CTLCOLORBTN, sent|defwinproc },
4818     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4819     { WM_CTLCOLORBTN, sent|defwinproc },
4820     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4821     { 0 }
4822 };
4823 static const struct message WmLButtonUpSeq[] =
4824 {
4825     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4826     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4827     { WM_CTLCOLORBTN, sent|defwinproc },
4828     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4829     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4830     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4831     { 0 }
4832 };
4833 static const struct message WmSetFontButtonSeq[] =
4834 {
4835     { WM_SETFONT, sent },
4836     { WM_PAINT, sent },
4837     { WM_ERASEBKGND, sent|defwinproc|optional },
4838     { WM_CTLCOLORBTN, sent|defwinproc },
4839     { 0 }
4840 };
4841
4842 static WNDPROC old_button_proc;
4843
4844 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4845 {
4846     static long defwndproc_counter = 0;
4847     LRESULT ret;
4848     struct message msg;
4849
4850     trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4851
4852     /* explicitly ignore WM_GETICON message */
4853     if (message == WM_GETICON) return 0;
4854
4855     msg.message = message;
4856     msg.flags = sent|wparam|lparam;
4857     if (defwndproc_counter) msg.flags |= defwinproc;
4858     msg.wParam = wParam;
4859     msg.lParam = lParam;
4860     add_message(&msg);
4861
4862     if (message == BM_SETSTATE)
4863         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4864
4865     defwndproc_counter++;
4866     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4867     defwndproc_counter--;
4868
4869     return ret;
4870 }
4871
4872 static void subclass_button(void)
4873 {
4874     WNDCLASSA cls;
4875
4876     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4877
4878     old_button_proc = cls.lpfnWndProc;
4879
4880     cls.hInstance = GetModuleHandle(0);
4881     cls.lpfnWndProc = button_hook_proc;
4882     cls.lpszClassName = "my_button_class";
4883     UnregisterClass(cls.lpszClassName, cls.hInstance);
4884     if (!RegisterClassA(&cls)) assert(0);
4885 }
4886
4887 static void test_button_messages(void)
4888 {
4889     static const struct
4890     {
4891         DWORD style;
4892         DWORD dlg_code;
4893         const struct message *setfocus;
4894         const struct message *killfocus;
4895     } button[] = {
4896         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4897           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4898         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4899           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4900         { BS_CHECKBOX, DLGC_BUTTON,
4901           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4902         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4903           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4904         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4905           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4906         { BS_3STATE, DLGC_BUTTON,
4907           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4908         { BS_AUTO3STATE, DLGC_BUTTON,
4909           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4910         { BS_GROUPBOX, DLGC_STATIC,
4911           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4912         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4913           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4914         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4915           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4916         { BS_OWNERDRAW, DLGC_BUTTON,
4917           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4918     };
4919     unsigned int i;
4920     HWND hwnd;
4921     DWORD dlg_code;
4922     HFONT zfont;
4923
4924     subclass_button();
4925
4926     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4927     {
4928         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4929                                0, 0, 50, 14, 0, 0, 0, NULL);
4930         ok(hwnd != 0, "Failed to create button window\n");
4931
4932         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4933         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4934
4935         ShowWindow(hwnd, SW_SHOW);
4936         UpdateWindow(hwnd);
4937         SetFocus(0);
4938         flush_sequence();
4939
4940         trace("button style %08x\n", button[i].style);
4941         SetFocus(hwnd);
4942         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4943
4944         SetFocus(0);
4945         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4946
4947         DestroyWindow(hwnd);
4948     }
4949
4950     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4951                            0, 0, 50, 14, 0, 0, 0, NULL);
4952     ok(hwnd != 0, "Failed to create button window\n");
4953
4954     SetFocus(0);
4955     flush_events();
4956     flush_sequence();
4957
4958     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4959     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4960
4961     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4962     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4963
4964     flush_sequence();
4965     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4966     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4967     UpdateWindow(hwnd);
4968     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4969
4970     DestroyWindow(hwnd);
4971 }
4972
4973 /****************** static message test *************************/
4974 static const struct message WmSetFontStaticSeq[] =
4975 {
4976     { WM_SETFONT, sent },
4977     { WM_PAINT, sent|defwinproc },
4978     { WM_ERASEBKGND, sent|defwinproc|optional },
4979     { WM_CTLCOLORSTATIC, sent|defwinproc },
4980     { 0 }
4981 };
4982
4983 static WNDPROC old_static_proc;
4984
4985 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4986 {
4987     static long defwndproc_counter = 0;
4988     LRESULT ret;
4989     struct message msg;
4990
4991     trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4992
4993     /* explicitly ignore WM_GETICON message */
4994     if (message == WM_GETICON) return 0;
4995
4996     msg.message = message;
4997     msg.flags = sent|wparam|lparam;
4998     if (defwndproc_counter) msg.flags |= defwinproc;
4999     msg.wParam = wParam;
5000     msg.lParam = lParam;
5001     add_message(&msg);
5002
5003     defwndproc_counter++;
5004     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5005     defwndproc_counter--;
5006
5007     return ret;
5008 }
5009
5010 static void subclass_static(void)
5011 {
5012     WNDCLASSA cls;
5013
5014     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5015
5016     old_static_proc = cls.lpfnWndProc;
5017
5018     cls.hInstance = GetModuleHandle(0);
5019     cls.lpfnWndProc = static_hook_proc;
5020     cls.lpszClassName = "my_static_class";
5021     UnregisterClass(cls.lpszClassName, cls.hInstance);
5022     if (!RegisterClassA(&cls)) assert(0);
5023 }
5024
5025 static void test_static_messages(void)
5026 {
5027     /* FIXME: make as comprehensive as the button message test */
5028     static const struct
5029     {
5030         DWORD style;
5031         DWORD dlg_code;
5032         const struct message *setfont;
5033     } static_ctrl[] = {
5034         { SS_LEFT, DLGC_STATIC,
5035           WmSetFontStaticSeq }
5036     };
5037     unsigned int i;
5038     HWND hwnd;
5039     DWORD dlg_code;
5040
5041     subclass_static();
5042
5043     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5044     {
5045         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5046                                0, 0, 50, 14, 0, 0, 0, NULL);
5047         ok(hwnd != 0, "Failed to create static window\n");
5048
5049         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5050         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5051
5052         ShowWindow(hwnd, SW_SHOW);
5053         UpdateWindow(hwnd);
5054         SetFocus(0);
5055         flush_sequence();
5056
5057         trace("static style %08x\n", static_ctrl[i].style);
5058         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5059         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5060
5061         DestroyWindow(hwnd);
5062     }
5063 }
5064
5065 /****************** ComboBox message test *************************/
5066 #define ID_COMBOBOX 0x000f
5067
5068 static const struct message WmKeyDownComboSeq[] =
5069 {
5070     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5071     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5072     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5073     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5074     { WM_CTLCOLOREDIT, sent|parent },
5075     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5076     { 0 }
5077 };
5078
5079 static WNDPROC old_combobox_proc;
5080
5081 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5082 {
5083     static long defwndproc_counter = 0;
5084     LRESULT ret;
5085     struct message msg;
5086
5087     /* do not log painting messages */
5088     if (message != WM_PAINT &&
5089         message != WM_NCPAINT &&
5090         message != WM_SYNCPAINT &&
5091         message != WM_ERASEBKGND &&
5092         message != WM_NCHITTEST &&
5093         message != WM_GETTEXT &&
5094         message != WM_GETICON &&
5095         message != WM_DEVICECHANGE)
5096     {
5097         trace("combo: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5098
5099         msg.message = message;
5100         msg.flags = sent|wparam|lparam;
5101         if (defwndproc_counter) msg.flags |= defwinproc;
5102         msg.wParam = wParam;
5103         msg.lParam = lParam;
5104         add_message(&msg);
5105     }
5106
5107     defwndproc_counter++;
5108     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5109     defwndproc_counter--;
5110
5111     return ret;
5112 }
5113
5114 static void subclass_combobox(void)
5115 {
5116     WNDCLASSA cls;
5117
5118     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5119
5120     old_combobox_proc = cls.lpfnWndProc;
5121
5122     cls.hInstance = GetModuleHandle(0);
5123     cls.lpfnWndProc = combobox_hook_proc;
5124     cls.lpszClassName = "my_combobox_class";
5125     UnregisterClass(cls.lpszClassName, cls.hInstance);
5126     if (!RegisterClassA(&cls)) assert(0);
5127 }
5128
5129 static void test_combobox_messages(void)
5130 {
5131     HWND parent, combo;
5132     LRESULT ret;
5133
5134     subclass_combobox();
5135
5136     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5137                              100, 100, 200, 200, 0, 0, 0, NULL);
5138     ok(parent != 0, "Failed to create parent window\n");
5139     flush_sequence();
5140
5141     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5142                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5143     ok(combo != 0, "Failed to create combobox window\n");
5144
5145     UpdateWindow(combo);
5146
5147     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5148     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5149
5150     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5151     ok(ret == 0, "expected 0, got %ld\n", ret);
5152     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5153     ok(ret == 1, "expected 1, got %ld\n", ret);
5154     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5155     ok(ret == 2, "expected 2, got %ld\n", ret);
5156
5157     SendMessage(combo, CB_SETCURSEL, 0, 0);
5158     SetFocus(combo);
5159     flush_sequence();
5160
5161     log_all_parent_messages++;
5162     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5163     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5164     log_all_parent_messages--;
5165     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5166
5167     DestroyWindow(combo);
5168     DestroyWindow(parent);
5169 }
5170
5171 /****************** WM_IME_KEYDOWN message test *******************/
5172
5173 static const struct message WmImeKeydownMsgSeq_0[] =
5174 {
5175     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5176     { WM_CHAR, wparam, 'A' },
5177     { 0 }
5178 };
5179
5180 static const struct message WmImeKeydownMsgSeq_1[] =
5181 {
5182     { WM_KEYDOWN, wparam, VK_RETURN },
5183     { WM_CHAR,    wparam, VK_RETURN },
5184     { 0 }
5185 };
5186
5187 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5188 {
5189     struct message msg;
5190
5191     trace("wmime_keydown_procA: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5192
5193     msg.message = message;
5194     msg.flags = wparam|lparam;
5195     msg.wParam = wParam;
5196     msg.lParam = lParam;
5197     add_message(&msg);
5198
5199     return DefWindowProcA(hwnd, message, wParam, lParam);
5200 }
5201
5202 static void register_wmime_keydown_class(void)
5203 {
5204     WNDCLASSA cls;
5205
5206     ZeroMemory(&cls, sizeof(WNDCLASSA));
5207     cls.lpfnWndProc = wmime_keydown_procA;
5208     cls.hInstance = GetModuleHandleA(0);
5209     cls.lpszClassName = "wmime_keydown_class";
5210     if (!RegisterClassA(&cls)) assert(0);
5211 }
5212
5213 void test_wmime_keydown_message(void)
5214 {
5215     HWND hwnd;
5216     MSG msg;
5217
5218     trace("Message sequences by WM_IME_KEYDOWN\n");
5219
5220     register_wmime_keydown_class();
5221     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5222                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5223                            NULL, NULL, 0);
5224     flush_events();
5225     flush_sequence();
5226
5227     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5228     SendMessage(hwnd, WM_CHAR, 'A', 1);
5229     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5230
5231     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5232     {
5233         TranslateMessage(&msg);
5234         DispatchMessage(&msg);
5235     }
5236     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5237
5238     DestroyWindow(hwnd);
5239 }
5240
5241 /************* painting message test ********************/
5242
5243 void dump_region(HRGN hrgn)
5244 {
5245     DWORD i, size;
5246     RGNDATA *data = NULL;
5247     RECT *rect;
5248
5249     if (!hrgn)
5250     {
5251         printf( "null region\n" );
5252         return;
5253     }
5254     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5255     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5256     GetRegionData( hrgn, size, data );
5257     printf("%d rects:", data->rdh.nCount );
5258     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5259         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5260     printf("\n");
5261     HeapFree( GetProcessHeap(), 0, data );
5262 }
5263
5264 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5265 {
5266     INT ret;
5267     RECT r1, r2;
5268     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5269     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5270
5271     ret = GetUpdateRgn( hwnd, update, FALSE );
5272     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5273     if (ret == NULLREGION)
5274     {
5275         ok( !hrgn, "Update region shouldn't be empty\n" );
5276     }
5277     else
5278     {
5279         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5280         {
5281             ok( 0, "Regions are different\n" );
5282             if (winetest_debug > 0)
5283             {
5284                 printf( "Update region: " );
5285                 dump_region( update );
5286                 printf( "Wanted region: " );
5287                 dump_region( hrgn );
5288             }
5289         }
5290     }
5291     GetRgnBox( update, &r1 );
5292     GetUpdateRect( hwnd, &r2, FALSE );
5293     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5294         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5295         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5296
5297     DeleteObject( tmp );
5298     DeleteObject( update );
5299 }
5300
5301 static const struct message WmInvalidateRgn[] = {
5302     { WM_NCPAINT, sent },
5303     { WM_GETTEXT, sent|defwinproc|optional },
5304     { 0 }
5305 };
5306
5307 static const struct message WmGetUpdateRect[] = {
5308     { WM_NCPAINT, sent },
5309     { WM_GETTEXT, sent|defwinproc|optional },
5310     { WM_PAINT, sent },
5311     { 0 }
5312 };
5313
5314 static const struct message WmInvalidateFull[] = {
5315     { WM_NCPAINT, sent|wparam, 1 },
5316     { WM_GETTEXT, sent|defwinproc|optional },
5317     { 0 }
5318 };
5319
5320 static const struct message WmInvalidateErase[] = {
5321     { WM_NCPAINT, sent|wparam, 1 },
5322     { WM_GETTEXT, sent|defwinproc|optional },
5323     { WM_ERASEBKGND, sent },
5324     { 0 }
5325 };
5326
5327 static const struct message WmInvalidatePaint[] = {
5328     { WM_PAINT, sent },
5329     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5330     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5331     { 0 }
5332 };
5333
5334 static const struct message WmInvalidateErasePaint[] = {
5335     { WM_PAINT, sent },
5336     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5337     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5338     { WM_ERASEBKGND, sent|beginpaint },
5339     { 0 }
5340 };
5341
5342 static const struct message WmInvalidateErasePaint2[] = {
5343     { WM_PAINT, sent },
5344     { WM_NCPAINT, sent|beginpaint },
5345     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5346     { WM_ERASEBKGND, sent|beginpaint },
5347     { 0 }
5348 };
5349
5350 static const struct message WmErase[] = {
5351     { WM_ERASEBKGND, sent },
5352     { 0 }
5353 };
5354
5355 static const struct message WmPaint[] = {
5356     { WM_PAINT, sent },
5357     { 0 }
5358 };
5359
5360 static const struct message WmParentOnlyPaint[] = {
5361     { WM_PAINT, sent|parent },
5362     { 0 }
5363 };
5364
5365 static const struct message WmInvalidateParent[] = {
5366     { WM_NCPAINT, sent|parent },
5367     { WM_GETTEXT, sent|defwinproc|parent|optional },
5368     { WM_ERASEBKGND, sent|parent },
5369     { 0 }
5370 };
5371
5372 static const struct message WmInvalidateParentChild[] = {
5373     { WM_NCPAINT, sent|parent },
5374     { WM_GETTEXT, sent|defwinproc|parent|optional },
5375     { WM_ERASEBKGND, sent|parent },
5376     { WM_NCPAINT, sent },
5377     { WM_GETTEXT, sent|defwinproc|optional },
5378     { WM_ERASEBKGND, sent },
5379     { 0 }
5380 };
5381
5382 static const struct message WmInvalidateParentChild2[] = {
5383     { WM_ERASEBKGND, sent|parent },
5384     { WM_NCPAINT, sent },
5385     { WM_GETTEXT, sent|defwinproc|optional },
5386     { WM_ERASEBKGND, sent },
5387     { 0 }
5388 };
5389
5390 static const struct message WmParentPaint[] = {
5391     { WM_PAINT, sent|parent },
5392     { WM_PAINT, sent },
5393     { 0 }
5394 };
5395
5396 static const struct message WmParentPaintNc[] = {
5397     { WM_PAINT, sent|parent },
5398     { WM_PAINT, sent },
5399     { WM_NCPAINT, sent|beginpaint },
5400     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5401     { WM_ERASEBKGND, sent|beginpaint },
5402     { 0 }
5403 };
5404
5405 static const struct message WmChildPaintNc[] = {
5406     { WM_PAINT, sent },
5407     { WM_NCPAINT, sent|beginpaint },
5408     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5409     { WM_ERASEBKGND, sent|beginpaint },
5410     { 0 }
5411 };
5412
5413 static const struct message WmParentErasePaint[] = {
5414     { WM_PAINT, sent|parent },
5415     { WM_NCPAINT, sent|parent|beginpaint },
5416     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5417     { WM_ERASEBKGND, sent|parent|beginpaint },
5418     { WM_PAINT, sent },
5419     { WM_NCPAINT, sent|beginpaint },
5420     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5421     { WM_ERASEBKGND, sent|beginpaint },
5422     { 0 }
5423 };
5424
5425 static const struct message WmParentOnlyNcPaint[] = {
5426     { WM_PAINT, sent|parent },
5427     { WM_NCPAINT, sent|parent|beginpaint },
5428     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5429     { 0 }
5430 };
5431
5432 static const struct message WmSetParentStyle[] = {
5433     { WM_STYLECHANGING, sent|parent },
5434     { WM_STYLECHANGED, sent|parent },
5435     { 0 }
5436 };
5437
5438 static void test_paint_messages(void)
5439 {
5440     BOOL ret;
5441     RECT rect;
5442     POINT pt;
5443     MSG msg;
5444     HWND hparent, hchild;
5445     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5446     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5447     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5448                                 100, 100, 200, 200, 0, 0, 0, NULL);
5449     ok (hwnd != 0, "Failed to create overlapped window\n");
5450
5451     ShowWindow( hwnd, SW_SHOW );
5452     UpdateWindow( hwnd );
5453     flush_events();
5454     flush_sequence();
5455
5456     check_update_rgn( hwnd, 0 );
5457     SetRectRgn( hrgn, 10, 10, 20, 20 );
5458     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5459     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5460     check_update_rgn( hwnd, hrgn );
5461     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5462     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5463     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5464     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5465     check_update_rgn( hwnd, hrgn );
5466     /* validate everything */
5467     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5468     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5469     check_update_rgn( hwnd, 0 );
5470
5471     /* test empty region */
5472     SetRectRgn( hrgn, 10, 10, 10, 15 );
5473     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5474     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5475     check_update_rgn( hwnd, 0 );
5476     /* test empty rect */
5477     SetRect( &rect, 10, 10, 10, 15 );
5478     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5479     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5480     check_update_rgn( hwnd, 0 );
5481
5482     /* flush pending messages */
5483     flush_events();
5484     flush_sequence();
5485
5486     GetClientRect( hwnd, &rect );
5487     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5488     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5489      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5490      */
5491     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5492     SetRectEmpty( &rect );
5493     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5494     check_update_rgn( hwnd, hrgn );
5495     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5496     flush_events();
5497     ok_sequence( WmPaint, "Paint", FALSE );
5498     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5499     check_update_rgn( hwnd, 0 );
5500
5501     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5502      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5503      */
5504     trace("testing ValidateRect(0, NULL)\n");
5505     SetRectEmpty( &rect );
5506     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5507     check_update_rgn( hwnd, hrgn );
5508     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5509     flush_events();
5510     ok_sequence( WmPaint, "Paint", FALSE );
5511     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5512     check_update_rgn( hwnd, 0 );
5513
5514     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5515     SetLastError(0xdeadbeef);
5516     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5517     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5518        "wrong error code %d\n", GetLastError());
5519     check_update_rgn( hwnd, 0 );
5520     flush_events();
5521     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5522
5523     trace("testing ValidateRgn(0, NULL)\n");
5524     SetLastError(0xdeadbeef);
5525     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5526     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5527     check_update_rgn( hwnd, 0 );
5528     flush_events();
5529     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5530
5531     /* now with frame */
5532     SetRectRgn( hrgn, -5, -5, 20, 20 );
5533
5534     /* flush pending messages */
5535     flush_events();
5536     flush_sequence();
5537     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5538     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5539
5540     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5541     check_update_rgn( hwnd, hrgn );
5542
5543     flush_sequence();
5544     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5545     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5546
5547     flush_sequence();
5548     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5549     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5550
5551     GetClientRect( hwnd, &rect );
5552     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5553     check_update_rgn( hwnd, hrgn );
5554
5555     flush_sequence();
5556     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5557     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5558
5559     flush_sequence();
5560     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5561     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5562     check_update_rgn( hwnd, 0 );
5563
5564     flush_sequence();
5565     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5566     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5567     check_update_rgn( hwnd, 0 );
5568
5569     flush_sequence();
5570     SetRectRgn( hrgn, 0, 0, 100, 100 );
5571     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5572     SetRectRgn( hrgn, 0, 0, 50, 100 );
5573     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5574     SetRectRgn( hrgn, 50, 0, 100, 100 );
5575     check_update_rgn( hwnd, hrgn );
5576     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5577     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5578     check_update_rgn( hwnd, 0 );
5579
5580     flush_sequence();
5581     SetRectRgn( hrgn, 0, 0, 100, 100 );
5582     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5583     SetRectRgn( hrgn, 0, 0, 100, 50 );
5584     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5585     ok_sequence( WmErase, "Erase", FALSE );
5586     SetRectRgn( hrgn, 0, 50, 100, 100 );
5587     check_update_rgn( hwnd, hrgn );
5588
5589     flush_sequence();
5590     SetRectRgn( hrgn, 0, 0, 100, 100 );
5591     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5592     SetRectRgn( hrgn, 0, 0, 50, 50 );
5593     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5594     ok_sequence( WmPaint, "Paint", FALSE );
5595
5596     flush_sequence();
5597     SetRectRgn( hrgn, -4, -4, -2, -2 );
5598     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5599     SetRectRgn( hrgn, -200, -200, -198, -198 );
5600     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5601     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5602
5603     flush_sequence();
5604     SetRectRgn( hrgn, -4, -4, -2, -2 );
5605     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5606     SetRectRgn( hrgn, -4, -4, -3, -3 );
5607     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5608     SetRectRgn( hrgn, 0, 0, 1, 1 );
5609     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5610     ok_sequence( WmPaint, "Paint", FALSE );
5611
5612     flush_sequence();
5613     SetRectRgn( hrgn, -4, -4, -1, -1 );
5614     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5615     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5616     /* make sure no WM_PAINT was generated */
5617     flush_events();
5618     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5619
5620     flush_sequence();
5621     SetRectRgn( hrgn, -4, -4, -1, -1 );
5622     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5623     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5624     {
5625         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5626         {
5627             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5628             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5629             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5630             ret = GetUpdateRect( hwnd, &rect, FALSE );
5631             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5632             /* this will send WM_NCPAINT and validate the non client area */
5633             ret = GetUpdateRect( hwnd, &rect, TRUE );
5634             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5635         }
5636         DispatchMessage( &msg );
5637     }
5638     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5639
5640     DestroyWindow( hwnd );
5641
5642     /* now test with a child window */
5643
5644     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5645                               100, 100, 200, 200, 0, 0, 0, NULL);
5646     ok (hparent != 0, "Failed to create parent window\n");
5647
5648     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5649                            10, 10, 100, 100, hparent, 0, 0, NULL);
5650     ok (hchild != 0, "Failed to create child window\n");
5651
5652     ShowWindow( hparent, SW_SHOW );
5653     UpdateWindow( hparent );
5654     UpdateWindow( hchild );
5655     flush_events();
5656     flush_sequence();
5657     log_all_parent_messages++;
5658
5659     SetRect( &rect, 0, 0, 50, 50 );
5660     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5661     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5662     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5663
5664     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5665     pt.x = pt.y = 0;
5666     MapWindowPoints( hchild, hparent, &pt, 1 );
5667     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5668     check_update_rgn( hchild, hrgn );
5669     SetRectRgn( hrgn, 0, 0, 50, 50 );
5670     check_update_rgn( hparent, hrgn );
5671     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5672     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5673     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5674     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5675
5676     flush_events();
5677     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5678
5679     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5680     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5681     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5682     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5683     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5684
5685     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5686     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5687     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5688
5689     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5690     flush_sequence();
5691     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5692     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5693     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5694
5695     /* flush all paint messages */
5696     flush_events();
5697     flush_sequence();
5698
5699     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5700     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5701     SetRectRgn( hrgn, 0, 0, 50, 50 );
5702     check_update_rgn( hparent, hrgn );
5703     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5704     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5705     SetRectRgn( hrgn, 0, 0, 50, 50 );
5706     check_update_rgn( hparent, hrgn );
5707
5708     /* flush all paint messages */
5709     flush_events();
5710     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5711     flush_sequence();
5712
5713     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5714     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5715     SetRectRgn( hrgn, 0, 0, 50, 50 );
5716     check_update_rgn( hparent, hrgn );
5717     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5718     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5719     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5720     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5721     check_update_rgn( hparent, hrgn );
5722     /* flush all paint messages */
5723     flush_events();
5724     flush_sequence();
5725
5726     /* same as above but parent gets completely validated */
5727     SetRect( &rect, 20, 20, 30, 30 );
5728     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5729     SetRectRgn( hrgn, 20, 20, 30, 30 );
5730     check_update_rgn( hparent, hrgn );
5731     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5732     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5733     check_update_rgn( hparent, 0 );  /* no update region */
5734     flush_events();
5735     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5736
5737     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5738     flush_sequence();
5739     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5740     SetRectRgn( hrgn, 20, 20, 30, 30 );
5741     check_update_rgn( hparent, hrgn );
5742     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5743     SetRectRgn( hrgn, 20, 20, 30, 30 );
5744     check_update_rgn( hparent, hrgn );
5745
5746     /* same as above but normal WM_PAINT doesn't validate parent */
5747     flush_sequence();
5748     SetRect( &rect, 20, 20, 30, 30 );
5749     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5750     SetRectRgn( hrgn, 20, 20, 30, 30 );
5751     check_update_rgn( hparent, hrgn );
5752     /* no WM_PAINT in child while parent still pending */
5753     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5754     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5755     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5756     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5757
5758     flush_sequence();
5759     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5760     /* no WM_PAINT in child while parent still pending */
5761     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5762     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5763     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5764     /* now that parent is valid child should get WM_PAINT */
5765     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5766     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5767     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5768     ok_sequence( WmEmptySeq, "No other message", FALSE );
5769
5770     /* same thing with WS_CLIPCHILDREN in parent */
5771     flush_sequence();
5772     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5773     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5774     /* changing style invalidates non client area, but we need to invalidate something else to see it */
5775     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5776     ok_sequence( WmEmptySeq, "No message", FALSE );
5777     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5778     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5779
5780     flush_sequence();
5781     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5782     SetRectRgn( hrgn, 20, 20, 30, 30 );
5783     check_update_rgn( hparent, hrgn );
5784     /* no WM_PAINT in child while parent still pending */
5785     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5786     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5787     /* WM_PAINT in parent first */
5788     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5789     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5790
5791     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5792     flush_sequence();
5793     SetRect( &rect, 0, 0, 30, 30 );
5794     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5795     SetRectRgn( hrgn, 0, 0, 30, 30 );
5796     check_update_rgn( hparent, hrgn );
5797     flush_events();
5798     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5799
5800     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5801     flush_sequence();
5802     SetRect( &rect, -10, 0, 30, 30 );
5803     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5804     SetRect( &rect, 0, 0, 20, 20 );
5805     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5806     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5807     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5808
5809     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5810     flush_sequence();
5811     SetRect( &rect, -10, 0, 30, 30 );
5812     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5813     SetRect( &rect, 0, 0, 100, 100 );
5814     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5815     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5816     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5817     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5818     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5819
5820     /* test RDW_INTERNALPAINT behavior */
5821
5822     flush_sequence();
5823     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5824     flush_events();
5825     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5826
5827     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5828     flush_events();
5829     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5830
5831     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5832     flush_events();
5833     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5834
5835     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5836     UpdateWindow( hparent );
5837     flush_events();
5838     flush_sequence();
5839     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5840     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5841     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5842                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5843     flush_events();
5844     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5845
5846     UpdateWindow( hparent );
5847     flush_events();
5848     flush_sequence();
5849     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5850     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5851     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5852                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5853     flush_events();
5854     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5855
5856     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5857     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5858     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5859     flush_events();
5860     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5861
5862     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5863     UpdateWindow( hparent );
5864     flush_events();
5865     flush_sequence();
5866     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5867     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5868     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5869                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5870     flush_events();
5871     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5872
5873     UpdateWindow( hparent );
5874     flush_events();
5875     flush_sequence();
5876     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5877     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5878     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5879                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5880     flush_events();
5881     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5882
5883     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
5884     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
5885
5886     UpdateWindow( hparent );
5887     flush_events();
5888     flush_sequence();
5889     trace("testing SetWindowPos(-10000, -10000) on child\n");
5890     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
5891     check_update_rgn( hchild, 0 );
5892     flush_events();
5893
5894 #if 0 /* this one doesn't pass under Wine yet */
5895     UpdateWindow( hparent );
5896     flush_events();
5897     flush_sequence();
5898     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
5899     ShowWindow( hchild, SW_MINIMIZE );
5900     check_update_rgn( hchild, 0 );
5901     flush_events();
5902 #endif
5903
5904     UpdateWindow( hparent );
5905     flush_events();
5906     flush_sequence();
5907     trace("testing SetWindowPos(-10000, -10000) on parent\n");
5908     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
5909     check_update_rgn( hparent, 0 );
5910     flush_events();
5911
5912     log_all_parent_messages--;
5913     DestroyWindow( hparent );
5914     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5915
5916     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
5917
5918     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
5919                               100, 100, 200, 200, 0, 0, 0, NULL);
5920     ok (hparent != 0, "Failed to create parent window\n");
5921
5922     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
5923                            10, 10, 100, 100, hparent, 0, 0, NULL);
5924     ok (hchild != 0, "Failed to create child window\n");
5925
5926     ShowWindow( hparent, SW_SHOW );
5927     UpdateWindow( hparent );
5928     UpdateWindow( hchild );
5929     flush_events();
5930     flush_sequence();
5931
5932     /* moving child outside of parent boundaries changes update region */
5933     SetRect( &rect, 0, 0, 40, 40 );
5934     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5935     SetRectRgn( hrgn, 0, 0, 40, 40 );
5936     check_update_rgn( hchild, hrgn );
5937     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
5938     SetRectRgn( hrgn, 10, 0, 40, 40 );
5939     check_update_rgn( hchild, hrgn );
5940     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
5941     SetRectRgn( hrgn, 10, 10, 40, 40 );
5942     check_update_rgn( hchild, hrgn );
5943
5944     /* moving parent off-screen does too */
5945     SetRect( &rect, 0, 0, 100, 100 );
5946     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
5947     SetRectRgn( hrgn, 0, 0, 100, 100 );
5948     check_update_rgn( hparent, hrgn );
5949     SetRectRgn( hrgn, 10, 10, 40, 40 );
5950     check_update_rgn( hchild, hrgn );
5951     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
5952     SetRectRgn( hrgn, 20, 20, 100, 100 );
5953     check_update_rgn( hparent, hrgn );
5954     SetRectRgn( hrgn, 30, 30, 40, 40 );
5955     check_update_rgn( hchild, hrgn );
5956
5957     /* invalidated region is cropped by the parent rects */
5958     SetRect( &rect, 0, 0, 50, 50 );
5959     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5960     SetRectRgn( hrgn, 30, 30, 50, 50 );
5961     check_update_rgn( hchild, hrgn );
5962
5963     DestroyWindow( hparent );
5964     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5965     flush_sequence();
5966
5967     DeleteObject( hrgn );
5968     DeleteObject( hrgn2 );
5969 }
5970
5971 struct wnd_event
5972 {
5973     HWND hwnd;
5974     HANDLE event;
5975 };
5976
5977 static DWORD WINAPI thread_proc(void *param)
5978 {
5979     MSG msg;
5980     struct wnd_event *wnd_event = (struct wnd_event *)param;
5981
5982     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5983                                       100, 100, 200, 200, 0, 0, 0, NULL);
5984     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5985
5986     SetEvent(wnd_event->event);
5987
5988     while (GetMessage(&msg, 0, 0, 0))
5989     {
5990         TranslateMessage(&msg);
5991         DispatchMessage(&msg);
5992     }
5993
5994     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5995
5996     return 0;
5997 }
5998
5999 static void test_interthread_messages(void)
6000 {
6001     HANDLE hThread;
6002     DWORD tid;
6003     WNDPROC proc;
6004     MSG msg;
6005     char buf[256];
6006     int len, expected_len;
6007     struct wnd_event wnd_event;
6008     BOOL ret;
6009
6010     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6011     if (!wnd_event.event)
6012     {
6013         trace("skipping interthread message test under win9x\n");
6014         return;
6015     }
6016
6017     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6018     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6019
6020     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6021
6022     CloseHandle(wnd_event.event);
6023
6024     SetLastError(0xdeadbeef);
6025     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6026     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6027        "wrong error code %d\n", GetLastError());
6028
6029     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6030     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6031
6032     expected_len = lstrlenA("window caption text");
6033     memset(buf, 0, sizeof(buf));
6034     SetLastError(0xdeadbeef);
6035     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6036     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6037     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6038
6039     msg.hwnd = wnd_event.hwnd;
6040     msg.message = WM_GETTEXT;
6041     msg.wParam = sizeof(buf);
6042     msg.lParam = (LPARAM)buf;
6043     memset(buf, 0, sizeof(buf));
6044     SetLastError(0xdeadbeef);
6045     len = DispatchMessageA(&msg);
6046     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
6047        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6048
6049     /* the following test causes an exception in user.exe under win9x */
6050     msg.hwnd = wnd_event.hwnd;
6051     msg.message = WM_TIMER;
6052     msg.wParam = 0;
6053     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6054     SetLastError(0xdeadbeef);
6055     len = DispatchMessageA(&msg);
6056     ok(!len && GetLastError() == 0xdeadbeef,
6057        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6058
6059     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6060     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6061
6062     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6063     CloseHandle(hThread);
6064
6065     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6066 }
6067
6068
6069 static const struct message WmVkN[] = {
6070     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6071     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6072     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6073     { WM_CHAR, wparam|lparam, 'n', 1 },
6074     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6075     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6076     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6077     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6078     { 0 }
6079 };
6080 static const struct message WmShiftVkN[] = {
6081     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6082     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6083     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6084     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6085     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6086     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6087     { WM_CHAR, wparam|lparam, 'N', 1 },
6088     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6089     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6090     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6091     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6092     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6093     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6094     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6095     { 0 }
6096 };
6097 static const struct message WmCtrlVkN[] = {
6098     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6099     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6100     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6101     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6102     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6103     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6104     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6105     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6106     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6107     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6108     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6109     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6110     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6111     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6112     { 0 }
6113 };
6114 static const struct message WmCtrlVkN_2[] = {
6115     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6116     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6117     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6118     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6119     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6120     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6121     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6122     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6123     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6124     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6125     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6126     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6127     { 0 }
6128 };
6129 static const struct message WmAltVkN[] = {
6130     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6131     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6132     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6133     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6134     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6135     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6136     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6137     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6138     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6139     { HCBT_SYSCOMMAND, hook },
6140     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6141     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6142     { 0x00AE, sent|defwinproc|optional }, /* XP */
6143     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6144     { WM_INITMENU, sent|defwinproc },
6145     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6146     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6147     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6148     { WM_CAPTURECHANGED, sent|defwinproc },
6149     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6150     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6151     { WM_EXITMENULOOP, sent|defwinproc },
6152     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6153     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6154     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6155     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6156     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6157     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6158     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6159     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6160     { 0 }
6161 };
6162 static const struct message WmAltVkN_2[] = {
6163     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6164     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6165     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6166     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6167     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6168     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6169     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6170     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6171     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6172     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6173     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6174     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6175     { 0 }
6176 };
6177 static const struct message WmCtrlAltVkN[] = {
6178     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6179     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6180     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6181     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6182     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6183     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6184     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6185     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6186     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6187     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6188     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6189     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6190     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6191     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6192     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6193     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6194     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6195     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6196     { 0 }
6197 };
6198 static const struct message WmCtrlShiftVkN[] = {
6199     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6200     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6201     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6202     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6203     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6204     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6205     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6206     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6207     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6208     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6209     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6210     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6211     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6212     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6213     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6214     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6215     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6216     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6217     { 0 }
6218 };
6219 static const struct message WmCtrlAltShiftVkN[] = {
6220     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6221     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6222     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6223     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6224     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6225     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6226     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6227     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6228     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6229     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6230     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6231     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6232     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6233     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6234     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6235     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6236     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6237     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6238     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6239     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6240     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6241     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6242     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6243     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6244     { 0 }
6245 };
6246 static const struct message WmAltPressRelease[] = {
6247     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6248     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6249     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6250     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6251     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6252     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6253     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6254     { HCBT_SYSCOMMAND, hook },
6255     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6256     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6257     { WM_INITMENU, sent|defwinproc },
6258     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6259     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6260     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6261
6262     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6263
6264     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6265     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6266     { WM_CAPTURECHANGED, sent|defwinproc },
6267     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6268     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6269     { WM_EXITMENULOOP, sent|defwinproc },
6270     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6271     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6272     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6273     { 0 }
6274 };
6275 static const struct message WmAltMouseButton[] = {
6276     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6277     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6278     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6279     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6280     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6281     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6282     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6283     { WM_LBUTTONUP, wparam, 0, 0 },
6284     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6285     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6286     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6287     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6288     { 0 }
6289 };
6290 static const struct message WmF1Seq[] = {
6291     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6292     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6293     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6294     { WM_KEYF1, wparam|lparam, 0, 0 },
6295     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6296     { WM_HELP, sent|defwinproc },
6297     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6298     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6299     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6300     { 0 }
6301 };
6302 static const struct message WmVkAppsSeq[] = {
6303     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6304     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6305     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6306     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6307     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6308     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6309     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6310     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6311     { 0 }
6312 };
6313
6314 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6315 {
6316     MSG msg;
6317
6318     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6319     {
6320         struct message log_msg;
6321
6322         trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
6323
6324         /* ignore some unwanted messages */
6325         if (msg.message == WM_MOUSEMOVE ||
6326             msg.message == WM_GETICON ||
6327             msg.message == WM_DEVICECHANGE)
6328             continue;
6329
6330         log_msg.message = msg.message;
6331         log_msg.flags = wparam|lparam;
6332         log_msg.wParam = msg.wParam;
6333         log_msg.lParam = msg.lParam;
6334         add_message(&log_msg);
6335
6336         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6337         {
6338             TranslateMessage(&msg);
6339             DispatchMessage(&msg);
6340         }
6341     }
6342 }
6343
6344 static void test_accelerators(void)
6345 {
6346     RECT rc;
6347     SHORT state;
6348     HACCEL hAccel;
6349     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6350                                 100, 100, 200, 200, 0, 0, 0, NULL);
6351     BOOL ret;
6352
6353     assert(hwnd != 0);
6354     UpdateWindow(hwnd);
6355     flush_events();
6356     flush_sequence();
6357
6358     SetFocus(hwnd);
6359     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6360
6361     state = GetKeyState(VK_SHIFT);
6362     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6363     state = GetKeyState(VK_CAPITAL);
6364     ok(state == 0, "wrong CapsLock state %04x\n", state);
6365
6366     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6367     assert(hAccel != 0);
6368
6369     pump_msg_loop(hwnd, 0);
6370     flush_sequence();
6371
6372     trace("testing VK_N press/release\n");
6373     flush_sequence();
6374     keybd_event('N', 0, 0, 0);
6375     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6376     pump_msg_loop(hwnd, hAccel);
6377     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6378
6379     trace("testing Shift+VK_N press/release\n");
6380     flush_sequence();
6381     keybd_event(VK_SHIFT, 0, 0, 0);
6382     keybd_event('N', 0, 0, 0);
6383     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6384     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6385     pump_msg_loop(hwnd, hAccel);
6386     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6387
6388     trace("testing Ctrl+VK_N press/release\n");
6389     flush_sequence();
6390     keybd_event(VK_CONTROL, 0, 0, 0);
6391     keybd_event('N', 0, 0, 0);
6392     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6393     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6394     pump_msg_loop(hwnd, hAccel);
6395     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6396
6397     trace("testing Alt+VK_N press/release\n");
6398     flush_sequence();
6399     keybd_event(VK_MENU, 0, 0, 0);
6400     keybd_event('N', 0, 0, 0);
6401     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6402     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6403     pump_msg_loop(hwnd, hAccel);
6404     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6405
6406     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6407     flush_sequence();
6408     keybd_event(VK_CONTROL, 0, 0, 0);
6409     keybd_event(VK_MENU, 0, 0, 0);
6410     keybd_event('N', 0, 0, 0);
6411     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6412     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6413     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6414     pump_msg_loop(hwnd, hAccel);
6415     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6416
6417     ret = DestroyAcceleratorTable(hAccel);
6418     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6419
6420     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6421     assert(hAccel != 0);
6422
6423     trace("testing VK_N press/release\n");
6424     flush_sequence();
6425     keybd_event('N', 0, 0, 0);
6426     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6427     pump_msg_loop(hwnd, hAccel);
6428     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6429
6430     trace("testing Shift+VK_N press/release\n");
6431     flush_sequence();
6432     keybd_event(VK_SHIFT, 0, 0, 0);
6433     keybd_event('N', 0, 0, 0);
6434     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6435     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6436     pump_msg_loop(hwnd, hAccel);
6437     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6438
6439     trace("testing Ctrl+VK_N press/release 2\n");
6440     flush_sequence();
6441     keybd_event(VK_CONTROL, 0, 0, 0);
6442     keybd_event('N', 0, 0, 0);
6443     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6444     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6445     pump_msg_loop(hwnd, hAccel);
6446     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6447
6448     trace("testing Alt+VK_N press/release 2\n");
6449     flush_sequence();
6450     keybd_event(VK_MENU, 0, 0, 0);
6451     keybd_event('N', 0, 0, 0);
6452     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6453     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6454     pump_msg_loop(hwnd, hAccel);
6455     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6456
6457     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6458     flush_sequence();
6459     keybd_event(VK_CONTROL, 0, 0, 0);
6460     keybd_event(VK_MENU, 0, 0, 0);
6461     keybd_event('N', 0, 0, 0);
6462     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6463     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6464     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6465     pump_msg_loop(hwnd, hAccel);
6466     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6467
6468     trace("testing Ctrl+Shift+VK_N press/release\n");
6469     flush_sequence();
6470     keybd_event(VK_CONTROL, 0, 0, 0);
6471     keybd_event(VK_SHIFT, 0, 0, 0);
6472     keybd_event('N', 0, 0, 0);
6473     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6474     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6475     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6476     pump_msg_loop(hwnd, hAccel);
6477     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6478
6479     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6480     flush_sequence();
6481     keybd_event(VK_CONTROL, 0, 0, 0);
6482     keybd_event(VK_MENU, 0, 0, 0);
6483     keybd_event(VK_SHIFT, 0, 0, 0);
6484     keybd_event('N', 0, 0, 0);
6485     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6486     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6487     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6488     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6489     pump_msg_loop(hwnd, hAccel);
6490     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6491
6492     ret = DestroyAcceleratorTable(hAccel);
6493     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6494
6495     trace("testing Alt press/release\n");
6496     flush_sequence();
6497     keybd_event(VK_MENU, 0, 0, 0);
6498     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6499     keybd_event(VK_MENU, 0, 0, 0);
6500     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6501     pump_msg_loop(hwnd, 0);
6502     /* this test doesn't pass in Wine for managed windows */
6503     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6504
6505     trace("testing Alt+MouseButton press/release\n");
6506     /* first, move mouse pointer inside of the window client area */
6507     GetClientRect(hwnd, &rc);
6508     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6509     rc.left += (rc.right - rc.left)/2;
6510     rc.top += (rc.bottom - rc.top)/2;
6511     SetCursorPos(rc.left, rc.top);
6512
6513     flush_events();
6514     flush_sequence();
6515     keybd_event(VK_MENU, 0, 0, 0);
6516     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6517     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6518     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6519     pump_msg_loop(hwnd, 0);
6520     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6521
6522     trace("testing VK_F1 press/release\n");
6523     keybd_event(VK_F1, 0, 0, 0);
6524     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6525     pump_msg_loop(hwnd, 0);
6526     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6527
6528     trace("testing VK_APPS press/release\n");
6529     keybd_event(VK_APPS, 0, 0, 0);
6530     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6531     pump_msg_loop(hwnd, 0);
6532     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6533
6534     DestroyWindow(hwnd);
6535 }
6536
6537 /************* window procedures ********************/
6538
6539 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6540                              WPARAM wParam, LPARAM lParam)
6541 {
6542     static long defwndproc_counter = 0;
6543     static long beginpaint_counter = 0;
6544     LRESULT ret;
6545     struct message msg;
6546
6547     trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6548
6549     /* explicitly ignore WM_GETICON message */
6550     if (message == WM_GETICON) return 0;
6551
6552     switch (message)
6553     {
6554         case WM_ENABLE:
6555         {
6556             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6557             ok((BOOL)wParam == !(style & WS_DISABLED),
6558                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6559             break;
6560         }
6561
6562         case WM_CAPTURECHANGED:
6563             if (test_DestroyWindow_flag)
6564             {
6565                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6566                 if (style & WS_CHILD)
6567                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6568                 else if (style & WS_POPUP)
6569                     lParam = WND_POPUP_ID;
6570                 else
6571                     lParam = WND_PARENT_ID;
6572             }
6573             break;
6574
6575         case WM_NCDESTROY:
6576         {
6577             HWND capture;
6578
6579             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6580             capture = GetCapture();
6581             if (capture)
6582             {
6583                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6584                 trace("current capture %p, releasing...\n", capture);
6585                 ReleaseCapture();
6586             }
6587         }
6588         /* fall through */
6589         case WM_DESTROY:
6590             if (pGetAncestor)
6591                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6592             if (test_DestroyWindow_flag)
6593             {
6594                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6595                 if (style & WS_CHILD)
6596                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6597                 else if (style & WS_POPUP)
6598                     lParam = WND_POPUP_ID;
6599                 else
6600                     lParam = WND_PARENT_ID;
6601             }
6602             break;
6603
6604         /* test_accelerators() depends on this */
6605         case WM_NCHITTEST:
6606             return HTCLIENT;
6607     
6608         /* ignore */
6609         case WM_MOUSEMOVE:
6610         case WM_SETCURSOR:
6611         case WM_DEVICECHANGE:
6612             return 0;
6613
6614         case WM_WINDOWPOSCHANGING:
6615         case WM_WINDOWPOSCHANGED:
6616         {
6617             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6618
6619             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6620             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6621                   winpos->hwnd, winpos->hwndInsertAfter,
6622                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6623             dump_winpos_flags(winpos->flags);
6624
6625             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6626              * in the high word for internal purposes
6627              */
6628             wParam = winpos->flags & 0xffff;
6629             /* We are not interested in the flags that don't match under XP and Win9x */
6630             wParam &= ~(SWP_NOZORDER);
6631             break;
6632         }
6633     }
6634
6635     msg.message = message;
6636     msg.flags = sent|wparam|lparam;
6637     if (defwndproc_counter) msg.flags |= defwinproc;
6638     if (beginpaint_counter) msg.flags |= beginpaint;
6639     msg.wParam = wParam;
6640     msg.lParam = lParam;
6641     add_message(&msg);
6642
6643     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6644     {
6645         HWND parent = GetParent(hwnd);
6646         RECT rc;
6647         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6648
6649         GetClientRect(parent, &rc);
6650         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6651         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6652               minmax->ptReserved.x, minmax->ptReserved.y,
6653               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6654               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6655               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6656               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6657
6658         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6659            minmax->ptMaxSize.x, rc.right);
6660         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6661            minmax->ptMaxSize.y, rc.bottom);
6662     }
6663
6664     if (message == WM_PAINT)
6665     {
6666         PAINTSTRUCT ps;
6667         beginpaint_counter++;
6668         BeginPaint( hwnd, &ps );
6669         beginpaint_counter--;
6670         EndPaint( hwnd, &ps );
6671         return 0;
6672     }
6673
6674     defwndproc_counter++;
6675     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6676                   : DefWindowProcA(hwnd, message, wParam, lParam);
6677     defwndproc_counter--;
6678
6679     return ret;
6680 }
6681
6682 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6683 {
6684     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6685 }
6686
6687 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6688 {
6689     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6690 }
6691
6692 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6693 {
6694     static long defwndproc_counter = 0;
6695     LRESULT ret;
6696     struct message msg;
6697
6698     trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6699
6700     /* explicitly ignore WM_GETICON message */
6701     if (message == WM_GETICON) return 0;
6702
6703     msg.message = message;
6704     msg.flags = sent|wparam|lparam;
6705     if (defwndproc_counter) msg.flags |= defwinproc;
6706     msg.wParam = wParam;
6707     msg.lParam = lParam;
6708     add_message(&msg);
6709
6710     if (message == WM_CREATE)
6711     {
6712         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6713         SetWindowLongA(hwnd, GWL_STYLE, style);
6714     }
6715
6716     defwndproc_counter++;
6717     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6718     defwndproc_counter--;
6719
6720     return ret;
6721 }
6722
6723 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6724 {
6725     static long defwndproc_counter = 0;
6726     static long beginpaint_counter = 0;
6727     LRESULT ret;
6728     struct message msg;
6729     LPARAM logged_lParam;
6730
6731     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6732
6733     /* explicitly ignore WM_GETICON message */
6734     if (message == WM_GETICON) return 0;
6735
6736     logged_lParam=lParam;
6737     if (log_all_parent_messages ||
6738         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6739         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6740         message == WM_ENABLE || message == WM_ENTERIDLE ||
6741         message == WM_DRAWITEM ||
6742         message == WM_IME_SETCONTEXT)
6743     {
6744         switch (message)
6745         {
6746             /* ignore */
6747             case WM_NCHITTEST:
6748                 return HTCLIENT;
6749             case WM_SETCURSOR:
6750             case WM_MOUSEMOVE:
6751                 return 0;
6752
6753             case WM_ERASEBKGND:
6754             {
6755                 RECT rc;
6756                 INT ret = GetClipBox((HDC)wParam, &rc);
6757
6758                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6759                        ret, rc.left, rc.top, rc.right, rc.bottom);
6760                 break;
6761             }
6762
6763             case WM_WINDOWPOSCHANGING:
6764             case WM_WINDOWPOSCHANGED:
6765             {
6766                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6767
6768                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6769                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6770                       winpos->hwnd, winpos->hwndInsertAfter,
6771                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6772                 dump_winpos_flags(winpos->flags);
6773
6774                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6775                  * in the high word for internal purposes
6776                  */
6777                 wParam = winpos->flags & 0xffff;
6778                 /* We are not interested in the flags that don't match under XP and Win9x */
6779                 wParam &= ~(SWP_NOZORDER);
6780                 break;
6781             }
6782
6783             case WM_DRAWITEM:
6784             {
6785                 /* encode DRAWITEMSTRUCT into an LPARAM */
6786                 DRAW_ITEM_STRUCT di;
6787                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6788
6789                 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6790                       dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6791
6792                 di.u.item.type = dis->CtlType;
6793                 di.u.item.ctl_id = dis->CtlID;
6794                 di.u.item.item_id = dis->itemID;
6795                 di.u.item.action = dis->itemAction;
6796                 di.u.item.state = dis->itemState;
6797
6798                 logged_lParam = di.u.lp;
6799                 break;
6800             }
6801         }
6802
6803         msg.message = message;
6804         msg.flags = sent|parent|wparam|lparam;
6805         if (defwndproc_counter) msg.flags |= defwinproc;
6806         if (beginpaint_counter) msg.flags |= beginpaint;
6807         msg.wParam = wParam;
6808         msg.lParam = logged_lParam;
6809         add_message(&msg);
6810     }
6811
6812     if (message == WM_PAINT)
6813     {
6814         PAINTSTRUCT ps;
6815         beginpaint_counter++;
6816         BeginPaint( hwnd, &ps );
6817         beginpaint_counter--;
6818         EndPaint( hwnd, &ps );
6819         return 0;
6820     }
6821
6822     defwndproc_counter++;
6823     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6824     defwndproc_counter--;
6825
6826     return ret;
6827 }
6828
6829 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6830 {
6831     static long defwndproc_counter = 0;
6832     LRESULT ret;
6833     struct message msg;
6834
6835     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6836
6837     /* explicitly ignore WM_GETICON message */
6838     if (message == WM_GETICON) return 0;
6839
6840     if (test_def_id)
6841     {
6842         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6843         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6844         if (after_end_dialog)
6845             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6846         else
6847             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6848     }
6849
6850     switch (message)
6851     {
6852         case WM_WINDOWPOSCHANGING:
6853         case WM_WINDOWPOSCHANGED:
6854         {
6855             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6856
6857             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6858             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6859                   winpos->hwnd, winpos->hwndInsertAfter,
6860                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6861             dump_winpos_flags(winpos->flags);
6862
6863             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6864              * in the high word for internal purposes
6865              */
6866             wParam = winpos->flags & 0xffff;
6867             /* We are not interested in the flags that don't match under XP and Win9x */
6868             wParam &= ~(SWP_NOZORDER);
6869             break;
6870         }
6871     }
6872
6873     msg.message = message;
6874     msg.flags = sent|wparam|lparam;
6875     if (defwndproc_counter) msg.flags |= defwinproc;
6876     msg.wParam = wParam;
6877     msg.lParam = lParam;
6878     add_message(&msg);
6879
6880     defwndproc_counter++;
6881     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6882     defwndproc_counter--;
6883
6884     return ret;
6885 }
6886
6887 static void dump_winpos_flags(UINT flags)
6888 {
6889     if (!winetest_debug) return;
6890
6891     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6892     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6893     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6894     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6895     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6896     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6897     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6898     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6899     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6900     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6901     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6902     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6903     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6904     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6905     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6906
6907 #define DUMPED_FLAGS \
6908     (SWP_NOSIZE | \
6909     SWP_NOMOVE | \
6910     SWP_NOZORDER | \
6911     SWP_NOREDRAW | \
6912     SWP_NOACTIVATE | \
6913     SWP_FRAMECHANGED | \
6914     SWP_SHOWWINDOW | \
6915     SWP_HIDEWINDOW | \
6916     SWP_NOCOPYBITS | \
6917     SWP_NOOWNERZORDER | \
6918     SWP_NOSENDCHANGING | \
6919     SWP_DEFERERASE | \
6920     SWP_ASYNCWINDOWPOS | \
6921     SWP_NOCLIENTSIZE | \
6922     SWP_NOCLIENTMOVE)
6923
6924     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6925     printf("\n");
6926 #undef DUMPED_FLAGS
6927 }
6928
6929 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6930 {
6931     static long defwndproc_counter = 0;
6932     LRESULT ret;
6933     struct message msg;
6934
6935     /* log only specific messages we are interested in */
6936     switch (message)
6937     {
6938 #if 0 /* probably log these as well */
6939     case WM_ACTIVATE:
6940     case WM_SETFOCUS:
6941     case WM_KILLFOCUS:
6942 #endif
6943     case WM_SHOWWINDOW:
6944         trace("WM_SHOWWINDOW %ld\n", wParam);
6945         break;
6946     case WM_SIZE:
6947         trace("WM_SIZE %ld\n", wParam);
6948         break;
6949     case WM_MOVE:
6950         trace("WM_MOVE\n");
6951         break;
6952     case WM_GETMINMAXINFO:
6953         trace("WM_GETMINMAXINFO\n");
6954         break;
6955
6956     case WM_WINDOWPOSCHANGING:
6957     case WM_WINDOWPOSCHANGED:
6958     {
6959         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6960
6961         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6962         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6963               winpos->hwnd, winpos->hwndInsertAfter,
6964               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6965         trace("flags: ");
6966         dump_winpos_flags(winpos->flags);
6967
6968         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6969          * in the high word for internal purposes
6970          */
6971         wParam = winpos->flags & 0xffff;
6972         /* We are not interested in the flags that don't match under XP and Win9x */
6973         wParam &= ~(SWP_NOZORDER);
6974         break;
6975     }
6976
6977     default: /* ignore */
6978         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6979         return DefWindowProcA(hwnd, message, wParam, lParam);
6980     }
6981
6982     msg.message = message;
6983     msg.flags = sent|wparam|lparam;
6984     if (defwndproc_counter) msg.flags |= defwinproc;
6985     msg.wParam = wParam;
6986     msg.lParam = lParam;
6987     add_message(&msg);
6988
6989     defwndproc_counter++;
6990     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6991     defwndproc_counter--;
6992
6993     return ret;
6994 }
6995
6996 static BOOL RegisterWindowClasses(void)
6997 {
6998     WNDCLASSA cls;
6999     WNDCLASSW clsW;
7000
7001     cls.style = 0;
7002     cls.lpfnWndProc = MsgCheckProcA;
7003     cls.cbClsExtra = 0;
7004     cls.cbWndExtra = 0;
7005     cls.hInstance = GetModuleHandleA(0);
7006     cls.hIcon = 0;
7007     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
7008     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7009     cls.lpszMenuName = NULL;
7010     cls.lpszClassName = "TestWindowClass";
7011     if(!RegisterClassA(&cls)) return FALSE;
7012
7013     cls.lpfnWndProc = ShowWindowProcA;
7014     cls.lpszClassName = "ShowWindowClass";
7015     if(!RegisterClassA(&cls)) return FALSE;
7016
7017     cls.lpfnWndProc = PopupMsgCheckProcA;
7018     cls.lpszClassName = "TestPopupClass";
7019     if(!RegisterClassA(&cls)) return FALSE;
7020
7021     cls.lpfnWndProc = ParentMsgCheckProcA;
7022     cls.lpszClassName = "TestParentClass";
7023     if(!RegisterClassA(&cls)) return FALSE;
7024
7025     cls.lpfnWndProc = DefWindowProcA;
7026     cls.lpszClassName = "SimpleWindowClass";
7027     if(!RegisterClassA(&cls)) return FALSE;
7028
7029     cls.style = CS_NOCLOSE;
7030     cls.lpszClassName = "NoCloseWindowClass";
7031     if(!RegisterClassA(&cls)) return FALSE;
7032
7033     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7034     cls.style = 0;
7035     cls.hInstance = GetModuleHandleA(0);
7036     cls.hbrBackground = 0;
7037     cls.lpfnWndProc = TestDlgProcA;
7038     cls.lpszClassName = "TestDialogClass";
7039     if(!RegisterClassA(&cls)) return FALSE;
7040
7041     clsW.style = 0;
7042     clsW.lpfnWndProc = MsgCheckProcW;
7043     clsW.cbClsExtra = 0;
7044     clsW.cbWndExtra = 0;
7045     clsW.hInstance = GetModuleHandleW(0);
7046     clsW.hIcon = 0;
7047     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7048     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7049     clsW.lpszMenuName = NULL;
7050     clsW.lpszClassName = testWindowClassW;
7051     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7052
7053     return TRUE;
7054 }
7055
7056 static BOOL is_our_logged_class(HWND hwnd)
7057 {
7058     char buf[256];
7059
7060     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7061     {
7062         if (!lstrcmpiA(buf, "TestWindowClass") ||
7063             !lstrcmpiA(buf, "ShowWindowClass") ||
7064             !lstrcmpiA(buf, "TestParentClass") ||
7065             !lstrcmpiA(buf, "TestPopupClass") ||
7066             !lstrcmpiA(buf, "SimpleWindowClass") ||
7067             !lstrcmpiA(buf, "TestDialogClass") ||
7068             !lstrcmpiA(buf, "MDI_frame_class") ||
7069             !lstrcmpiA(buf, "MDI_client_class") ||
7070             !lstrcmpiA(buf, "MDI_child_class") ||
7071             !lstrcmpiA(buf, "my_button_class") ||
7072             !lstrcmpiA(buf, "my_edit_class") ||
7073             !lstrcmpiA(buf, "static") ||
7074             !lstrcmpiA(buf, "ListBox") ||
7075             !lstrcmpiA(buf, "ComboBox") ||
7076             !lstrcmpiA(buf, "MyDialogClass") ||
7077             !lstrcmpiA(buf, "#32770") ||
7078             !lstrcmpiA(buf, "#32768"))
7079         return TRUE;
7080         trace("ignoring window class %s\n", buf);
7081     }
7082     return FALSE;
7083 }
7084
7085 static HHOOK hCBT_hook;
7086 static DWORD cbt_hook_thread_id;
7087
7088 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7089
7090     static const char * const CBT_code_name[10] = {
7091         "HCBT_MOVESIZE",
7092         "HCBT_MINMAX",
7093         "HCBT_QS",
7094         "HCBT_CREATEWND",
7095         "HCBT_DESTROYWND",
7096         "HCBT_ACTIVATE",
7097         "HCBT_CLICKSKIPPED",
7098         "HCBT_KEYSKIPPED",
7099         "HCBT_SYSCOMMAND",
7100         "HCBT_SETFOCUS" };
7101     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
7102     HWND hwnd;
7103
7104     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
7105
7106     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7107
7108     if (nCode == HCBT_CLICKSKIPPED)
7109     {
7110         /* ignore this event, XP sends it a lot when switching focus between windows */
7111         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7112     }
7113
7114     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7115     {
7116         struct message msg;
7117
7118         msg.message = nCode;
7119         msg.flags = hook|wparam|lparam;
7120         msg.wParam = wParam;
7121         msg.lParam = lParam;
7122         add_message(&msg);
7123
7124         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7125     }
7126
7127     if (nCode == HCBT_DESTROYWND)
7128     {
7129         if (test_DestroyWindow_flag)
7130         {
7131             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7132             if (style & WS_CHILD)
7133                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7134             else if (style & WS_POPUP)
7135                 lParam = WND_POPUP_ID;
7136             else
7137                 lParam = WND_PARENT_ID;
7138         }
7139     }
7140
7141     /* Log also SetFocus(0) calls */
7142     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7143
7144     if (is_our_logged_class(hwnd))
7145     {
7146         struct message msg;
7147
7148         msg.message = nCode;
7149         msg.flags = hook|wparam|lparam;
7150         msg.wParam = wParam;
7151         msg.lParam = lParam;
7152         add_message(&msg);
7153     }
7154     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7155 }
7156
7157 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7158                                     DWORD event,
7159                                     HWND hwnd,
7160                                     LONG object_id,
7161                                     LONG child_id,
7162                                     DWORD thread_id,
7163                                     DWORD event_time)
7164 {
7165     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7166            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7167
7168     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7169
7170     /* ignore mouse cursor events */
7171     if (object_id == OBJID_CURSOR) return;
7172
7173     if (!hwnd || is_our_logged_class(hwnd))
7174     {
7175         struct message msg;
7176
7177         msg.message = event;
7178         msg.flags = winevent_hook|wparam|lparam;
7179         msg.wParam = object_id;
7180         msg.lParam = child_id;
7181         add_message(&msg);
7182     }
7183 }
7184
7185 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7186 static const WCHAR wszAnsi[] = {'U',0};
7187
7188 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7189 {
7190     switch (uMsg)
7191     {
7192     case CB_FINDSTRINGEXACT:
7193         trace("String: %p\n", (LPCWSTR)lParam);
7194         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7195             return 1;
7196         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7197             return 0;
7198         return -1;
7199     }
7200     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7201 }
7202
7203 static const struct message WmGetTextLengthAfromW[] = {
7204     { WM_GETTEXTLENGTH, sent },
7205     { WM_GETTEXT, sent },
7206     { 0 }
7207 };
7208
7209 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7210
7211 /* dummy window proc for WM_GETTEXTLENGTH test */
7212 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7213 {
7214     switch(msg)
7215     {
7216     case WM_GETTEXTLENGTH:
7217         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7218     case WM_GETTEXT:
7219         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7220         return lstrlenW( (LPWSTR)lp );
7221     default:
7222         return DefWindowProcW( hwnd, msg, wp, lp );
7223     }
7224 }
7225
7226 static void test_message_conversion(void)
7227 {
7228     static const WCHAR wszMsgConversionClass[] =
7229         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7230     WNDCLASSW cls;
7231     LRESULT lRes;
7232     HWND hwnd;
7233     WNDPROC wndproc, newproc;
7234     BOOL ret;
7235
7236     cls.style = 0;
7237     cls.lpfnWndProc = MsgConversionProcW;
7238     cls.cbClsExtra = 0;
7239     cls.cbWndExtra = 0;
7240     cls.hInstance = GetModuleHandleW(NULL);
7241     cls.hIcon = NULL;
7242     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7243     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7244     cls.lpszMenuName = NULL;
7245     cls.lpszClassName = wszMsgConversionClass;
7246     /* this call will fail on Win9x, but that doesn't matter as this test is
7247      * meaningless on those platforms */
7248     if(!RegisterClassW(&cls)) return;
7249
7250     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7251                            100, 100, 200, 200, 0, 0, 0, NULL);
7252     ok(hwnd != NULL, "Window creation failed\n");
7253
7254     /* {W, A} -> A */
7255
7256     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7257     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7258     ok(lRes == 0, "String should have been converted\n");
7259     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7260     ok(lRes == 1, "String shouldn't have been converted\n");
7261
7262     /* {W, A} -> W */
7263
7264     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7265     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7266     ok(lRes == 1, "String shouldn't have been converted\n");
7267     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7268     ok(lRes == 1, "String shouldn't have been converted\n");
7269
7270     /* Synchronous messages */
7271
7272     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7273     ok(lRes == 0, "String should have been converted\n");
7274     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7275     ok(lRes == 1, "String shouldn't have been converted\n");
7276
7277     /* Asynchronous messages */
7278
7279     SetLastError(0);
7280     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7281     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7282         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7283     SetLastError(0);
7284     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7285     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7286         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7287     SetLastError(0);
7288     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7289     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7290         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7291     SetLastError(0);
7292     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7293     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7294         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7295     SetLastError(0);
7296     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7297     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7298         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7299     SetLastError(0);
7300     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7301     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7302         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7303     SetLastError(0);
7304     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7305     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7306         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7307     SetLastError(0);
7308     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7309     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7310         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7311
7312     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7313
7314     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7315                           WS_OVERLAPPEDWINDOW,
7316                           100, 100, 200, 200, 0, 0, 0, NULL);
7317     assert(hwnd);
7318     flush_sequence();
7319     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7320     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7321     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7322         "got bad length %ld\n", lRes );
7323
7324     flush_sequence();
7325     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7326                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7327     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7328     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7329         "got bad length %ld\n", lRes );
7330
7331     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7332     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7333     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7334     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7335                                      NULL, 0, NULL, NULL ),
7336         "got bad length %ld\n", lRes );
7337
7338     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7339     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7340     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7341                                      NULL, 0, NULL, NULL ),
7342         "got bad length %ld\n", lRes );
7343
7344     ret = DestroyWindow(hwnd);
7345     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7346 }
7347
7348 struct timer_info
7349 {
7350     HWND hWnd;
7351     HANDLE handles[2];
7352     DWORD id;
7353 };
7354
7355 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7356 {
7357 }
7358
7359 #define TIMER_ID  0x19
7360
7361 static DWORD WINAPI timer_thread_proc(LPVOID x)
7362 {
7363     struct timer_info *info = x;
7364     DWORD r;
7365
7366     r = KillTimer(info->hWnd, 0x19);
7367     ok(r,"KillTimer failed in thread\n");
7368     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7369     ok(r,"SetTimer failed in thread\n");
7370     ok(r==TIMER_ID,"SetTimer id different\n");
7371     r = SetEvent(info->handles[0]);
7372     ok(r,"SetEvent failed in thread\n");
7373     return 0;
7374 }
7375
7376 static void test_timers(void)
7377 {
7378     struct timer_info info;
7379     DWORD id;
7380
7381     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7382        WS_OVERLAPPEDWINDOW ,
7383        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7384        NULL, NULL, 0);
7385
7386     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7387     ok(info.id, "SetTimer failed\n");
7388     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7389     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7390     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7391
7392     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7393
7394     WaitForSingleObject(info.handles[1], INFINITE);
7395
7396     CloseHandle(info.handles[0]);
7397     CloseHandle(info.handles[1]);
7398
7399     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7400
7401     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7402 }
7403
7404 static int count = 0;
7405 static VOID CALLBACK callback_count(
7406     HWND hwnd,
7407     UINT uMsg,
7408     UINT_PTR idEvent,
7409     DWORD dwTime
7410 )
7411 {
7412     count++;
7413 }
7414
7415 static void test_timers_no_wnd(void)
7416 {
7417     UINT_PTR id, id2;
7418     MSG msg;
7419
7420     count = 0;
7421     id = SetTimer(NULL, 0, 100, callback_count);
7422     ok(id != 0, "did not get id from SetTimer.\n");
7423     id2 = SetTimer(NULL, id, 200, callback_count);
7424     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7425     Sleep(150);
7426     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7427     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7428     Sleep(150);
7429     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7430     ok(count == 1, "did not get one count as expected (%i).\n", count);
7431     KillTimer(NULL, id);
7432     Sleep(250);
7433     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7434     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7435 }
7436
7437 /* Various win events with arbitrary parameters */
7438 static const struct message WmWinEventsSeq[] = {
7439     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7440     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7441     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7442     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7443     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7444     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7445     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7446     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7447     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7448     /* our win event hook ignores OBJID_CURSOR events */
7449     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7450     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7451     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7452     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7453     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7454     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7455     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7456     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7457     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7458     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7459     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7460     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7461     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7462     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7463     { 0 }
7464 };
7465 static const struct message WmWinEventCaretSeq[] = {
7466     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7467     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7468     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7469     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7470     { 0 }
7471 };
7472 static const struct message WmWinEventCaretSeq_2[] = {
7473     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7474     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7475     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7476     { 0 }
7477 };
7478 static const struct message WmWinEventAlertSeq[] = {
7479     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7480     { 0 }
7481 };
7482 static const struct message WmWinEventAlertSeq_2[] = {
7483     /* create window in the thread proc */
7484     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7485     /* our test event */
7486     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7487     { 0 }
7488 };
7489 static const struct message WmGlobalHookSeq_1[] = {
7490     /* create window in the thread proc */
7491     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7492     /* our test events */
7493     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7494     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7495     { 0 }
7496 };
7497 static const struct message WmGlobalHookSeq_2[] = {
7498     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7499     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7500     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7501     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7502     { 0 }
7503 };
7504
7505 static const struct message WmMouseLLHookSeq[] = {
7506     { WM_MOUSEMOVE, hook },
7507     { WM_LBUTTONUP, hook },
7508     { WM_MOUSEMOVE, hook },
7509     { 0 }
7510 };
7511
7512 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7513                                          DWORD event,
7514                                          HWND hwnd,
7515                                          LONG object_id,
7516                                          LONG child_id,
7517                                          DWORD thread_id,
7518                                          DWORD event_time)
7519 {
7520     char buf[256];
7521
7522     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7523            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7524
7525     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7526     {
7527         if (!lstrcmpiA(buf, "TestWindowClass") ||
7528             !lstrcmpiA(buf, "static"))
7529         {
7530             struct message msg;
7531
7532             msg.message = event;
7533             msg.flags = winevent_hook|wparam|lparam;
7534             msg.wParam = object_id;
7535             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7536             add_message(&msg);
7537         }
7538     }
7539 }
7540
7541 static HHOOK hCBT_global_hook;
7542 static DWORD cbt_global_hook_thread_id;
7543
7544 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7545
7546     HWND hwnd;
7547     char buf[256];
7548
7549     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7550
7551     if (nCode == HCBT_SYSCOMMAND)
7552     {
7553         struct message msg;
7554
7555         msg.message = nCode;
7556         msg.flags = hook|wparam|lparam;
7557         msg.wParam = wParam;
7558         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7559         add_message(&msg);
7560
7561         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7562     }
7563     /* WH_MOUSE_LL hook */
7564     if (nCode == HC_ACTION)
7565     {
7566         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7567
7568         /* we can't test for real mouse events */
7569         if (mhll->flags & LLMHF_INJECTED)
7570         {
7571             struct message msg;
7572
7573             memset (&msg, 0, sizeof (msg));
7574             msg.message = wParam;
7575             msg.flags = hook;
7576             add_message(&msg);
7577         }
7578         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7579     }
7580
7581     /* Log also SetFocus(0) calls */
7582     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7583
7584     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7585     {
7586         if (!lstrcmpiA(buf, "TestWindowClass") ||
7587             !lstrcmpiA(buf, "static"))
7588         {
7589             struct message msg;
7590
7591             msg.message = nCode;
7592             msg.flags = hook|wparam|lparam;
7593             msg.wParam = wParam;
7594             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7595             add_message(&msg);
7596         }
7597     }
7598     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7599 }
7600
7601 static DWORD WINAPI win_event_global_thread_proc(void *param)
7602 {
7603     HWND hwnd;
7604     MSG msg;
7605     HANDLE hevent = *(HANDLE *)param;
7606
7607     assert(pNotifyWinEvent);
7608
7609     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7610     assert(hwnd);
7611     trace("created thread window %p\n", hwnd);
7612
7613     *(HWND *)param = hwnd;
7614
7615     flush_sequence();
7616     /* this event should be received only by our new hook proc,
7617      * an old one does not expect an event from another thread.
7618      */
7619     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7620     SetEvent(hevent);
7621
7622     while (GetMessage(&msg, 0, 0, 0))
7623     {
7624         TranslateMessage(&msg);
7625         DispatchMessage(&msg);
7626     }
7627     return 0;
7628 }
7629
7630 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7631 {
7632     HWND hwnd;
7633     MSG msg;
7634     HANDLE hevent = *(HANDLE *)param;
7635
7636     flush_sequence();
7637     /* these events should be received only by our new hook proc,
7638      * an old one does not expect an event from another thread.
7639      */
7640
7641     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7642     assert(hwnd);
7643     trace("created thread window %p\n", hwnd);
7644
7645     *(HWND *)param = hwnd;
7646
7647     /* Windows doesn't like when a thread plays games with the focus,
7648        that leads to all kinds of misbehaviours and failures to activate
7649        a window. So, better keep next lines commented out.
7650     SetFocus(0);
7651     SetFocus(hwnd);*/
7652
7653     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7654     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7655
7656     SetEvent(hevent);
7657
7658     while (GetMessage(&msg, 0, 0, 0))
7659     {
7660         TranslateMessage(&msg);
7661         DispatchMessage(&msg);
7662     }
7663     return 0;
7664 }
7665
7666 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7667 {
7668     HWND hwnd;
7669     MSG msg;
7670     HANDLE hevent = *(HANDLE *)param;
7671
7672     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7673     assert(hwnd);
7674     trace("created thread window %p\n", hwnd);
7675
7676     *(HWND *)param = hwnd;
7677
7678     flush_sequence();
7679
7680     /* Windows doesn't like when a thread plays games with the focus,
7681      * that leads to all kinds of misbehaviours and failures to activate
7682      * a window. So, better don't generate a mouse click message below.
7683      */
7684     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7685     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7686     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7687
7688     SetEvent(hevent);
7689     while (GetMessage(&msg, 0, 0, 0))
7690     {
7691         TranslateMessage(&msg);
7692         DispatchMessage(&msg);
7693     }
7694     return 0;
7695 }
7696
7697 static void test_winevents(void)
7698 {
7699     BOOL ret;
7700     MSG msg;
7701     HWND hwnd, hwnd2;
7702     UINT i;
7703     HANDLE hthread, hevent;
7704     DWORD tid;
7705     HWINEVENTHOOK hhook;
7706     const struct message *events = WmWinEventsSeq;
7707
7708     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7709                            WS_OVERLAPPEDWINDOW,
7710                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7711                            NULL, NULL, 0);
7712     assert(hwnd);
7713
7714     /****** start of global hook test *************/
7715     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7716     if (!hCBT_global_hook)
7717     {
7718         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7719         skip( "cannot set global hook\n" );
7720         return;
7721     }
7722
7723     hevent = CreateEventA(NULL, 0, 0, NULL);
7724     assert(hevent);
7725     hwnd2 = (HWND)hevent;
7726
7727     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7728     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7729
7730     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7731
7732     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7733
7734     flush_sequence();
7735     /* this one should be received only by old hook proc */
7736     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7737     /* this one should be received only by old hook proc */
7738     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7739
7740     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7741
7742     ret = UnhookWindowsHookEx(hCBT_global_hook);
7743     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7744
7745     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7746     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7747     CloseHandle(hthread);
7748     CloseHandle(hevent);
7749     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7750     /****** end of global hook test *************/
7751
7752     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7753     {
7754         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7755         return;
7756     }
7757
7758     flush_sequence();
7759
7760     if (0)
7761     {
7762     /* this test doesn't pass under Win9x */
7763     /* win2k ignores events with hwnd == 0 */
7764     SetLastError(0xdeadbeef);
7765     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7766     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7767        GetLastError() == 0xdeadbeef, /* Win9x */
7768        "unexpected error %d\n", GetLastError());
7769     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7770     }
7771
7772     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7773         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7774
7775     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7776
7777     /****** start of event filtering test *************/
7778     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7779         EVENT_OBJECT_SHOW, /* 0x8002 */
7780         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7781         GetModuleHandleA(0), win_event_global_hook_proc,
7782         GetCurrentProcessId(), 0,
7783         WINEVENT_INCONTEXT);
7784     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7785
7786     hevent = CreateEventA(NULL, 0, 0, NULL);
7787     assert(hevent);
7788     hwnd2 = (HWND)hevent;
7789
7790     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7791     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7792
7793     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7794
7795     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7796
7797     flush_sequence();
7798     /* this one should be received only by old hook proc */
7799     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7800     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7801     /* this one should be received only by old hook proc */
7802     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7803
7804     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7805
7806     ret = pUnhookWinEvent(hhook);
7807     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7808
7809     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7810     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7811     CloseHandle(hthread);
7812     CloseHandle(hevent);
7813     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7814     /****** end of event filtering test *************/
7815
7816     /****** start of out of context event test *************/
7817     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7818         EVENT_MIN, EVENT_MAX,
7819         0, win_event_global_hook_proc,
7820         GetCurrentProcessId(), 0,
7821         WINEVENT_OUTOFCONTEXT);
7822     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7823
7824     hevent = CreateEventA(NULL, 0, 0, NULL);
7825     assert(hevent);
7826     hwnd2 = (HWND)hevent;
7827
7828     flush_sequence();
7829
7830     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7831     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7832
7833     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7834
7835     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7836     /* process pending winevent messages */
7837     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7838     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7839
7840     flush_sequence();
7841     /* this one should be received only by old hook proc */
7842     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7843     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7844     /* this one should be received only by old hook proc */
7845     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7846
7847     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7848     /* process pending winevent messages */
7849     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7850     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7851
7852     ret = pUnhookWinEvent(hhook);
7853     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7854
7855     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7856     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7857     CloseHandle(hthread);
7858     CloseHandle(hevent);
7859     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7860     /****** end of out of context event test *************/
7861
7862     /****** start of MOUSE_LL hook test *************/
7863     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7864     /* WH_MOUSE_LL is not supported on Win9x platforms */
7865     if (!hCBT_global_hook)
7866     {
7867         trace("Skipping WH_MOUSE_LL test on this platform\n");
7868         goto skip_mouse_ll_hook_test;
7869     }
7870
7871     hevent = CreateEventA(NULL, 0, 0, NULL);
7872     assert(hevent);
7873     hwnd2 = (HWND)hevent;
7874
7875     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7876     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7877
7878     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7879         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7880
7881     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7882     flush_sequence();
7883
7884     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7885     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7886     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7887
7888     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7889
7890     ret = UnhookWindowsHookEx(hCBT_global_hook);
7891     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7892
7893     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7894     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7895     CloseHandle(hthread);
7896     CloseHandle(hevent);
7897     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7898     /****** end of MOUSE_LL hook test *************/
7899 skip_mouse_ll_hook_test:
7900
7901     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7902 }
7903
7904 static void test_set_hook(void)
7905 {
7906     BOOL ret;
7907     HHOOK hhook;
7908     HWINEVENTHOOK hwinevent_hook;
7909
7910     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7911     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7912     UnhookWindowsHookEx(hhook);
7913
7914     if (0)
7915     {
7916     /* this test doesn't pass under Win9x: BUG! */
7917     SetLastError(0xdeadbeef);
7918     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7919     ok(!hhook, "global hook requires hModule != 0\n");
7920     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7921     }
7922
7923     SetLastError(0xdeadbeef);
7924     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7925     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7926     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7927        GetLastError() == 0xdeadbeef, /* Win9x */
7928        "unexpected error %d\n", GetLastError());
7929
7930     SetLastError(0xdeadbeef);
7931     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7932     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7933        GetLastError() == 0xdeadbeef, /* Win9x */
7934        "unexpected error %d\n", GetLastError());
7935
7936     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7937
7938     /* even process local incontext hooks require hmodule */
7939     SetLastError(0xdeadbeef);
7940     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7941         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7942     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7943     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7944        GetLastError() == 0xdeadbeef, /* Win9x */
7945        "unexpected error %d\n", GetLastError());
7946
7947     /* even thread local incontext hooks require hmodule */
7948     SetLastError(0xdeadbeef);
7949     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7950         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7951     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7952     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7953        GetLastError() == 0xdeadbeef, /* Win9x */
7954        "unexpected error %d\n", GetLastError());
7955
7956     if (0)
7957     {
7958     /* these 3 tests don't pass under Win9x */
7959     SetLastError(0xdeadbeef);
7960     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7961         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7962     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7963     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7964
7965     SetLastError(0xdeadbeef);
7966     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7967         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7968     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7969     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7970
7971     SetLastError(0xdeadbeef);
7972     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7973         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7974     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7975     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7976     }
7977
7978     SetLastError(0xdeadbeef);
7979     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7980         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7981     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7982     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7983     ret = pUnhookWinEvent(hwinevent_hook);
7984     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7985
7986 todo_wine {
7987     /* This call succeeds under win2k SP4, but fails under Wine.
7988        Does win2k test/use passed process id? */
7989     SetLastError(0xdeadbeef);
7990     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7991         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7992     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7993     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7994     ret = pUnhookWinEvent(hwinevent_hook);
7995     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7996 }
7997
7998     SetLastError(0xdeadbeef);
7999     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8000     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8001         GetLastError() == 0xdeadbeef, /* Win9x */
8002         "unexpected error %d\n", GetLastError());
8003 }
8004
8005 static const struct message ScrollWindowPaint1[] = {
8006     { WM_PAINT, sent },
8007     { WM_ERASEBKGND, sent|beginpaint },
8008     { 0 }
8009 };
8010
8011 static const struct message ScrollWindowPaint2[] = {
8012     { WM_PAINT, sent },
8013     { 0 }
8014 };
8015
8016 static void test_scrollwindowex(void)
8017 {
8018     HWND hwnd, hchild;
8019     RECT rect={0,0,130,130};
8020
8021     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8022             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8023             100, 100, 200, 200, 0, 0, 0, NULL);
8024     ok (hwnd != 0, "Failed to create overlapped window\n");
8025     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8026             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8027             10, 10, 150, 150, hwnd, 0, 0, NULL);
8028     ok (hchild != 0, "Failed to create child\n");
8029     UpdateWindow(hwnd);
8030     flush_events();
8031     flush_sequence();
8032
8033     /* scroll without the child window */
8034     trace("start scroll\n");
8035     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8036             SW_ERASE|SW_INVALIDATE);
8037     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8038     trace("end scroll\n");
8039     flush_sequence();
8040     flush_events();
8041     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8042     flush_events();
8043     flush_sequence();
8044
8045     /* Now without the SW_ERASE flag */
8046     trace("start scroll\n");
8047     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8048     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8049     trace("end scroll\n");
8050     flush_sequence();
8051     flush_events();
8052     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8053     flush_events();
8054     flush_sequence();
8055
8056     /* now scroll the child window as well */
8057     trace("start scroll\n");
8058     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8059             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8060     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8061                 /* windows sometimes a WM_MOVE */
8062         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8063     }
8064     trace("end scroll\n");
8065     flush_sequence();
8066     flush_events();
8067     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8068     flush_events();
8069     flush_sequence();
8070
8071     /* now scroll with ScrollWindow() */
8072     trace("start scroll with ScrollWindow\n");
8073     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8074     trace("end scroll\n");
8075     flush_sequence();
8076     flush_events();
8077     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8078
8079     ok(DestroyWindow(hchild), "failed to destroy window\n");
8080     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8081     flush_sequence();
8082 }
8083
8084 static const struct message destroy_window_with_children[] = {
8085     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8086     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8087     { 0x0090, sent|optional },
8088     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8089     { 0x0090, sent|optional },
8090     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8091     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8092     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8093     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8094     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8095     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8096     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8097     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8098     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8099     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8100     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8101     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8102     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8103     { 0 }
8104 };
8105
8106 static void test_DestroyWindow(void)
8107 {
8108     BOOL ret;
8109     HWND parent, child1, child2, child3, child4, test;
8110     UINT child_id = WND_CHILD_ID + 1;
8111
8112     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8113                              100, 100, 200, 200, 0, 0, 0, NULL);
8114     assert(parent != 0);
8115     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8116                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8117     assert(child1 != 0);
8118     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8119                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8120     assert(child2 != 0);
8121     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8122                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8123     assert(child3 != 0);
8124     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8125                              0, 0, 50, 50, parent, 0, 0, NULL);
8126     assert(child4 != 0);
8127
8128     /* test owner/parent of child2 */
8129     test = GetParent(child2);
8130     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8131     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8132     if(pGetAncestor) {
8133         test = pGetAncestor(child2, GA_PARENT);
8134         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8135     }
8136     test = GetWindow(child2, GW_OWNER);
8137     ok(!test, "wrong owner %p\n", test);
8138
8139     test = SetParent(child2, parent);
8140     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8141
8142     /* test owner/parent of the parent */
8143     test = GetParent(parent);
8144     ok(!test, "wrong parent %p\n", test);
8145     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8146     if(pGetAncestor) {
8147         test = pGetAncestor(parent, GA_PARENT);
8148         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8149     }
8150     test = GetWindow(parent, GW_OWNER);
8151     ok(!test, "wrong owner %p\n", test);
8152
8153     /* test owner/parent of child1 */
8154     test = GetParent(child1);
8155     ok(test == parent, "wrong parent %p\n", test);
8156     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8157     if(pGetAncestor) {
8158         test = pGetAncestor(child1, GA_PARENT);
8159         ok(test == parent, "wrong parent %p\n", test);
8160     }
8161     test = GetWindow(child1, GW_OWNER);
8162     ok(!test, "wrong owner %p\n", test);
8163
8164     /* test owner/parent of child2 */
8165     test = GetParent(child2);
8166     ok(test == parent, "wrong parent %p\n", test);
8167     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8168     if(pGetAncestor) {
8169         test = pGetAncestor(child2, GA_PARENT);
8170         ok(test == parent, "wrong parent %p\n", test);
8171     }
8172     test = GetWindow(child2, GW_OWNER);
8173     ok(!test, "wrong owner %p\n", test);
8174
8175     /* test owner/parent of child3 */
8176     test = GetParent(child3);
8177     ok(test == child1, "wrong parent %p\n", test);
8178     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8179     if(pGetAncestor) {
8180         test = pGetAncestor(child3, GA_PARENT);
8181         ok(test == child1, "wrong parent %p\n", test);
8182     }
8183     test = GetWindow(child3, GW_OWNER);
8184     ok(!test, "wrong owner %p\n", test);
8185
8186     /* test owner/parent of child4 */
8187     test = GetParent(child4);
8188     ok(test == parent, "wrong parent %p\n", test);
8189     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8190     if(pGetAncestor) {
8191         test = pGetAncestor(child4, GA_PARENT);
8192         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8193     }
8194     test = GetWindow(child4, GW_OWNER);
8195     ok(test == parent, "wrong owner %p\n", test);
8196
8197     flush_sequence();
8198
8199     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8200            parent, child1, child2, child3, child4);
8201
8202     SetCapture(child4);
8203     test = GetCapture();
8204     ok(test == child4, "wrong capture window %p\n", test);
8205
8206     test_DestroyWindow_flag = TRUE;
8207     ret = DestroyWindow(parent);
8208     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8209     test_DestroyWindow_flag = FALSE;
8210     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8211
8212     ok(!IsWindow(parent), "parent still exists\n");
8213     ok(!IsWindow(child1), "child1 still exists\n");
8214     ok(!IsWindow(child2), "child2 still exists\n");
8215     ok(!IsWindow(child3), "child3 still exists\n");
8216     ok(!IsWindow(child4), "child4 still exists\n");
8217
8218     test = GetCapture();
8219     ok(!test, "wrong capture window %p\n", test);
8220 }
8221
8222
8223 static const struct message WmDispatchPaint[] = {
8224     { WM_NCPAINT, sent },
8225     { WM_GETTEXT, sent|defwinproc|optional },
8226     { WM_GETTEXT, sent|defwinproc|optional },
8227     { WM_ERASEBKGND, sent },
8228     { 0 }
8229 };
8230
8231 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8232 {
8233     if (message == WM_PAINT) return 0;
8234     return MsgCheckProcA( hwnd, message, wParam, lParam );
8235 }
8236
8237 static void test_DispatchMessage(void)
8238 {
8239     RECT rect;
8240     MSG msg;
8241     int count;
8242     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8243                                100, 100, 200, 200, 0, 0, 0, NULL);
8244     ShowWindow( hwnd, SW_SHOW );
8245     UpdateWindow( hwnd );
8246     flush_events();
8247     flush_sequence();
8248     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8249
8250     SetRect( &rect, -5, -5, 5, 5 );
8251     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8252     count = 0;
8253     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8254     {
8255         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8256         else
8257         {
8258             flush_sequence();
8259             DispatchMessage( &msg );
8260             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8261             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8262             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8263             if (++count > 10) break;
8264         }
8265     }
8266     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8267
8268     trace("now without DispatchMessage\n");
8269     flush_sequence();
8270     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8271     count = 0;
8272     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8273     {
8274         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8275         else
8276         {
8277             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8278             flush_sequence();
8279             /* this will send WM_NCCPAINT just like DispatchMessage does */
8280             GetUpdateRgn( hwnd, hrgn, TRUE );
8281             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8282             DeleteObject( hrgn );
8283             GetClientRect( hwnd, &rect );
8284             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8285             ok( !count, "Got multiple WM_PAINTs\n" );
8286             if (++count > 10) break;
8287         }
8288     }
8289     DestroyWindow(hwnd);
8290 }
8291
8292
8293 static const struct message WmUser[] = {
8294     { WM_USER, sent },
8295     { 0 }
8296 };
8297
8298 struct sendmsg_info
8299 {
8300     HWND  hwnd;
8301     DWORD timeout;
8302     DWORD ret;
8303 };
8304
8305 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8306 {
8307     struct sendmsg_info *info = arg;
8308     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8309     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
8310     return 0;
8311 }
8312
8313 static void wait_for_thread( HANDLE thread )
8314 {
8315     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8316     {
8317         MSG msg;
8318         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8319     }
8320 }
8321
8322 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8323 {
8324     if (message == WM_USER) Sleep(200);
8325     return MsgCheckProcA( hwnd, message, wParam, lParam );
8326 }
8327
8328 static void test_SendMessageTimeout(void)
8329 {
8330     HANDLE thread;
8331     struct sendmsg_info info;
8332     DWORD tid;
8333
8334     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8335                                100, 100, 200, 200, 0, 0, 0, NULL);
8336     flush_events();
8337     flush_sequence();
8338
8339     info.timeout = 1000;
8340     info.ret = 0xdeadbeef;
8341     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8342     wait_for_thread( thread );
8343     CloseHandle( thread );
8344     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8345     ok_sequence( WmUser, "WmUser", FALSE );
8346
8347     info.timeout = 1;
8348     info.ret = 0xdeadbeef;
8349     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8350     Sleep(100);  /* SendMessageTimeout should time out here */
8351     wait_for_thread( thread );
8352     CloseHandle( thread );
8353     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8354     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8355
8356     /* 0 means infinite timeout */
8357     info.timeout = 0;
8358     info.ret = 0xdeadbeef;
8359     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8360     Sleep(100);
8361     wait_for_thread( thread );
8362     CloseHandle( thread );
8363     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8364     ok_sequence( WmUser, "WmUser", FALSE );
8365
8366     /* timeout is treated as signed despite the prototype */
8367     info.timeout = 0x7fffffff;
8368     info.ret = 0xdeadbeef;
8369     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8370     Sleep(100);
8371     wait_for_thread( thread );
8372     CloseHandle( thread );
8373     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8374     ok_sequence( WmUser, "WmUser", FALSE );
8375
8376     info.timeout = 0x80000000;
8377     info.ret = 0xdeadbeef;
8378     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8379     Sleep(100);
8380     wait_for_thread( thread );
8381     CloseHandle( thread );
8382     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8383     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8384
8385     /* now check for timeout during message processing */
8386     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8387     info.timeout = 100;
8388     info.ret = 0xdeadbeef;
8389     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8390     wait_for_thread( thread );
8391     CloseHandle( thread );
8392     /* we should time out but still get the message */
8393     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8394     ok_sequence( WmUser, "WmUser", FALSE );
8395
8396     DestroyWindow( info.hwnd );
8397 }
8398
8399
8400 /****************** edit message test *************************/
8401 #define ID_EDIT 0x1234
8402 static const struct message sl_edit_setfocus[] =
8403 {
8404     { HCBT_SETFOCUS, hook },
8405     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8406     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8407     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8408     { WM_SETFOCUS, sent|wparam, 0 },
8409     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8410     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8411     { WM_CTLCOLOREDIT, sent|parent },
8412     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8413     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8414     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8415     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8416     { 0 }
8417 };
8418 static const struct message ml_edit_setfocus[] =
8419 {
8420     { HCBT_SETFOCUS, hook },
8421     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8422     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8423     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8424     { WM_SETFOCUS, sent|wparam, 0 },
8425     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8426     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8427     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8428     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8429     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8430     { 0 }
8431 };
8432 static const struct message sl_edit_killfocus[] =
8433 {
8434     { HCBT_SETFOCUS, hook },
8435     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8436     { WM_KILLFOCUS, sent|wparam, 0 },
8437     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8438     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8439     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8440     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8441     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8442     { 0 }
8443 };
8444 static const struct message sl_edit_lbutton_dblclk[] =
8445 {
8446     { WM_LBUTTONDBLCLK, sent },
8447     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8448     { 0 }
8449 };
8450 static const struct message sl_edit_lbutton_down[] =
8451 {
8452     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8453     { HCBT_SETFOCUS, hook },
8454     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8455     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8456     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8457     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8458     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8459     { WM_CTLCOLOREDIT, sent|parent },
8460     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8461     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8462     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8463     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8464     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8465     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8466     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8467     { WM_CTLCOLOREDIT, sent|parent|optional },
8468     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8469     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8470     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8471     { 0 }
8472 };
8473 static const struct message ml_edit_lbutton_down[] =
8474 {
8475     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8476     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8477     { HCBT_SETFOCUS, hook },
8478     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8479     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8480     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8481     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8482     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8483     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8484     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8485     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8486     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8487     { 0 }
8488 };
8489 static const struct message sl_edit_lbutton_up[] =
8490 {
8491     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8492     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8493     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8494     { WM_CAPTURECHANGED, sent|defwinproc },
8495     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8496     { 0 }
8497 };
8498 static const struct message ml_edit_lbutton_up[] =
8499 {
8500     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8501     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8502     { WM_CAPTURECHANGED, sent|defwinproc },
8503     { 0 }
8504 };
8505
8506 static WNDPROC old_edit_proc;
8507
8508 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8509 {
8510     static long defwndproc_counter = 0;
8511     LRESULT ret;
8512     struct message msg;
8513
8514     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8515
8516     /* explicitly ignore WM_GETICON message */
8517     if (message == WM_GETICON) return 0;
8518
8519     msg.message = message;
8520     msg.flags = sent|wparam|lparam;
8521     if (defwndproc_counter) msg.flags |= defwinproc;
8522     msg.wParam = wParam;
8523     msg.lParam = lParam;
8524     add_message(&msg);
8525
8526     defwndproc_counter++;
8527     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8528     defwndproc_counter--;
8529
8530     return ret;
8531 }
8532
8533 static void subclass_edit(void)
8534 {
8535     WNDCLASSA cls;
8536
8537     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8538
8539     old_edit_proc = cls.lpfnWndProc;
8540
8541     cls.hInstance = GetModuleHandle(0);
8542     cls.lpfnWndProc = edit_hook_proc;
8543     cls.lpszClassName = "my_edit_class";
8544     UnregisterClass(cls.lpszClassName, cls.hInstance);
8545     if (!RegisterClassA(&cls)) assert(0);
8546 }
8547
8548 static void test_edit_messages(void)
8549 {
8550     HWND hwnd, parent;
8551     DWORD dlg_code;
8552
8553     subclass_edit();
8554     log_all_parent_messages++;
8555
8556     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8557                              100, 100, 200, 200, 0, 0, 0, NULL);
8558     ok (parent != 0, "Failed to create parent window\n");
8559
8560     /* test single line edit */
8561     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8562                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8563     ok(hwnd != 0, "Failed to create edit window\n");
8564
8565     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8566     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8567
8568     ShowWindow(hwnd, SW_SHOW);
8569     UpdateWindow(hwnd);
8570     SetFocus(0);
8571     flush_sequence();
8572
8573     SetFocus(hwnd);
8574     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8575
8576     SetFocus(0);
8577     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8578
8579     SetFocus(0);
8580     ReleaseCapture();
8581     flush_sequence();
8582
8583     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8584     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8585
8586     SetFocus(0);
8587     ReleaseCapture();
8588     flush_sequence();
8589
8590     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8591     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8592
8593     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8594     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8595
8596     DestroyWindow(hwnd);
8597
8598     /* test multiline edit */
8599     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8600                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8601     ok(hwnd != 0, "Failed to create edit window\n");
8602
8603     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8604     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8605        "wrong dlg_code %08x\n", dlg_code);
8606
8607     ShowWindow(hwnd, SW_SHOW);
8608     UpdateWindow(hwnd);
8609     SetFocus(0);
8610     flush_sequence();
8611
8612     SetFocus(hwnd);
8613     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8614
8615     SetFocus(0);
8616     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8617
8618     SetFocus(0);
8619     ReleaseCapture();
8620     flush_sequence();
8621
8622     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8623     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8624
8625     SetFocus(0);
8626     ReleaseCapture();
8627     flush_sequence();
8628
8629     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8630     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8631
8632     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8633     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8634
8635     DestroyWindow(hwnd);
8636     DestroyWindow(parent);
8637
8638     log_all_parent_messages--;
8639 }
8640
8641 /**************************** End of Edit test ******************************/
8642
8643 static const struct message WmKeyDownSkippedSeq[] =
8644 {
8645     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8646     { 0 }
8647 };
8648 static const struct message WmKeyUpSkippedSeq[] =
8649 {
8650     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8651     { 0 }
8652 };
8653
8654 #define EV_START_STOP 0
8655 #define EV_SENDMSG 1
8656 #define EV_ACK 2
8657
8658 struct peekmsg_info
8659 {
8660     HWND  hwnd;
8661     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8662 };
8663
8664 static DWORD CALLBACK send_msg_thread_2(void *param)
8665 {
8666     DWORD ret;
8667     struct peekmsg_info *info = param;
8668
8669     trace("thread: waiting for start\n");
8670     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8671     trace("thread: looping\n");
8672
8673     while (1)
8674     {
8675         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8676
8677         switch (ret)
8678         {
8679         case WAIT_OBJECT_0 + EV_START_STOP:
8680             trace("thread: exiting\n");
8681             return 0;
8682
8683         case WAIT_OBJECT_0 + EV_SENDMSG:
8684             trace("thread: sending message\n");
8685             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8686             SetEvent(info->hevent[EV_ACK]);
8687             break;
8688
8689         default:
8690             trace("unexpected return: %04x\n", ret);
8691             assert(0);
8692             break;
8693         }
8694     }
8695     return 0;
8696 }
8697
8698 static void test_PeekMessage(void)
8699 {
8700     MSG msg;
8701     HANDLE hthread;
8702     DWORD tid, qstatus;
8703     UINT qs_all_input = QS_ALLINPUT;
8704     UINT qs_input = QS_INPUT;
8705     BOOL ret;
8706     struct peekmsg_info info;
8707
8708     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8709                               100, 100, 200, 200, 0, 0, 0, NULL);
8710     assert(info.hwnd);
8711     ShowWindow(info.hwnd, SW_SHOW);
8712     UpdateWindow(info.hwnd);
8713     SetFocus(info.hwnd);
8714
8715     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8716     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8717     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8718
8719     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8720     Sleep(100);
8721
8722     trace("signalling to start looping\n");
8723     SetEvent(info.hevent[EV_START_STOP]);
8724
8725     flush_events();
8726     flush_sequence();
8727
8728     SetLastError(0xdeadbeef);
8729     qstatus = GetQueueStatus(qs_all_input);
8730     if (GetLastError() == ERROR_INVALID_FLAGS)
8731     {
8732         trace("QS_RAWINPUT not supported on this platform\n");
8733         qs_all_input &= ~QS_RAWINPUT;
8734         qs_input &= ~QS_RAWINPUT;
8735     }
8736     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8737
8738     trace("signalling to send message\n");
8739     SetEvent(info.hevent[EV_SENDMSG]);
8740     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8741
8742     /* pass invalid QS_xxxx flags */
8743     SetLastError(0xdeadbeef);
8744     qstatus = GetQueueStatus(0xffffffff);
8745     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8746     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8747
8748     qstatus = GetQueueStatus(qs_all_input);
8749     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8750        "wrong qstatus %08x\n", qstatus);
8751
8752     msg.message = 0;
8753     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8754     ok(!ret,
8755        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8756         msg.message);
8757     ok_sequence(WmUser, "WmUser", FALSE);
8758
8759     qstatus = GetQueueStatus(qs_all_input);
8760     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8761
8762     keybd_event('N', 0, 0, 0);
8763     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8764     qstatus = GetQueueStatus(qs_all_input);
8765     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8766        "wrong qstatus %08x\n", qstatus);
8767
8768     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8769     qstatus = GetQueueStatus(qs_all_input);
8770     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8771        "wrong qstatus %08x\n", qstatus);
8772
8773     InvalidateRect(info.hwnd, NULL, FALSE);
8774     qstatus = GetQueueStatus(qs_all_input);
8775     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8776        "wrong qstatus %08x\n", qstatus);
8777
8778     trace("signalling to send message\n");
8779     SetEvent(info.hevent[EV_SENDMSG]);
8780     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8781
8782     qstatus = GetQueueStatus(qs_all_input);
8783     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8784        "wrong qstatus %08x\n", qstatus);
8785
8786     msg.message = 0;
8787     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8788     ok(!ret,
8789        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8790         msg.message);
8791     ok_sequence(WmUser, "WmUser", FALSE);
8792
8793     qstatus = GetQueueStatus(qs_all_input);
8794     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8795        "wrong qstatus %08x\n", qstatus);
8796
8797     trace("signalling to send message\n");
8798     SetEvent(info.hevent[EV_SENDMSG]);
8799     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8800
8801     qstatus = GetQueueStatus(qs_all_input);
8802     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8803        "wrong qstatus %08x\n", qstatus);
8804
8805     msg.message = 0;
8806     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8807     ok(!ret,
8808        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8809         msg.message);
8810     ok_sequence(WmUser, "WmUser", FALSE);
8811
8812     qstatus = GetQueueStatus(qs_all_input);
8813     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8814        "wrong qstatus %08x\n", qstatus);
8815
8816     msg.message = 0;
8817     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8818     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8819        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8820        ret, msg.message, msg.wParam);
8821     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8822
8823     qstatus = GetQueueStatus(qs_all_input);
8824     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8825        "wrong qstatus %08x\n", qstatus);
8826
8827     msg.message = 0;
8828     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8829     ok(!ret,
8830        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8831         msg.message);
8832     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8833
8834     qstatus = GetQueueStatus(qs_all_input);
8835     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8836        "wrong qstatus %08x\n", qstatus);
8837
8838     msg.message = 0;
8839     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8840     ok(ret && msg.message == WM_PAINT,
8841        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8842     DispatchMessageA(&msg);
8843     ok_sequence(WmPaint, "WmPaint", FALSE);
8844
8845     qstatus = GetQueueStatus(qs_all_input);
8846     ok(qstatus == MAKELONG(0, QS_KEY),
8847        "wrong qstatus %08x\n", qstatus);
8848
8849     msg.message = 0;
8850     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8851     ok(!ret,
8852        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8853         msg.message);
8854     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8855
8856     qstatus = GetQueueStatus(qs_all_input);
8857     ok(qstatus == MAKELONG(0, QS_KEY),
8858        "wrong qstatus %08x\n", qstatus);
8859
8860     trace("signalling to send message\n");
8861     SetEvent(info.hevent[EV_SENDMSG]);
8862     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8863
8864     qstatus = GetQueueStatus(qs_all_input);
8865     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8866        "wrong qstatus %08x\n", qstatus);
8867
8868     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8869
8870     qstatus = GetQueueStatus(qs_all_input);
8871     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8872        "wrong qstatus %08x\n", qstatus);
8873
8874     msg.message = 0;
8875     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8876     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8877        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8878        ret, msg.message, msg.wParam);
8879     ok_sequence(WmUser, "WmUser", FALSE);
8880
8881     qstatus = GetQueueStatus(qs_all_input);
8882     ok(qstatus == MAKELONG(0, QS_KEY),
8883        "wrong qstatus %08x\n", qstatus);
8884
8885     msg.message = 0;
8886     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8887     ok(!ret,
8888        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8889         msg.message);
8890     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8891
8892     qstatus = GetQueueStatus(qs_all_input);
8893     ok(qstatus == MAKELONG(0, QS_KEY),
8894        "wrong qstatus %08x\n", qstatus);
8895
8896     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8897
8898     qstatus = GetQueueStatus(qs_all_input);
8899     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8900        "wrong qstatus %08x\n", qstatus);
8901
8902     trace("signalling to send message\n");
8903     SetEvent(info.hevent[EV_SENDMSG]);
8904     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8905
8906     qstatus = GetQueueStatus(qs_all_input);
8907     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8908        "wrong qstatus %08x\n", qstatus);
8909
8910     msg.message = 0;
8911     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8912     ok(!ret,
8913        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8914         msg.message);
8915     ok_sequence(WmUser, "WmUser", FALSE);
8916
8917     qstatus = GetQueueStatus(qs_all_input);
8918     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8919        "wrong qstatus %08x\n", qstatus);
8920
8921     msg.message = 0;
8922     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8923         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8924     else /* workaround for a missing QS_RAWINPUT support */
8925         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8926     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8927        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8928        ret, msg.message, msg.wParam);
8929     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8930
8931     qstatus = GetQueueStatus(qs_all_input);
8932     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8933        "wrong qstatus %08x\n", qstatus);
8934
8935     msg.message = 0;
8936     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8937         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8938     else /* workaround for a missing QS_RAWINPUT support */
8939         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8940     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8941        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8942        ret, msg.message, msg.wParam);
8943     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8944
8945     qstatus = GetQueueStatus(qs_all_input);
8946     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8947        "wrong qstatus %08x\n", qstatus);
8948
8949     msg.message = 0;
8950     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8951     ok(!ret,
8952        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8953         msg.message);
8954     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8955
8956     qstatus = GetQueueStatus(qs_all_input);
8957     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8958        "wrong qstatus %08x\n", qstatus);
8959
8960     msg.message = 0;
8961     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8962     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8963        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8964        ret, msg.message, msg.wParam);
8965     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8966
8967     qstatus = GetQueueStatus(qs_all_input);
8968     ok(qstatus == 0,
8969        "wrong qstatus %08x\n", qstatus);
8970
8971     msg.message = 0;
8972     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8973     ok(!ret,
8974        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8975         msg.message);
8976     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8977
8978     qstatus = GetQueueStatus(qs_all_input);
8979     ok(qstatus == 0,
8980        "wrong qstatus %08x\n", qstatus);
8981
8982     /* test whether presence of the quit flag in the queue affects
8983      * the queue state
8984      */
8985     PostQuitMessage(0x1234abcd);
8986
8987     qstatus = GetQueueStatus(qs_all_input);
8988     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8989        "wrong qstatus %08x\n", qstatus);
8990
8991     PostMessageA(info.hwnd, WM_USER, 0, 0);
8992
8993     qstatus = GetQueueStatus(qs_all_input);
8994     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8995        "wrong qstatus %08x\n", qstatus);
8996
8997     msg.message = 0;
8998     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8999     ok(ret && msg.message == WM_USER,
9000        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9001     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9002
9003     qstatus = GetQueueStatus(qs_all_input);
9004     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9005        "wrong qstatus %08x\n", qstatus);
9006
9007     msg.message = 0;
9008     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9009     ok(ret && msg.message == WM_QUIT,
9010        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9011     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9012     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9013     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9014
9015     qstatus = GetQueueStatus(qs_all_input);
9016 todo_wine {
9017     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9018        "wrong qstatus %08x\n", qstatus);
9019 }
9020
9021     msg.message = 0;
9022     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9023     ok(!ret,
9024        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9025         msg.message);
9026     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9027
9028     qstatus = GetQueueStatus(qs_all_input);
9029     ok(qstatus == 0,
9030        "wrong qstatus %08x\n", qstatus);
9031
9032     trace("signalling to exit\n");
9033     SetEvent(info.hevent[EV_START_STOP]);
9034
9035     WaitForSingleObject(hthread, INFINITE);
9036
9037     CloseHandle(hthread);
9038     CloseHandle(info.hevent[0]);
9039     CloseHandle(info.hevent[1]);
9040     CloseHandle(info.hevent[2]);
9041
9042     DestroyWindow(info.hwnd);
9043 }
9044
9045 static void wait_move_event(HWND hwnd, int x, int y)
9046 {
9047     MSG msg;
9048     DWORD time;
9049     BOOL  ret;
9050     int go = 0;
9051
9052     time = GetTickCount();
9053     while (GetTickCount() - time < 200 && !go) {
9054         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9055         go  = ret && msg.pt.x > x && msg.pt.y > y;
9056     }
9057 }
9058
9059 #define STEP 20
9060 static void test_PeekMessage2(void)
9061 {
9062     HWND hwnd;
9063     BOOL ret;
9064     MSG msg;
9065     UINT message;
9066     DWORD time1, time2, time3;
9067     int x1, y1, x2, y2, x3, y3;
9068     POINT pos;
9069
9070     time1 = time2 = time3 = 0;
9071     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9072
9073     /* Initialise window and make sure it is ready for events */
9074     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9075                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9076     assert(hwnd);
9077     trace("Window for test_PeekMessage2 %p\n", hwnd);
9078     ShowWindow(hwnd, SW_SHOW);
9079     UpdateWindow(hwnd);
9080     SetFocus(hwnd);
9081     GetCursorPos(&pos);
9082     SetCursorPos(100, 100);
9083     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9084     flush_events();
9085
9086     /* Do initial mousemove, wait until we can see it
9087        and then do our test peek with PM_NOREMOVE. */
9088     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9089     wait_move_event(hwnd, 80, 80);
9090
9091     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9092     ok(ret, "no message available\n");
9093     if (ret) {
9094         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9095         message = msg.message;
9096         time1 = msg.time;
9097         x1 = msg.pt.x;
9098         y1 = msg.pt.y;
9099         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9100     }
9101
9102     /* Allow time to advance a bit, and then simulate the user moving their
9103      * mouse around. After that we peek again with PM_NOREMOVE.
9104      * Although the previous mousemove message was never removed, the
9105      * mousemove we now peek should reflect the recent mouse movements
9106      * because the input queue will merge the move events. */
9107     Sleep(2);
9108     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9109     wait_move_event(hwnd, x1, y1);
9110
9111     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9112     ok(ret, "no message available\n");
9113     if (ret) {
9114         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9115         message = msg.message;
9116         time2 = msg.time;
9117         x2 = msg.pt.x;
9118         y2 = msg.pt.y;
9119         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9120         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9121         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9122     }
9123
9124     /* Have another go, to drive the point home */
9125     Sleep(2);
9126     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9127     wait_move_event(hwnd, x2, y2);
9128
9129     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9130     ok(ret, "no message available\n");
9131     if (ret) {
9132         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9133         message = msg.message;
9134         time3 = msg.time;
9135         x3 = msg.pt.x;
9136         y3 = msg.pt.y;
9137         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9138         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9139         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9140     }
9141
9142     DestroyWindow(hwnd);
9143     SetCursorPos(pos.x, pos.y);
9144     flush_events();
9145 }
9146
9147 static void test_quit_message(void)
9148 {
9149     MSG msg;
9150     BOOL ret;
9151
9152     /* test using PostQuitMessage */
9153     PostQuitMessage(0xbeef);
9154
9155     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9156     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9157     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9158     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9159
9160     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9161     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9162
9163     ret = GetMessage(&msg, NULL, 0, 0);
9164     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9165     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9166
9167     /* note: WM_QUIT message received after WM_USER message */
9168     ret = GetMessage(&msg, NULL, 0, 0);
9169     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9170     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9171     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9172
9173     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9174     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9175
9176     /* now test with PostThreadMessage - different behaviour! */
9177     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9178
9179     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9180     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9181     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9182     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9183
9184     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9185     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9186
9187     /* note: we receive the WM_QUIT message first this time */
9188     ret = GetMessage(&msg, NULL, 0, 0);
9189     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9190     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9191     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9192
9193     ret = GetMessage(&msg, NULL, 0, 0);
9194     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9195     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9196 }
9197
9198 static const struct message WmMouseHoverSeq[] = {
9199     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9200     { WM_MOUSEACTIVATE, sent|optional },
9201     { WM_TIMER, sent|optional }, /* XP sends it */
9202     { WM_SYSTIMER, sent },
9203     { WM_MOUSEHOVER, sent|wparam, 0 },
9204     { 0 }
9205 };
9206
9207 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9208 {
9209     MSG msg;
9210     DWORD start_ticks, end_ticks;
9211
9212     start_ticks = GetTickCount();
9213     /* add some deviation (5%) to cover not expected delays */
9214     start_ticks += timeout / 20;
9215
9216     do
9217     {
9218         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9219         {
9220             /* Timer proc messages are not dispatched to the window proc,
9221              * and therefore not logged.
9222              */
9223             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9224             {
9225                 struct message s_msg;
9226
9227                 s_msg.message = msg.message;
9228                 s_msg.flags = sent|wparam|lparam;
9229                 s_msg.wParam = msg.wParam;
9230                 s_msg.lParam = msg.lParam;
9231                 add_message(&s_msg);
9232             }
9233             DispatchMessage(&msg);
9234         }
9235
9236         end_ticks = GetTickCount();
9237
9238         /* inject WM_MOUSEMOVE to see how it changes tracking */
9239         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9240         {
9241             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9242             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9243
9244             inject_mouse_move = FALSE;
9245         }
9246     } while (start_ticks + timeout >= end_ticks);
9247 }
9248
9249 static void test_TrackMouseEvent(void)
9250 {
9251     TRACKMOUSEEVENT tme;
9252     BOOL ret;
9253     HWND hwnd, hchild;
9254     RECT rc_parent, rc_child;
9255     UINT default_hover_time, hover_width = 0, hover_height = 0;
9256
9257 #define track_hover(track_hwnd, track_hover_time) \
9258     tme.cbSize = sizeof(tme); \
9259     tme.dwFlags = TME_HOVER; \
9260     tme.hwndTrack = track_hwnd; \
9261     tme.dwHoverTime = track_hover_time; \
9262     SetLastError(0xdeadbeef); \
9263     ret = pTrackMouseEvent(&tme); \
9264     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9265
9266 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9267     tme.cbSize = sizeof(tme); \
9268     tme.dwFlags = TME_QUERY; \
9269     tme.hwndTrack = (HWND)0xdeadbeef; \
9270     tme.dwHoverTime = 0xdeadbeef; \
9271     SetLastError(0xdeadbeef); \
9272     ret = pTrackMouseEvent(&tme); \
9273     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9274     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9275     ok(tme.dwFlags == (expected_track_flags), \
9276        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9277     ok(tme.hwndTrack == (expected_track_hwnd), \
9278        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9279     ok(tme.dwHoverTime == (expected_hover_time), \
9280        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9281
9282 #define track_hover_cancel(track_hwnd) \
9283     tme.cbSize = sizeof(tme); \
9284     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9285     tme.hwndTrack = track_hwnd; \
9286     tme.dwHoverTime = 0xdeadbeef; \
9287     SetLastError(0xdeadbeef); \
9288     ret = pTrackMouseEvent(&tme); \
9289     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9290
9291     default_hover_time = 0xdeadbeef;
9292     SetLastError(0xdeadbeef);
9293     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9294     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9295     if (!ret) default_hover_time = 400;
9296     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9297
9298     SetLastError(0xdeadbeef);
9299     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9300     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9301     if (!ret) hover_width = 4;
9302     SetLastError(0xdeadbeef);
9303     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9304     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9305     if (!ret) hover_height = 4;
9306     trace("hover rect is %u x %d\n", hover_width, hover_height);
9307
9308     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9309                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9310                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9311                           NULL, NULL, 0);
9312     assert(hwnd);
9313
9314     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9315                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9316                           50, 50, 200, 200, hwnd,
9317                           NULL, NULL, 0);
9318     assert(hchild);
9319
9320     flush_events();
9321     flush_sequence();
9322
9323     tme.cbSize = 0;
9324     tme.dwFlags = TME_QUERY;
9325     tme.hwndTrack = (HWND)0xdeadbeef;
9326     tme.dwHoverTime = 0xdeadbeef;
9327     SetLastError(0xdeadbeef);
9328     ret = pTrackMouseEvent(&tme);
9329     ok(!ret, "TrackMouseEvent should fail\n");
9330     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
9331
9332     tme.cbSize = sizeof(tme);
9333     tme.dwFlags = TME_HOVER;
9334     tme.hwndTrack = (HWND)0xdeadbeef;
9335     tme.dwHoverTime = 0xdeadbeef;
9336     SetLastError(0xdeadbeef);
9337     ret = pTrackMouseEvent(&tme);
9338     ok(!ret, "TrackMouseEvent should fail\n");
9339     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9340
9341     tme.cbSize = sizeof(tme);
9342     tme.dwFlags = TME_HOVER | TME_CANCEL;
9343     tme.hwndTrack = (HWND)0xdeadbeef;
9344     tme.dwHoverTime = 0xdeadbeef;
9345     SetLastError(0xdeadbeef);
9346     ret = pTrackMouseEvent(&tme);
9347     ok(!ret, "TrackMouseEvent should fail\n");
9348     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9349
9350     GetWindowRect(hwnd, &rc_parent);
9351     GetWindowRect(hchild, &rc_child);
9352     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9353
9354     /* Process messages so that the system updates its internal current
9355      * window and hittest, otherwise TrackMouseEvent calls don't have any
9356      * effect.
9357      */
9358     flush_events();
9359     flush_sequence();
9360
9361     track_query(0, NULL, 0);
9362     track_hover(hchild, 0);
9363     track_query(0, NULL, 0);
9364
9365     flush_events();
9366     flush_sequence();
9367
9368     track_hover(hwnd, 0);
9369     track_query(TME_HOVER, hwnd, default_hover_time);
9370
9371     pump_msg_loop_timeout(default_hover_time, FALSE);
9372     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9373
9374     track_query(0, NULL, 0);
9375
9376     track_hover(hwnd, HOVER_DEFAULT);
9377     track_query(TME_HOVER, hwnd, default_hover_time);
9378
9379     Sleep(default_hover_time / 2);
9380     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9381     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9382
9383     track_query(TME_HOVER, hwnd, default_hover_time);
9384
9385     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9386     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9387
9388     track_query(0, NULL, 0);
9389
9390     track_hover(hwnd, HOVER_DEFAULT);
9391     track_query(TME_HOVER, hwnd, default_hover_time);
9392
9393     pump_msg_loop_timeout(default_hover_time, TRUE);
9394     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9395
9396     track_query(0, NULL, 0);
9397
9398     track_hover(hwnd, HOVER_DEFAULT);
9399     track_query(TME_HOVER, hwnd, default_hover_time);
9400     track_hover_cancel(hwnd);
9401
9402     DestroyWindow(hwnd);
9403
9404 #undef track_hover
9405 #undef track_query
9406 #undef track_hover_cancel
9407 }
9408
9409
9410 static const struct message WmSetWindowRgn[] = {
9411     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9412     { WM_NCCALCSIZE, sent|wparam, 1 },
9413     { WM_NCPAINT, sent }, /* wparam != 1 */
9414     { WM_GETTEXT, sent|defwinproc|optional },
9415     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9416     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9417     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9418     { 0 }
9419 };
9420
9421 static const struct message WmSetWindowRgn_no_redraw[] = {
9422     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9423     { WM_NCCALCSIZE, sent|wparam, 1 },
9424     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9425     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9426     { 0 }
9427 };
9428
9429 static const struct message WmSetWindowRgn_clear[] = {
9430     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9431     { WM_NCCALCSIZE, sent|wparam, 1 },
9432     { WM_NCPAINT, sent }, /* wparam != 1 */
9433     { WM_GETTEXT, sent|defwinproc|optional },
9434     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9435     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9436     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9437     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9438     { WM_GETTEXT, sent|defwinproc|optional },
9439     { WM_ERASEBKGND, sent|optional },
9440     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9441     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9442     { 0 }
9443 };
9444
9445 static void test_SetWindowRgn(void)
9446 {
9447     HRGN hrgn;
9448     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9449                                 100, 100, 200, 200, 0, 0, 0, NULL);
9450     ok( hwnd != 0, "Failed to create overlapped window\n" );
9451
9452     ShowWindow( hwnd, SW_SHOW );
9453     UpdateWindow( hwnd );
9454     flush_events();
9455     flush_sequence();
9456
9457     trace("testing SetWindowRgn\n");
9458     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9459     SetWindowRgn( hwnd, hrgn, TRUE );
9460     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9461
9462     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9463     SetWindowRgn( hwnd, hrgn, FALSE );
9464     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9465
9466     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9467     SetWindowRgn( hwnd, hrgn, TRUE );
9468     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9469
9470     SetWindowRgn( hwnd, 0, TRUE );
9471     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9472
9473     DestroyWindow( hwnd );
9474 }
9475
9476 /*************************** ShowWindow() test ******************************/
9477 static const struct message WmShowNormal[] = {
9478     { WM_SHOWWINDOW, sent|wparam, 1 },
9479     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9480     { HCBT_ACTIVATE, hook },
9481     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9482     { HCBT_SETFOCUS, hook },
9483     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9484     { 0 }
9485 };
9486 static const struct message WmShow[] = {
9487     { WM_SHOWWINDOW, sent|wparam, 1 },
9488     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9489     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9490     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9491     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9493     { 0 }
9494 };
9495 static const struct message WmShowNoActivate_1[] = {
9496     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9497     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9498     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9499     { WM_MOVE, sent|defwinproc },
9500     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9501     { 0 }
9502 };
9503 static const struct message WmShowNoActivate_2[] = {
9504     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9505     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9506     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9507     { WM_MOVE, sent|defwinproc },
9508     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9509     { HCBT_SETFOCUS, hook|optional },
9510     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9511     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9512     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9513     { 0 }
9514 };
9515 static const struct message WmShowNA_1[] = {
9516     { WM_SHOWWINDOW, sent|wparam, 1 },
9517     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9518     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9519     { 0 }
9520 };
9521 static const struct message WmShowNA_2[] = {
9522     { WM_SHOWWINDOW, sent|wparam, 1 },
9523     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9524     { 0 }
9525 };
9526 static const struct message WmRestore_1[] = {
9527     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9528     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9529     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9530     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9531     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9532     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9533     { WM_MOVE, sent|defwinproc },
9534     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9535     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9536     { 0 }
9537 };
9538 static const struct message WmRestore_2[] = {
9539     { WM_SHOWWINDOW, sent|wparam, 1 },
9540     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9541     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9542     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9543     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9544     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9545     { 0 }
9546 };
9547 static const struct message WmRestore_3[] = {
9548     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9549     { WM_GETMINMAXINFO, sent },
9550     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9551     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9552     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9553     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9554     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9555     { WM_MOVE, sent|defwinproc },
9556     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9557     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9558     { 0 }
9559 };
9560 static const struct message WmRestore_4[] = {
9561     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9562     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9563     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9564     { WM_MOVE, sent|defwinproc },
9565     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9566     { 0 }
9567 };
9568 static const struct message WmRestore_5[] = {
9569     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9570     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9571     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9572     { WM_MOVE, sent|defwinproc },
9573     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9574     { 0 }
9575 };
9576 static const struct message WmHide_1[] = {
9577     { WM_SHOWWINDOW, sent|wparam, 0 },
9578     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9579     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9580     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9581     { 0 }
9582 };
9583 static const struct message WmHide_2[] = {
9584     { WM_SHOWWINDOW, sent|wparam, 0 },
9585     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9586     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9587     { 0 }
9588 };
9589 static const struct message WmHide_3[] = {
9590     { WM_SHOWWINDOW, sent|wparam, 0 },
9591     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9592     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9593     { HCBT_SETFOCUS, hook },
9594     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9595     { 0 }
9596 };
9597 static const struct message WmShowMinimized_1[] = {
9598     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9599     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9600     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9601     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9602     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9603     { WM_MOVE, sent|defwinproc },
9604     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9605     { 0 }
9606 };
9607 static const struct message WmMinimize_1[] = {
9608     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9609     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9610     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9611     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9612     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9613     { WM_MOVE, sent|defwinproc },
9614     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9615     { 0 }
9616 };
9617 static const struct message WmMinimize_2[] = {
9618     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9619     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9620     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9621     { WM_MOVE, sent|defwinproc },
9622     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9623     { 0 }
9624 };
9625 static const struct message WmMinimize_3[] = {
9626     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9627     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9628     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9629     { WM_MOVE, sent|defwinproc },
9630     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9631     { 0 }
9632 };
9633 static const struct message WmShowMinNoActivate[] = {
9634     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9635     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9636     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9637     { 0 }
9638 };
9639 static const struct message WmMinMax_1[] = {
9640     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9641     { 0 }
9642 };
9643 static const struct message WmMinMax_2[] = {
9644     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9645     { 0 }
9646 };
9647 static const struct message WmMinMax_3[] = {
9648     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9649     { 0 }
9650 };
9651 static const struct message WmMinMax_4[] = {
9652     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9653     { 0 }
9654 };
9655 static const struct message WmShowMaximized_1[] = {
9656     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9657     { WM_GETMINMAXINFO, sent },
9658     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9659     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9660     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9661     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9662     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9663     { WM_MOVE, sent|defwinproc },
9664     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9665     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9666     { 0 }
9667 };
9668 static const struct message WmShowMaximized_2[] = {
9669     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9670     { WM_GETMINMAXINFO, sent },
9671     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
9672     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9673     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9674     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9675     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9676     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9677     { WM_MOVE, sent|defwinproc },
9678     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9679     { HCBT_SETFOCUS, hook },
9680     { 0 }
9681 };
9682 static const struct message WmShowMaximized_3[] = {
9683     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9684     { WM_GETMINMAXINFO, sent },
9685     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9686     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9687     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9688     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9689     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9690     { WM_MOVE, sent|defwinproc },
9691     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9692     { 0 }
9693 };
9694
9695 static void test_ShowWindow(void)
9696 {
9697     /* ShowWindow commands in random order */
9698     static const struct
9699     {
9700         INT cmd; /* ShowWindow command */
9701         LPARAM ret; /* ShowWindow return value */
9702         DWORD style; /* window style after the command */
9703         const struct message *msg; /* message sequence the command produces */
9704         BOOL todo_msg; /* message sequence doesn't match what Wine does */
9705     } sw[] =
9706     {
9707 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9708 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9709 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9710 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9711 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9712 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9713 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9714 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9715 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9716 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9717 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9718 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9719 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9720 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9721 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9722 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9723 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9724 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9725 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9726 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9727 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9728 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9729 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9730 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9731 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9732 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9733 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9734 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9735 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9736 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9737 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9738 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
9739 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9740 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
9741 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
9742 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9743 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9744 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9745 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9746 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
9747 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9748 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9749 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9750 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9751 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9752 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9753 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9754 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9755 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9756 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9757 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9758 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9759 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9760 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
9761 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9762 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9763 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9764     };
9765     HWND hwnd;
9766     DWORD style;
9767     LPARAM ret;
9768     INT i;
9769
9770 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9771     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9772                           120, 120, 90, 90,
9773                           0, 0, 0, NULL);
9774     assert(hwnd);
9775
9776     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9777     ok(style == 0, "expected style 0, got %08x\n", style);
9778
9779     flush_events();
9780     flush_sequence();
9781
9782     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9783     {
9784         static const char * const sw_cmd_name[13] =
9785         {
9786             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9787             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9788             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9789             "SW_NORMALNA" /* 0xCC */
9790         };
9791         char comment[64];
9792         INT idx; /* index into the above array of names */
9793
9794         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9795
9796         style = GetWindowLong(hwnd, GWL_STYLE);
9797         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9798         ret = ShowWindow(hwnd, sw[i].cmd);
9799         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9800         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9801         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9802
9803         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9804         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9805
9806         flush_events();
9807         flush_sequence();
9808     }
9809
9810     DestroyWindow(hwnd);
9811 }
9812
9813 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9814 {
9815     struct message msg;
9816
9817     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9818
9819     switch (message)
9820     {
9821     case WM_WINDOWPOSCHANGING:
9822     case WM_WINDOWPOSCHANGED:
9823     {
9824         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9825
9826         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9827         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
9828               winpos->hwnd, winpos->hwndInsertAfter,
9829               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9830         dump_winpos_flags(winpos->flags);
9831
9832         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9833          * in the high word for internal purposes
9834          */
9835         wParam = winpos->flags & 0xffff;
9836         /* We are not interested in the flags that don't match under XP and Win9x */
9837         wParam &= ~(SWP_NOZORDER);
9838         break;
9839     }
9840
9841     /* explicitly ignore WM_GETICON message */
9842     case WM_GETICON:
9843         return 0;
9844     }
9845
9846     msg.message = message;
9847     msg.flags = sent|wparam|lparam;
9848     msg.wParam = wParam;
9849     msg.lParam = lParam;
9850     add_message(&msg);
9851
9852     /* calling DefDlgProc leads to a recursion under XP */
9853
9854     switch (message)
9855     {
9856     case WM_INITDIALOG:
9857     case WM_GETDLGCODE:
9858         return 0;
9859     }
9860     return 1;
9861 }
9862
9863 static const struct message WmDefDlgSetFocus_1[] = {
9864     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9865     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9866     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9867     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9868     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9869     { HCBT_SETFOCUS, hook },
9870     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9871     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9872     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9873     { WM_SETFOCUS, sent|wparam, 0 },
9874     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9875     { WM_CTLCOLOREDIT, sent },
9876     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9877     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9878     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9879     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9880     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9881     { 0 }
9882 };
9883 static const struct message WmDefDlgSetFocus_2[] = {
9884     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9885     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9886     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9887     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9888     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9889     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9890     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9891     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9892     { 0 }
9893 };
9894 /* Creation of a dialog */
9895 static const struct message WmCreateDialogParamSeq_1[] = {
9896     { HCBT_CREATEWND, hook },
9897     { WM_NCCREATE, sent },
9898     { WM_NCCALCSIZE, sent|wparam, 0 },
9899     { WM_CREATE, sent },
9900     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9901     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9902     { WM_MOVE, sent },
9903     { WM_SETFONT, sent },
9904     { WM_INITDIALOG, sent },
9905     { WM_CHANGEUISTATE, sent|optional },
9906     { 0 }
9907 };
9908 /* Creation of a dialog */
9909 static const struct message WmCreateDialogParamSeq_2[] = {
9910     { HCBT_CREATEWND, hook },
9911     { WM_NCCREATE, sent },
9912     { WM_NCCALCSIZE, sent|wparam, 0 },
9913     { WM_CREATE, sent },
9914     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9915     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9916     { WM_MOVE, sent },
9917     { WM_CHANGEUISTATE, sent|optional },
9918     { 0 }
9919 };
9920
9921 static void test_dialog_messages(void)
9922 {
9923     WNDCLASS cls;
9924     HWND hdlg, hedit1, hedit2, hfocus;
9925     LRESULT ret;
9926
9927 #define set_selection(hctl, start, end) \
9928     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9929     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9930
9931 #define check_selection(hctl, start, end) \
9932     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9933     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9934
9935     subclass_edit();
9936
9937     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9938                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9939                           0, 0, 100, 100, 0, 0, 0, NULL);
9940     ok(hdlg != 0, "Failed to create custom dialog window\n");
9941
9942     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9943                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9944                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9945     ok(hedit1 != 0, "Failed to create edit control\n");
9946     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9947                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9948                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9949     ok(hedit2 != 0, "Failed to create edit control\n");
9950
9951     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9952     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9953
9954     hfocus = GetFocus();
9955     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9956
9957     SetFocus(hedit2);
9958     hfocus = GetFocus();
9959     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9960
9961     check_selection(hedit1, 0, 0);
9962     check_selection(hedit2, 0, 0);
9963
9964     set_selection(hedit2, 0, -1);
9965     check_selection(hedit2, 0, 3);
9966
9967     SetFocus(0);
9968     hfocus = GetFocus();
9969     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9970
9971     flush_sequence();
9972     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9973     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9974     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9975
9976     hfocus = GetFocus();
9977     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9978
9979     check_selection(hedit1, 0, 5);
9980     check_selection(hedit2, 0, 3);
9981
9982     flush_sequence();
9983     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9984     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9985     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9986
9987     hfocus = GetFocus();
9988     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9989
9990     check_selection(hedit1, 0, 5);
9991     check_selection(hedit2, 0, 3);
9992
9993     EndDialog(hdlg, 0);
9994     DestroyWindow(hedit1);
9995     DestroyWindow(hedit2);
9996     DestroyWindow(hdlg);
9997     flush_sequence();
9998
9999 #undef set_selection
10000 #undef check_selection
10001
10002     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10003     cls.lpszClassName = "MyDialogClass";
10004     cls.hInstance = GetModuleHandle(0);
10005     /* need a cast since a dlgproc is used as a wndproc */
10006     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10007     if (!RegisterClass(&cls)) assert(0);
10008
10009     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10010     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10011     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10012     EndDialog(hdlg, 0);
10013     DestroyWindow(hdlg);
10014     flush_sequence();
10015
10016     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10017     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10018     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10019     EndDialog(hdlg, 0);
10020     DestroyWindow(hdlg);
10021     flush_sequence();
10022
10023     UnregisterClass(cls.lpszClassName, cls.hInstance);
10024 }
10025
10026 static void test_nullCallback(void)
10027 {
10028     HWND hwnd;
10029
10030     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10031                            100, 100, 200, 200, 0, 0, 0, NULL);
10032     ok (hwnd != 0, "Failed to create overlapped window\n");
10033
10034     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10035     flush_events();
10036     DestroyWindow(hwnd);
10037 }
10038
10039 /* SetActiveWindow( 0 ) hwnd visible */
10040 static const struct message SetActiveWindowSeq0[] =
10041 {
10042     { HCBT_ACTIVATE, hook },
10043     { WM_NCACTIVATE, sent|wparam, 0 },
10044     { WM_GETTEXT, sent|defwinproc|optional },
10045     { WM_ACTIVATE, sent|wparam, 0 },
10046     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10047     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10048     { WM_NCACTIVATE, sent|wparam, 1 },
10049     { WM_GETTEXT, sent|defwinproc|optional },
10050     { WM_ACTIVATE, sent|wparam, 1 },
10051     { HCBT_SETFOCUS, hook },
10052     { WM_KILLFOCUS, sent|defwinproc },
10053     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10054     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10055     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10056     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10057     { WM_SETFOCUS, sent|defwinproc },
10058     { 0 }
10059 };
10060 /* SetActiveWindow( hwnd ) hwnd visible */
10061 static const struct message SetActiveWindowSeq1[] =
10062 {
10063     { 0 }
10064 };
10065 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10066 static const struct message SetActiveWindowSeq2[] =
10067 {
10068     { HCBT_ACTIVATE, hook },
10069     { WM_NCACTIVATE, sent|wparam, 0 },
10070     { WM_GETTEXT, sent|defwinproc|optional },
10071     { WM_ACTIVATE, sent|wparam, 0 },
10072     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10073     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10074     { WM_NCPAINT, sent|optional },
10075     { WM_GETTEXT, sent|defwinproc|optional },
10076     { WM_ERASEBKGND, sent|optional },
10077     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10078     { WM_NCACTIVATE, sent|wparam, 1 },
10079     { WM_ACTIVATE, sent|wparam, 1 },
10080     { HCBT_SETFOCUS, hook },
10081     { WM_KILLFOCUS, sent|defwinproc },
10082     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10083     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10084     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10085     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10086     { WM_SETFOCUS, sent|defwinproc },
10087     { 0 }
10088 };
10089
10090 /* SetActiveWindow( hwnd ) hwnd not visible */
10091 static const struct message SetActiveWindowSeq3[] =
10092 {
10093     { HCBT_ACTIVATE, hook },
10094     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10096     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10097     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10098     { WM_ACTIVATEAPP, sent|wparam, 1 },
10099     { WM_ACTIVATEAPP, sent|wparam, 1 },
10100     { WM_NCACTIVATE, sent|wparam, 1 },
10101     { WM_ACTIVATE, sent|wparam, 1 },
10102     { HCBT_SETFOCUS, hook },
10103     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10104     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10105     { WM_SETFOCUS, sent|defwinproc },
10106     { 0 }
10107 };
10108 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10109 static const struct message SetActiveWindowSeq4[] =
10110 {
10111     { HCBT_ACTIVATE, hook },
10112     { WM_NCACTIVATE, sent|wparam, 0 },
10113     { WM_GETTEXT, sent|defwinproc|optional },
10114     { WM_ACTIVATE, sent|wparam, 0 },
10115     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10116     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10117     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10118     { WM_NCACTIVATE, sent|wparam, 1 },
10119     { WM_ACTIVATE, sent|wparam, 1 },
10120     { HCBT_SETFOCUS, hook },
10121     { WM_KILLFOCUS, sent|defwinproc },
10122     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10123     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10124     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10125     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10126     { WM_SETFOCUS, sent|defwinproc },
10127     { 0 }
10128 };
10129
10130
10131 static void test_SetActiveWindow(void)
10132 {
10133     HWND hwnd, popup, ret;
10134
10135     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10136                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10137                            100, 100, 200, 200, 0, 0, 0, NULL);
10138
10139     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10140                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10141                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10142
10143     ok(hwnd != 0, "Failed to create overlapped window\n");
10144     flush_sequence();
10145
10146     ok(popup != 0, "Failed to create popup window\n");
10147     flush_sequence();
10148
10149     trace("SetActiveWindow(0)\n");
10150     ret = SetActiveWindow(0);
10151     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10152     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10153     flush_sequence();
10154
10155     trace("SetActiveWindow(hwnd), hwnd visible\n");
10156     ret = SetActiveWindow(hwnd);
10157     todo_wine
10158     {
10159         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10160     }
10161     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10162     flush_sequence();
10163
10164     trace("SetActiveWindow(popup), hwnd visible, popup visble\n");
10165     ret = SetActiveWindow(popup);
10166     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visble\n");
10167     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visble", TRUE);
10168     flush_sequence();
10169
10170     ShowWindow(hwnd, SW_HIDE);
10171     ShowWindow(popup, SW_HIDE);
10172     flush_sequence();
10173
10174     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10175     ret = SetActiveWindow(hwnd);
10176     ok( ret == NULL, "Failed to SetActiveWindow(hwnd), hwnd not visible\n");
10177     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10178     flush_sequence();
10179
10180     trace("SetActiveWindow(popup), hwnd not visible, popup not visble\n");
10181     ret = SetActiveWindow(popup);
10182     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10183     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visble", TRUE);
10184     flush_sequence();
10185
10186     trace("done\n");
10187
10188     DestroyWindow(hwnd);
10189 }
10190
10191 static const struct message SetForegroundWindowSeq[] =
10192 {
10193     { WM_NCACTIVATE, sent|wparam, 0 },
10194     { WM_GETTEXT, sent|defwinproc|optional },
10195     { WM_ACTIVATE, sent|wparam, 0 },
10196     { WM_ACTIVATEAPP, sent|wparam, 0 },
10197     { WM_KILLFOCUS, sent },
10198     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10199     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10200     { 0 }
10201 };
10202
10203 static void test_SetForegroundWindow(void)
10204 {
10205     HWND hwnd;
10206
10207     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10208                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10209                            100, 100, 200, 200, 0, 0, 0, NULL);
10210     ok (hwnd != 0, "Failed to create overlapped window\n");
10211     flush_sequence();
10212
10213     trace("SetForegroundWindow( 0 )\n");
10214     SetForegroundWindow( 0 );
10215     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10216     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10217     SetForegroundWindow( GetDesktopWindow() );
10218     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10219                                         "foreground top level window", FALSE);
10220     trace("done\n");
10221
10222     DestroyWindow(hwnd);
10223 }
10224
10225 static void test_dbcs_wm_char(void)
10226 {
10227     BYTE dbch[2];
10228     WCHAR wch, bad_wch;
10229     HWND hwnd, hwnd2;
10230     MSG msg;
10231     DWORD time;
10232     POINT pt;
10233     DWORD_PTR res;
10234     CPINFOEXA cpinfo;
10235     UINT i, j, k;
10236     struct message wmCharSeq[2];
10237
10238     if (!pGetCPInfoExA)
10239     {
10240         skip("GetCPInfoExA is not available\n");
10241         return;
10242     }
10243
10244     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10245     if (cpinfo.MaxCharSize != 2)
10246     {
10247         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10248         return;
10249     }
10250
10251     dbch[0] = dbch[1] = 0;
10252     wch = 0;
10253     bad_wch = cpinfo.UnicodeDefaultChar;
10254     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10255         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10256             for (k = 128; k <= 255; k++)
10257             {
10258                 char str[2];
10259                 WCHAR wstr[2];
10260                 str[0] = j;
10261                 str[1] = k;
10262                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10263                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10264                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10265                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10266                 {
10267                     dbch[0] = j;
10268                     dbch[1] = k;
10269                     wch = wstr[0];
10270                     break;
10271                 }
10272             }
10273
10274     if (!wch)
10275     {
10276         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10277         return;
10278     }
10279     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10280            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10281
10282     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10283                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10284     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10285                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10286     ok (hwnd != 0, "Failed to create overlapped window\n");
10287     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10288     flush_sequence();
10289
10290     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10291     wmCharSeq[0].message = WM_CHAR;
10292     wmCharSeq[0].flags = sent|wparam;
10293     wmCharSeq[0].wParam = wch;
10294
10295     /* posted message */
10296     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10297     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10298     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10299     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10300     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10301     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10302     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10303
10304     /* posted thread message */
10305     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10306     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10307     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10308     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10309     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10310     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10311     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10312
10313     /* sent message */
10314     flush_sequence();
10315     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10316     ok_sequence( WmEmptySeq, "no messages", FALSE );
10317     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10318     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10319     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10320
10321     /* sent message with timeout */
10322     flush_sequence();
10323     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10324     ok_sequence( WmEmptySeq, "no messages", FALSE );
10325     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10326     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10327     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10328
10329     /* sent message with timeout and callback */
10330     flush_sequence();
10331     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10332     ok_sequence( WmEmptySeq, "no messages", FALSE );
10333     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10334     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10335     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10336
10337     /* sent message with callback */
10338     flush_sequence();
10339     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10340     ok_sequence( WmEmptySeq, "no messages", FALSE );
10341     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10342     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10343     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10344
10345     /* direct window proc call */
10346     flush_sequence();
10347     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10348     ok_sequence( WmEmptySeq, "no messages", FALSE );
10349     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10350     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10351
10352     /* dispatch message */
10353     msg.hwnd = hwnd;
10354     msg.message = WM_CHAR;
10355     msg.wParam = dbch[0];
10356     msg.lParam = 0;
10357     DispatchMessageA( &msg );
10358     ok_sequence( WmEmptySeq, "no messages", FALSE );
10359     msg.wParam = dbch[1];
10360     DispatchMessageA( &msg );
10361     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10362
10363     /* window handle is irrelevant */
10364     flush_sequence();
10365     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10366     ok_sequence( WmEmptySeq, "no messages", FALSE );
10367     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10368     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10369     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10370
10371     /* interleaved post and send */
10372     flush_sequence();
10373     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10374     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10375     ok_sequence( WmEmptySeq, "no messages", FALSE );
10376     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10377     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10378     ok_sequence( WmEmptySeq, "no messages", FALSE );
10379     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10380     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10381     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10382     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10383     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10384     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10385     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10386
10387     /* interleaved sent message and winproc */
10388     flush_sequence();
10389     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10390     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10391     ok_sequence( WmEmptySeq, "no messages", FALSE );
10392     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10393     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10394     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10395     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10396
10397     /* interleaved winproc and dispatch */
10398     msg.hwnd = hwnd;
10399     msg.message = WM_CHAR;
10400     msg.wParam = dbch[0];
10401     msg.lParam = 0;
10402     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10403     DispatchMessageA( &msg );
10404     ok_sequence( WmEmptySeq, "no messages", FALSE );
10405     msg.wParam = dbch[1];
10406     DispatchMessageA( &msg );
10407     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10408     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10409     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10410
10411     /* interleaved sends */
10412     flush_sequence();
10413     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10414     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10415     ok_sequence( WmEmptySeq, "no messages", FALSE );
10416     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10417     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10418     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10419     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10420
10421     /* dbcs WM_CHAR */
10422     flush_sequence();
10423     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10424     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10425     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10426
10427     /* other char messages are not magic */
10428     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10429     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10430     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10431     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10432     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10433     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10434     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10435     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10436     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10437     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10438
10439     /* test retrieving messages */
10440
10441     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10442     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10443     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10444     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10445     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10446     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10447     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10448     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10449     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10450     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10451
10452     /* message filters */
10453     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10454     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10455     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10456     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10457     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10458     /* message id is filtered, hwnd is not */
10459     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10460     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10461     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10462     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10463     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10464     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10465
10466     /* mixing GetMessage and PostMessage */
10467     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10468     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10469     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10470     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10471     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10472     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10473     time = msg.time;
10474     pt = msg.pt;
10475     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10476     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10477     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10478     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10479     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10480     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10481     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10482     ok( msg.pt.x == pt.x && msg.pt.y == pt.y, "bad point %u,%u/%u,%u\n", msg.pt.x, msg.pt.y, pt.x, pt.y );
10483     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10484
10485     /* without PM_REMOVE */
10486     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10487     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10488     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10489     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10490     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10491     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10492     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10493     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10494     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10495     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10496     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10497     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10498     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10499     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10500     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10501     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10502     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10503     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10504
10505     DestroyWindow(hwnd);
10506 }
10507
10508 #define ID_LISTBOX 0x000f
10509
10510 static const struct message wm_lb_setcursel_0[] =
10511 {
10512     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10513     { WM_CTLCOLORLISTBOX, sent|parent },
10514     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10515     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10516     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10517     { 0 }
10518 };
10519 static const struct message wm_lb_setcursel_1[] =
10520 {
10521     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10522     { WM_CTLCOLORLISTBOX, sent|parent },
10523     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10524     { WM_CTLCOLORLISTBOX, sent|parent },
10525     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10526     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10527     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10528     { 0 }
10529 };
10530 static const struct message wm_lb_setcursel_2[] =
10531 {
10532     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10533     { WM_CTLCOLORLISTBOX, sent|parent },
10534     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10535     { WM_CTLCOLORLISTBOX, sent|parent },
10536     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10537     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10538     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10539     { 0 }
10540 };
10541 static const struct message wm_lb_click_0[] =
10542 {
10543     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10544     { HCBT_SETFOCUS, hook },
10545     { WM_KILLFOCUS, sent|parent },
10546     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10547     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10548     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10549     { WM_SETFOCUS, sent|defwinproc },
10550
10551     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10552     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10553     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10554     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10555     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10556
10557     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10558     { WM_CTLCOLORLISTBOX, sent|parent },
10559     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10560     { WM_CTLCOLORLISTBOX, sent|parent },
10561     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10562     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10563
10564     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10565     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10566
10567     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10568     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10569     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10570     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10571     { 0 }
10572 };
10573
10574 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10575
10576 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10577
10578 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10579 {
10580     static long defwndproc_counter = 0;
10581     LRESULT ret;
10582     struct message msg;
10583
10584     /* do not log painting messages */
10585     if (message != WM_PAINT &&
10586         message != WM_NCPAINT &&
10587         message != WM_SYNCPAINT &&
10588         message != WM_ERASEBKGND &&
10589         message != WM_NCHITTEST &&
10590         message != WM_GETTEXT &&
10591         message != WM_GETICON &&
10592         message != WM_DEVICECHANGE)
10593     {
10594         trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
10595
10596         msg.message = message;
10597         msg.flags = sent|wparam|lparam;
10598         if (defwndproc_counter) msg.flags |= defwinproc;
10599         msg.wParam = wp;
10600         msg.lParam = lp;
10601         add_message(&msg);
10602     }
10603
10604     defwndproc_counter++;
10605     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10606     defwndproc_counter--;
10607
10608     return ret;
10609 }
10610
10611 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10612                                int caret_index, int top_index, int line)
10613 {
10614     LRESULT ret;
10615
10616     /* calling an orig proc helps to avoid unnecessary message logging */
10617     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10618     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10619     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10620     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10621     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10622     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10623     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10624     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10625 }
10626
10627 static void test_listbox_messages(void)
10628 {
10629     HWND parent, listbox;
10630     LRESULT ret;
10631
10632     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10633                              100, 100, 200, 200, 0, 0, 0, NULL);
10634     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10635                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10636                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10637     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10638
10639     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10640
10641     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10642     ok(ret == 0, "expected 0, got %ld\n", ret);
10643     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10644     ok(ret == 1, "expected 1, got %ld\n", ret);
10645     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10646     ok(ret == 2, "expected 2, got %ld\n", ret);
10647
10648     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10649
10650     flush_sequence();
10651
10652     log_all_parent_messages++;
10653
10654     trace("selecting item 0\n");
10655     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10656     ok(ret == 0, "expected 0, got %ld\n", ret);
10657     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10658     check_lb_state(listbox, 3, 0, 0, 0);
10659     flush_sequence();
10660
10661     trace("selecting item 1\n");
10662     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10663     ok(ret == 1, "expected 1, got %ld\n", ret);
10664     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10665     check_lb_state(listbox, 3, 1, 1, 0);
10666
10667     trace("selecting item 2\n");
10668     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10669     ok(ret == 2, "expected 2, got %ld\n", ret);
10670     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10671     check_lb_state(listbox, 3, 2, 2, 0);
10672
10673     trace("clicking on item 0\n");
10674     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10675     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10676     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10677     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10678     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10679     check_lb_state(listbox, 3, 0, 0, 0);
10680     flush_sequence();
10681
10682     log_all_parent_messages--;
10683
10684     DestroyWindow(listbox);
10685     DestroyWindow(parent);
10686 }
10687
10688 /*************************** Menu test ******************************/
10689 static const struct message wm_popup_menu_1[] =
10690 {
10691     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10692     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10693     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
10694     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
10695     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
10696     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
10697     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10698     { WM_INITMENU, sent|lparam, 0, 0 },
10699     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
10700     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
10701     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
10702     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
10703     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
10704     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10705     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10706     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
10707     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10708     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10709     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10710     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
10711     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10712     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10713     { 0 }
10714 };
10715 static const struct message wm_popup_menu_2[] =
10716 {
10717     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10718     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10719     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
10720     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
10721     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
10722     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
10723     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10724     { WM_INITMENU, sent|lparam, 0, 0 },
10725     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
10726     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
10727     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
10728     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
10729     { HCBT_CREATEWND, hook },
10730     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
10731                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
10732     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
10733     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10734     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
10735     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
10736     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
10737     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
10738     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
10739     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10740     { HCBT_DESTROYWND, hook },
10741     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10742     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
10743     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10744     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10745     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10746     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
10747     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10748     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10749     { 0 }
10750 };
10751 static const struct message wm_popup_menu_3[] =
10752 {
10753     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10754     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10755     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
10756     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
10757     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
10758     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
10759     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10760     { WM_INITMENU, sent|lparam, 0, 0 },
10761     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
10762     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
10763     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
10764     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
10765     { HCBT_CREATEWND, hook },
10766     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
10767                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
10768     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
10769     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10770     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
10771     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
10772     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
10773     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
10774     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
10775     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10776     { HCBT_DESTROYWND, hook },
10777     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10778     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
10779     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10780     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10781     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10782     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
10783     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10784     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10785     { 0 }
10786 };
10787
10788 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10789 {
10790     if (message == WM_ENTERIDLE ||
10791         message == WM_INITMENU ||
10792         message == WM_INITMENUPOPUP ||
10793         message == WM_MENUSELECT ||
10794         message == WM_PARENTNOTIFY ||
10795         message == WM_ENTERMENULOOP ||
10796         message == WM_EXITMENULOOP ||
10797         message == WM_UNINITMENUPOPUP ||
10798         message == WM_KEYDOWN ||
10799         message == WM_KEYUP ||
10800         message == WM_CHAR ||
10801         message == WM_SYSKEYDOWN ||
10802         message == WM_SYSKEYUP ||
10803         message == WM_SYSCHAR ||
10804         message == WM_COMMAND ||
10805         message == WM_MENUCOMMAND)
10806     {
10807         struct message msg;
10808
10809         trace("parent_menu_proc: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
10810
10811         msg.message = message;
10812         msg.flags = sent|wparam|lparam;
10813         msg.wParam = wp;
10814         msg.lParam = lp;
10815         add_message(&msg);
10816     }
10817
10818     return DefWindowProcA(hwnd, message, wp, lp);
10819 }
10820
10821 static void set_menu_style(HMENU hmenu, DWORD style)
10822 {
10823     MENUINFO mi;
10824     BOOL ret;
10825
10826     mi.cbSize = sizeof(mi);
10827     mi.fMask = MIM_STYLE;
10828     mi.dwStyle = style;
10829     SetLastError(0xdeadbeef);
10830     ret = pSetMenuInfo(hmenu, &mi);
10831     ok(ret, "SetMenuInfo error %u\n", GetLastError());
10832 }
10833
10834 static DWORD get_menu_style(HMENU hmenu)
10835 {
10836     MENUINFO mi;
10837     BOOL ret;
10838
10839     mi.cbSize = sizeof(mi);
10840     mi.fMask = MIM_STYLE;
10841     mi.dwStyle = 0;
10842     SetLastError(0xdeadbeef);
10843     ret = pGetMenuInfo(hmenu, &mi);
10844     ok(ret, "GetMenuInfo error %u\n", GetLastError());
10845
10846     return mi.dwStyle;
10847 }
10848
10849 static void test_menu_messages(void)
10850 {
10851     MSG msg;
10852     WNDCLASSA cls;
10853     HMENU hmenu, hmenu_popup;
10854     HWND hwnd;
10855     DWORD style;
10856
10857     if (!pGetMenuInfo || !pSetMenuInfo)
10858     {
10859         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
10860         return;
10861     }
10862     cls.style = 0;
10863     cls.lpfnWndProc = parent_menu_proc;
10864     cls.cbClsExtra = 0;
10865     cls.cbWndExtra = 0;
10866     cls.hInstance = GetModuleHandleA(0);
10867     cls.hIcon = 0;
10868     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
10869     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
10870     cls.lpszMenuName = NULL;
10871     cls.lpszClassName = "TestMenuClass";
10872     UnregisterClass(cls.lpszClassName, cls.hInstance);
10873     if (!RegisterClassA(&cls)) assert(0);
10874
10875     SetLastError(0xdeadbeef);
10876     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10877                            100, 100, 200, 200, 0, 0, 0, NULL);
10878     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
10879
10880     SetLastError(0xdeadbeef);
10881     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
10882     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
10883
10884     SetMenu(hwnd, hmenu);
10885
10886     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
10887     style = get_menu_style(hmenu);
10888     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
10889
10890     hmenu_popup = GetSubMenu(hmenu, 0);
10891     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
10892     style = get_menu_style(hmenu_popup);
10893     ok(style == 0, "expected 0, got %u\n", style);
10894
10895     hmenu_popup = GetSubMenu(hmenu_popup, 0);
10896     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
10897     style = get_menu_style(hmenu_popup);
10898     ok(style == 0, "expected 0, got %u\n", style);
10899
10900     /* Alt+E, Enter */
10901     trace("testing a popup menu command\n");
10902     flush_sequence();
10903     keybd_event(VK_MENU, 0, 0, 0);
10904     keybd_event('E', 0, 0, 0);
10905     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
10906     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
10907     keybd_event(VK_RETURN, 0, 0, 0);
10908     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
10909     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10910     {
10911         TranslateMessage(&msg);
10912         DispatchMessage(&msg);
10913     }
10914     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
10915
10916     /* Alt+F, Right, Enter */
10917     trace("testing submenu of a popup menu command\n");
10918     flush_sequence();
10919     keybd_event(VK_MENU, 0, 0, 0);
10920     keybd_event('F', 0, 0, 0);
10921     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
10922     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
10923     keybd_event(VK_RIGHT, 0, 0, 0);
10924     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
10925     keybd_event(VK_RETURN, 0, 0, 0);
10926     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
10927     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10928     {
10929         TranslateMessage(&msg);
10930         DispatchMessage(&msg);
10931     }
10932     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
10933
10934     set_menu_style(hmenu, 0);
10935     style = get_menu_style(hmenu);
10936     ok(style == 0, "expected 0, got %u\n", style);
10937
10938     hmenu_popup = GetSubMenu(hmenu, 0);
10939     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
10940     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
10941     style = get_menu_style(hmenu_popup);
10942     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
10943
10944     hmenu_popup = GetSubMenu(hmenu_popup, 0);
10945     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
10946     style = get_menu_style(hmenu_popup);
10947     ok(style == 0, "expected 0, got %u\n", style);
10948
10949     /* Alt+F, Right, Enter */
10950     trace("testing submenu of a popup menu command\n");
10951     flush_sequence();
10952     keybd_event(VK_MENU, 0, 0, 0);
10953     keybd_event('F', 0, 0, 0);
10954     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
10955     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
10956     keybd_event(VK_RIGHT, 0, 0, 0);
10957     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
10958     keybd_event(VK_RETURN, 0, 0, 0);
10959     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
10960     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10961     {
10962         TranslateMessage(&msg);
10963         DispatchMessage(&msg);
10964     }
10965     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
10966
10967     DestroyWindow(hwnd);
10968     DestroyMenu(hmenu);
10969 }
10970
10971 START_TEST(msg)
10972 {
10973     BOOL ret;
10974     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
10975
10976     init_procs();
10977
10978     if (!RegisterWindowClasses()) assert(0);
10979
10980     if (pSetWinEventHook)
10981     {
10982         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
10983                                                       GetModuleHandleA(0),
10984                                                       win_event_proc,
10985                                                       0,
10986                                                       GetCurrentThreadId(),
10987                                                       WINEVENT_INCONTEXT);
10988         assert(hEvent_hook);
10989
10990         if (pIsWinEventHookInstalled)
10991         {
10992             UINT event;
10993             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
10994                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
10995         }
10996     }
10997
10998     cbt_hook_thread_id = GetCurrentThreadId();
10999     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11000     assert(hCBT_hook);
11001
11002     test_winevents();
11003
11004     /* Fix message sequences before removing 4 lines below */
11005 #if 1
11006     if (pUnhookWinEvent && hEvent_hook)
11007     {
11008         ret = pUnhookWinEvent(hEvent_hook);
11009         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11010         pUnhookWinEvent = 0;
11011     }
11012     hEvent_hook = 0;
11013 #endif
11014
11015     test_ShowWindow();
11016     test_PeekMessage();
11017     test_PeekMessage2();
11018     test_scrollwindowex();
11019     test_messages();
11020     test_setwindowpos();
11021     test_showwindow();
11022     invisible_parent_tests();
11023     test_mdi_messages();
11024     test_button_messages();
11025     test_static_messages();
11026     test_listbox_messages();
11027     test_combobox_messages();
11028     test_wmime_keydown_message();
11029     test_paint_messages();
11030     test_interthread_messages();
11031     test_message_conversion();
11032     test_accelerators();
11033     test_timers();
11034     test_timers_no_wnd();
11035     test_set_hook();
11036     test_DestroyWindow();
11037     test_DispatchMessage();
11038     test_SendMessageTimeout();
11039     test_edit_messages();
11040     test_quit_message();
11041     test_SetActiveWindow();
11042
11043     if (!pTrackMouseEvent)
11044         skip("TrackMouseEvent is not available\n");
11045     else
11046         test_TrackMouseEvent();
11047
11048     test_SetWindowRgn();
11049     test_sys_menu();
11050     test_dialog_messages();
11051     test_nullCallback();
11052     test_dbcs_wm_char();
11053     test_menu_messages();
11054     /* keep it the last test, under Windows it tends to break the tests
11055      * which rely on active/foreground windows being correct.
11056      */
11057     test_SetForegroundWindow();
11058
11059     UnhookWindowsHookEx(hCBT_hook);
11060     if (pUnhookWinEvent)
11061     {
11062         ret = pUnhookWinEvent(hEvent_hook);
11063         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11064         SetLastError(0xdeadbeef);
11065         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11066         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11067            GetLastError() == 0xdeadbeef, /* Win9x */
11068            "unexpected error %d\n", GetLastError());
11069     }
11070     else
11071         skip("UnhookWinEvent is not available\n");
11072 }