msi: Fix a typo.
[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     { WM_SETVISIBLE, 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     { WM_SETVISIBLE, 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_SHOWMINIMIZED) for a not visible overlapped window */
464 static const struct message WmShowMinOverlappedSeq[] = {
465     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
466     { HCBT_SETFOCUS, hook },
467     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
468     { WM_KILLFOCUS, sent },
469     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
470     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
471     { WM_GETTEXT, sent|optional },
472     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
473     { WM_GETMINMAXINFO, sent|defwinproc },
474     { WM_NCCALCSIZE, sent|wparam, TRUE },
475     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
476     { WM_NCPAINT, sent },
477     { WM_GETTEXT, sent|defwinproc|optional },
478     { WM_WINDOWPOSCHANGED, sent },
479     { WM_MOVE, sent|defwinproc },
480     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
481     { WM_NCCALCSIZE, sent|optional },
482     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
483     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
484     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
485     { WM_NCACTIVATE, sent|wparam, 0 },
486     { WM_GETTEXT, sent|defwinproc|optional },
487     { WM_ACTIVATE, sent },
488     { WM_ACTIVATEAPP, sent|wparam, 0 },
489     { 0 }
490 };
491 /* ShowWindow(SW_HIDE) for a visible overlapped window */
492 static const struct message WmHideOverlappedSeq[] = {
493     { WM_SHOWWINDOW, sent|wparam, 0 },
494     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
495     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
496     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
497     { WM_SIZE, sent|optional }, /* XP doesn't send it */
498     { WM_MOVE, sent|optional }, /* XP doesn't send it */
499     { WM_NCACTIVATE, sent|wparam, 0 },
500     { WM_ACTIVATE, sent|wparam, 0 },
501     { WM_ACTIVATEAPP, sent|wparam, 0 },
502     { WM_KILLFOCUS, sent|wparam, 0 },
503     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
504     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
505     { 0 }
506 };
507 /* DestroyWindow for a visible overlapped window */
508 static const struct message WmDestroyOverlappedSeq[] = {
509     { HCBT_DESTROYWND, hook },
510     { 0x0090, sent|optional },
511     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
512     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
513     { 0x0090, sent|optional },
514     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
515     { WM_NCACTIVATE, sent|wparam, 0 },
516     { WM_ACTIVATE, sent|wparam, 0 },
517     { WM_ACTIVATEAPP, sent|wparam, 0 },
518     { WM_KILLFOCUS, sent|wparam, 0 },
519     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
520     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
521     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
522     { WM_DESTROY, sent },
523     { WM_NCDESTROY, sent },
524     { 0 }
525 };
526 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
527 static const struct message WmCreateMaxPopupSeq[] = {
528     { HCBT_CREATEWND, hook },
529     { WM_NCCREATE, sent },
530     { WM_NCCALCSIZE, sent|wparam, 0 },
531     { WM_CREATE, sent },
532     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
533     { WM_SIZE, sent|wparam, SIZE_RESTORED },
534     { WM_MOVE, sent },
535     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
536     { WM_GETMINMAXINFO, sent },
537     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
538     { WM_NCCALCSIZE, sent|wparam, TRUE },
539     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
540     { WM_MOVE, sent|defwinproc },
541     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
542     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
543     { WM_SHOWWINDOW, sent|wparam, 1 },
544     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
545     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
546     { HCBT_ACTIVATE, hook },
547     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
548     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
549     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
550     { WM_ACTIVATEAPP, sent|wparam, 1 },
551     { WM_NCACTIVATE, sent|wparam, 1 },
552     { WM_ACTIVATE, sent|wparam, 1 },
553     { HCBT_SETFOCUS, hook },
554     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
555     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
556     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
557     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
558     { WM_SYNCPAINT, sent|wparam|optional, 4 },
559     { WM_NCPAINT, sent|wparam|optional, 1 },
560     { WM_ERASEBKGND, sent|optional },
561     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
562     { 0 }
563 };
564 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
565 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
566     { HCBT_CREATEWND, hook },
567     { WM_NCCREATE, sent },
568     { WM_NCCALCSIZE, sent|wparam, 0 },
569     { WM_CREATE, sent },
570     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
571     { WM_SIZE, sent|wparam, SIZE_RESTORED },
572     { WM_MOVE, sent },
573     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
574     { WM_GETMINMAXINFO, sent },
575     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
576     { WM_NCCALCSIZE, sent|wparam, TRUE },
577     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
578     { WM_MOVE, sent|defwinproc },
579     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
580     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
581     { 0 }
582 };
583 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
584 static const struct message WmShowMaxPopupResizedSeq[] = {
585     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
586     { WM_GETMINMAXINFO, sent },
587     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
588     { WM_NCCALCSIZE, sent|wparam, TRUE },
589     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
590     { HCBT_ACTIVATE, hook },
591     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
592     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
593     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
594     { WM_ACTIVATEAPP, sent|wparam, 1 },
595     { WM_NCACTIVATE, sent|wparam, 1 },
596     { WM_ACTIVATE, sent|wparam, 1 },
597     { HCBT_SETFOCUS, hook },
598     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
599     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
600     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
601     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
602     { WM_NCPAINT, sent|wparam|optional, 1 },
603     { WM_ERASEBKGND, sent|optional },
604     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
605     /* WinNT4.0 sends WM_MOVE */
606     { WM_MOVE, sent|defwinproc|optional },
607     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
608     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
609     { 0 }
610 };
611 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
612 static const struct message WmShowMaxPopupSeq[] = {
613     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
614     { WM_GETMINMAXINFO, sent },
615     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
616     { WM_NCCALCSIZE, sent|wparam, TRUE },
617     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
618     { HCBT_ACTIVATE, hook },
619     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
620     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
621     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
622     { WM_ACTIVATEAPP, sent|wparam, 1 },
623     { WM_NCACTIVATE, sent|wparam, 1 },
624     { WM_ACTIVATE, sent|wparam, 1 },
625     { HCBT_SETFOCUS, hook },
626     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
627     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
628     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
629     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
630     { WM_SYNCPAINT, sent|wparam|optional, 4 },
631     { WM_NCPAINT, sent|wparam|optional, 1 },
632     { WM_ERASEBKGND, sent|optional },
633     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
635     { 0 }
636 };
637 /* CreateWindow(WS_VISIBLE) for popup window */
638 static const struct message WmCreatePopupSeq[] = {
639     { HCBT_CREATEWND, hook },
640     { WM_NCCREATE, sent },
641     { WM_NCCALCSIZE, sent|wparam, 0 },
642     { WM_CREATE, sent },
643     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
644     { WM_SIZE, sent|wparam, SIZE_RESTORED },
645     { WM_MOVE, sent },
646     { WM_SHOWWINDOW, sent|wparam, 1 },
647     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
648     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
649     { HCBT_ACTIVATE, hook },
650     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
651     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
652     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
653     { WM_NCPAINT, sent|wparam|optional, 1 },
654     { WM_ERASEBKGND, sent|optional },
655     { WM_ACTIVATEAPP, sent|wparam, 1 },
656     { WM_NCACTIVATE, sent|wparam, 1 },
657     { WM_ACTIVATE, sent|wparam, 1 },
658     { HCBT_SETFOCUS, hook },
659     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
660     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
661     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
662     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
663     { WM_SYNCPAINT, sent|wparam|optional, 4 },
664     { WM_NCPAINT, sent|wparam|optional, 1 },
665     { WM_ERASEBKGND, sent|optional },
666     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
667     { 0 }
668 };
669 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
670 static const struct message WmShowVisMaxPopupSeq[] = {
671     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
672     { WM_GETMINMAXINFO, sent },
673     { WM_GETTEXT, sent|optional },
674     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
675     { WM_NCCALCSIZE, sent|wparam, TRUE },
676     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
677     { WM_NCPAINT, sent|wparam|optional, 1 },
678     { WM_ERASEBKGND, sent|optional },
679     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
680     { WM_MOVE, sent|defwinproc },
681     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
682     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
683     { 0 }
684 };
685 /* CreateWindow (for a child popup window, not initially visible) */
686 static const struct message WmCreateChildPopupSeq[] = {
687     { HCBT_CREATEWND, hook },
688     { WM_NCCREATE, sent }, 
689     { WM_NCCALCSIZE, sent|wparam, 0 },
690     { WM_CREATE, sent },
691     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
692     { WM_SIZE, sent|wparam, SIZE_RESTORED },
693     { WM_MOVE, sent },
694     { 0 }
695 };
696 /* CreateWindow (for a popup window, not initially visible,
697  * which sets WS_VISIBLE in WM_CREATE handler)
698  */
699 static const struct message WmCreateInvisiblePopupSeq[] = {
700     { HCBT_CREATEWND, hook },
701     { WM_NCCREATE, sent }, 
702     { WM_NCCALCSIZE, sent|wparam, 0 },
703     { WM_CREATE, sent },
704     { WM_STYLECHANGING, sent },
705     { WM_STYLECHANGED, sent },
706     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
707     { WM_SIZE, sent|wparam, SIZE_RESTORED },
708     { WM_MOVE, sent },
709     { 0 }
710 };
711 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
712  * for a popup window with WS_VISIBLE style set
713  */
714 static const struct message WmShowVisiblePopupSeq_2[] = {
715     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
716     { 0 }
717 };
718 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
719  * for a popup window with WS_VISIBLE style set
720  */
721 static const struct message WmShowVisiblePopupSeq_3[] = {
722     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
723     { HCBT_ACTIVATE, hook },
724     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
725     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
726     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
727     { WM_NCACTIVATE, sent|wparam, 1 },
728     { WM_ACTIVATE, sent|wparam, 1 },
729     { HCBT_SETFOCUS, hook },
730     { WM_KILLFOCUS, sent|parent },
731     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
732     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
733     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
734     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
735     { WM_SETFOCUS, sent|defwinproc },
736     { 0 }
737 };
738 /* CreateWindow (for child window, not initially visible) */
739 static const struct message WmCreateChildSeq[] = {
740     { HCBT_CREATEWND, hook },
741     { WM_NCCREATE, sent }, 
742     /* child is inserted into parent's child list after WM_NCCREATE returns */
743     { WM_NCCALCSIZE, sent|wparam, 0 },
744     { WM_CREATE, sent },
745     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
746     { WM_SIZE, sent|wparam, SIZE_RESTORED },
747     { WM_MOVE, sent },
748     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
749     { 0 }
750 };
751 /* CreateWindow (for maximized child window, not initially visible) */
752 static const struct message WmCreateMaximizedChildSeq[] = {
753     { HCBT_CREATEWND, hook },
754     { WM_NCCREATE, sent }, 
755     { WM_NCCALCSIZE, sent|wparam, 0 },
756     { WM_CREATE, sent },
757     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
758     { WM_SIZE, sent|wparam, SIZE_RESTORED },
759     { WM_MOVE, sent },
760     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
761     { WM_GETMINMAXINFO, sent },
762     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
763     { WM_NCCALCSIZE, sent|wparam, 1 },
764     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
765     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
766     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
767     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
768     { 0 }
769 };
770 /* CreateWindow (for a child window, initially visible) */
771 static const struct message WmCreateVisibleChildSeq[] = {
772     { HCBT_CREATEWND, hook },
773     { WM_NCCREATE, sent }, 
774     /* child is inserted into parent's child list after WM_NCCREATE returns */
775     { WM_NCCALCSIZE, sent|wparam, 0 },
776     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
777     { WM_CREATE, sent },
778     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
779     { WM_SIZE, sent|wparam, SIZE_RESTORED },
780     { WM_MOVE, sent },
781     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
782     { WM_SHOWWINDOW, sent|wparam, 1 },
783     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
784     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
785     { WM_ERASEBKGND, sent|parent|optional },
786     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
787     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
788     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
789     { 0 }
790 };
791 /* ShowWindow(SW_SHOW) for a not visible child window */
792 static const struct message WmShowChildSeq[] = {
793     { WM_SHOWWINDOW, sent|wparam, 1 },
794     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
795     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
796     { WM_ERASEBKGND, sent|parent|optional },
797     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
798     { 0 }
799 };
800 /* ShowWindow(SW_HIDE) for a visible child window */
801 static const struct message WmHideChildSeq[] = {
802     { WM_SHOWWINDOW, sent|wparam, 0 },
803     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
804     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
805     { WM_ERASEBKGND, sent|parent|optional },
806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
807     { 0 }
808 };
809 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
810 static const struct message WmHideChildSeq2[] = {
811     { WM_SHOWWINDOW, sent|wparam, 0 },
812     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
813     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
814     { WM_ERASEBKGND, sent|parent },
815     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
816     { 0 }
817 };
818 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
819  * for a not visible child window
820  */
821 static const struct message WmShowChildSeq_2[] = {
822     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
823     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
824     { WM_CHILDACTIVATE, sent },
825     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
826     { 0 }
827 };
828 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
829  * for a not visible child window
830  */
831 static const struct message WmShowChildSeq_3[] = {
832     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
833     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
834     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
835     { 0 }
836 };
837 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
838  * for a visible child window with a caption
839  */
840 static const struct message WmShowChildSeq_4[] = {
841     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
842     { WM_CHILDACTIVATE, sent },
843     { 0 }
844 };
845 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
846 static const struct message WmShowChildInvisibleParentSeq_1[] = {
847     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
849     { WM_NCCALCSIZE, sent|wparam, 1 },
850     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
851     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
852     { WM_MOVE, sent|defwinproc },
853     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
854     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
855     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
856     /* FIXME: Wine creates an icon/title window while Windows doesn't */
857     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
858     { WM_GETTEXT, sent|optional },
859     { 0 }
860 };
861 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
862 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
863     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
864     { 0 }
865 };
866 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
867 static const struct message WmShowChildInvisibleParentSeq_2[] = {
868     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
869     { WM_GETMINMAXINFO, sent },
870     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
871     { WM_NCCALCSIZE, sent|wparam, 1 },
872     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
873     { WM_CHILDACTIVATE, sent },
874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
875     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
876     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
877     { 0 }
878 };
879 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
880 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
881     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
882     { 0 }
883 };
884 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
885 static const struct message WmShowChildInvisibleParentSeq_3[] = {
886     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
887     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
888     { WM_NCCALCSIZE, sent|wparam, 1 },
889     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
890     { WM_CHILDACTIVATE, sent },
891     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
892     { WM_MOVE, sent|defwinproc },
893     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
894     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
895     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
896     /* FIXME: Wine creates an icon/title window while Windows doesn't */
897     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
898     { WM_GETTEXT, sent|optional },
899     { 0 }
900 };
901 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
902 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
903     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
904     { 0 }
905 };
906 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
907 static const struct message WmShowChildInvisibleParentSeq_4[] = {
908     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
909     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
910     { WM_NCCALCSIZE, sent|wparam, 1 },
911     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
912     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
913     { WM_MOVE, sent|defwinproc },
914     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
915     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
916     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
917     /* FIXME: Wine creates an icon/title window while Windows doesn't */
918     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
919     { WM_GETTEXT, sent|optional },
920     { 0 }
921 };
922 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
923 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
924     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
925     { 0 }
926 };
927 /* ShowWindow(SW_SHOW) for child with invisible parent */
928 static const struct message WmShowChildInvisibleParentSeq_5[] = {
929     { WM_SHOWWINDOW, sent|wparam, 1 },
930     { 0 }
931 };
932 /* ShowWindow(SW_HIDE) for child with invisible parent */
933 static const struct message WmHideChildInvisibleParentSeq[] = {
934     { WM_SHOWWINDOW, sent|wparam, 0 },
935     { 0 }
936 };
937 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
938 static const struct message WmShowChildInvisibleParentSeq_6[] = {
939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
940     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
941     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
942     { 0 }
943 };
944 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
945 static const struct message WmHideChildInvisibleParentSeq_2[] = {
946     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
947     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
948     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
949     { 0 }
950 };
951 /* DestroyWindow for a visible child window */
952 static const struct message WmDestroyChildSeq[] = {
953     { HCBT_DESTROYWND, hook },
954     { 0x0090, sent|optional },
955     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
956     { WM_SHOWWINDOW, sent|wparam, 0 },
957     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
958     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
959     { WM_ERASEBKGND, sent|parent|optional },
960     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
961     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
962     { WM_KILLFOCUS, sent },
963     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
964     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
965     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
966     { WM_SETFOCUS, sent|parent },
967     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
968     { WM_DESTROY, sent },
969     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
970     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
971     { WM_NCDESTROY, sent },
972     { 0 }
973 };
974 /* DestroyWindow for a visible child window with invisible parent */
975 static const struct message WmDestroyInvisibleChildSeq[] = {
976     { HCBT_DESTROYWND, hook },
977     { 0x0090, sent|optional },
978     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
979     { WM_SHOWWINDOW, sent|wparam, 0 },
980     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
981     { WM_DESTROY, sent },
982     { WM_NCDESTROY, sent },
983     { 0 }
984 };
985 /* Moving the mouse in nonclient area */
986 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
987     { WM_NCHITTEST, sent },
988     { WM_SETCURSOR, sent },
989     { WM_NCMOUSEMOVE, posted },
990     { 0 }
991 };
992 /* Moving the mouse in client area */
993 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
994     { WM_NCHITTEST, sent },
995     { WM_SETCURSOR, sent },
996     { WM_MOUSEMOVE, posted },
997     { 0 }
998 };
999 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1000 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1001     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1002     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1003     { WM_GETMINMAXINFO, sent|defwinproc },
1004     { WM_ENTERSIZEMOVE, sent|defwinproc },
1005     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1006     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1007     { WM_MOVE, sent|defwinproc },
1008     { WM_EXITSIZEMOVE, sent|defwinproc },
1009     { 0 }
1010 };
1011 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1012 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1013     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1014     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1015     { WM_GETMINMAXINFO, sent|defwinproc },
1016     { WM_ENTERSIZEMOVE, sent|defwinproc },
1017     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1018     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1019     { WM_GETMINMAXINFO, sent|defwinproc },
1020     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1021     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1022     { WM_GETTEXT, sent|defwinproc },
1023     { WM_ERASEBKGND, sent|defwinproc },
1024     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1025     { WM_MOVE, sent|defwinproc },
1026     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1027     { WM_EXITSIZEMOVE, sent|defwinproc },
1028     { 0 }
1029 };
1030 /* Resizing child window with MoveWindow (32) */
1031 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1032     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1033     { WM_NCCALCSIZE, sent|wparam, 1 },
1034     { WM_ERASEBKGND, sent|parent|optional },
1035     { WM_ERASEBKGND, sent|optional },
1036     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1037     { WM_MOVE, sent|defwinproc },
1038     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1039     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1040     { 0 }
1041 };
1042 /* Clicking on inactive button */
1043 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1044     { WM_NCHITTEST, sent },
1045     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1046     { WM_MOUSEACTIVATE, sent },
1047     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1048     { WM_SETCURSOR, sent },
1049     { WM_SETCURSOR, sent|parent|defwinproc },
1050     { WM_LBUTTONDOWN, posted },
1051     { WM_KILLFOCUS, posted|parent },
1052     { WM_SETFOCUS, posted },
1053     { WM_CTLCOLORBTN, posted|parent },
1054     { BM_SETSTATE, posted },
1055     { WM_CTLCOLORBTN, posted|parent },
1056     { WM_LBUTTONUP, posted },
1057     { BM_SETSTATE, posted },
1058     { WM_CTLCOLORBTN, posted|parent },
1059     { WM_COMMAND, posted|parent },
1060     { 0 }
1061 };
1062 /* Reparenting a button (16/32) */
1063 /* The last child (button) reparented gets topmost for its new parent. */
1064 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1065     { WM_SHOWWINDOW, sent|wparam, 0 },
1066     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1067     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1068     { WM_ERASEBKGND, sent|parent },
1069     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1070     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1071     { WM_CHILDACTIVATE, sent },
1072     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1073     { WM_MOVE, sent|defwinproc },
1074     { WM_SHOWWINDOW, sent|wparam, 1 },
1075     { 0 }
1076 };
1077 /* Creation of a custom dialog (32) */
1078 static const struct message WmCreateCustomDialogSeq[] = {
1079     { HCBT_CREATEWND, hook },
1080     { WM_GETMINMAXINFO, sent },
1081     { WM_NCCREATE, sent },
1082     { WM_NCCALCSIZE, sent|wparam, 0 },
1083     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1084     { WM_CREATE, sent },
1085     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1086     { WM_SHOWWINDOW, sent|wparam, 1 },
1087     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1088     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1089     { HCBT_ACTIVATE, hook },
1090     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1091
1092
1093     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1094
1095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1096
1097     { WM_NCACTIVATE, sent|wparam, 1 },
1098     { WM_GETTEXT, sent|optional|defwinproc },
1099     { WM_GETTEXT, sent|optional|defwinproc },
1100     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1101     { WM_ACTIVATE, sent|wparam, 1 },
1102     { WM_KILLFOCUS, sent|parent },
1103     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1104     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1105     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1106     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1107     { WM_SETFOCUS, sent },
1108     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1109     { WM_NCPAINT, sent|wparam, 1 },
1110     { WM_GETTEXT, sent|optional|defwinproc },
1111     { WM_GETTEXT, sent|optional|defwinproc },
1112     { WM_ERASEBKGND, sent },
1113     { WM_CTLCOLORDLG, sent|defwinproc },
1114     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1115     { WM_GETTEXT, sent|optional },
1116     { WM_GETTEXT, sent|optional },
1117     { WM_NCCALCSIZE, sent|optional },
1118     { WM_NCPAINT, sent|optional },
1119     { WM_GETTEXT, sent|optional|defwinproc },
1120     { WM_GETTEXT, sent|optional|defwinproc },
1121     { WM_ERASEBKGND, sent|optional },
1122     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1123     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1124     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1125     { WM_MOVE, sent },
1126     { 0 }
1127 };
1128 /* Calling EndDialog for a custom dialog (32) */
1129 static const struct message WmEndCustomDialogSeq[] = {
1130     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1131     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1132     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1133     { WM_GETTEXT, sent|optional },
1134     { HCBT_ACTIVATE, hook },
1135     { WM_NCACTIVATE, sent|wparam, 0 },
1136     { WM_GETTEXT, sent|optional|defwinproc },
1137     { WM_GETTEXT, sent|optional|defwinproc },
1138     { WM_ACTIVATE, sent|wparam, 0 },
1139     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1140     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1141     { HCBT_SETFOCUS, hook },
1142     { WM_KILLFOCUS, sent },
1143     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1144     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1145     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1146     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1147     { WM_SETFOCUS, sent|parent|defwinproc },
1148     { 0 }
1149 };
1150 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1151 static const struct message WmShowCustomDialogSeq[] = {
1152     { WM_SHOWWINDOW, sent|wparam, 1 },
1153     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1154     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1155     { HCBT_ACTIVATE, hook },
1156     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1157
1158     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1159
1160     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1161     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1162     { WM_NCACTIVATE, sent|wparam, 1 },
1163     { WM_ACTIVATE, sent|wparam, 1 },
1164
1165     { WM_KILLFOCUS, sent|parent },
1166     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1167     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1168     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1169     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1170     { WM_SETFOCUS, sent },
1171     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1172     { WM_NCPAINT, sent|wparam, 1 },
1173     { WM_ERASEBKGND, sent },
1174     { WM_CTLCOLORDLG, sent|defwinproc },
1175     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1176     { 0 }
1177 };
1178 /* Creation and destruction of a modal dialog (32) */
1179 static const struct message WmModalDialogSeq[] = {
1180     { WM_CANCELMODE, sent|parent },
1181     { HCBT_SETFOCUS, hook },
1182     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1183     { WM_KILLFOCUS, sent|parent },
1184     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1185     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1186     { WM_ENABLE, sent|parent|wparam, 0 },
1187     { HCBT_CREATEWND, hook },
1188     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1189     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1190     { WM_SETFONT, sent },
1191     { WM_INITDIALOG, sent },
1192     { WM_CHANGEUISTATE, sent|optional },
1193     { WM_UPDATEUISTATE, sent|optional },
1194     { WM_SHOWWINDOW, sent },
1195     { HCBT_ACTIVATE, hook },
1196     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1197     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1198     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1199     { WM_NCACTIVATE, sent|wparam, 1 },
1200     { WM_GETTEXT, sent|optional },
1201     { WM_ACTIVATE, sent|wparam, 1 },
1202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1203     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1204     { WM_NCPAINT, sent },
1205     { WM_GETTEXT, sent|optional },
1206     { WM_ERASEBKGND, sent },
1207     { WM_CTLCOLORDLG, sent },
1208     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1209     { WM_GETTEXT, sent|optional },
1210     { WM_NCCALCSIZE, sent|optional },
1211     { WM_NCPAINT, sent|optional },
1212     { WM_GETTEXT, sent|optional },
1213     { WM_ERASEBKGND, sent|optional },
1214     { WM_CTLCOLORDLG, sent|optional },
1215     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1216     { WM_PAINT, sent|optional },
1217     { WM_CTLCOLORBTN, sent },
1218     { WM_ENTERIDLE, sent|parent|optional },
1219     { WM_ENTERIDLE, sent|parent|optional },
1220     { WM_ENTERIDLE, sent|parent|optional },
1221     { WM_ENTERIDLE, sent|parent|optional },
1222     { WM_ENTERIDLE, sent|parent|optional },
1223     { WM_ENTERIDLE, sent|parent|optional },
1224     { WM_ENTERIDLE, sent|parent|optional },
1225     { WM_ENTERIDLE, sent|parent|optional },
1226     { WM_ENTERIDLE, sent|parent|optional },
1227     { WM_ENTERIDLE, sent|parent|optional },
1228     { WM_ENTERIDLE, sent|parent|optional },
1229     { WM_ENTERIDLE, sent|parent|optional },
1230     { WM_ENTERIDLE, sent|parent|optional },
1231     { WM_ENTERIDLE, sent|parent|optional },
1232     { WM_ENTERIDLE, sent|parent|optional },
1233     { WM_ENTERIDLE, sent|parent|optional },
1234     { WM_ENTERIDLE, sent|parent|optional },
1235     { WM_ENTERIDLE, sent|parent|optional },
1236     { WM_ENTERIDLE, sent|parent|optional },
1237     { WM_ENTERIDLE, sent|parent|optional },
1238     { WM_TIMER, sent },
1239     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1240     { WM_ENABLE, sent|parent|wparam, 1 },
1241     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1242     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1243     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1244     { WM_GETTEXT, sent|optional },
1245     { HCBT_ACTIVATE, hook },
1246     { WM_NCACTIVATE, sent|wparam, 0 },
1247     { WM_GETTEXT, sent|optional },
1248     { WM_ACTIVATE, sent|wparam, 0 },
1249     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1250     { WM_WINDOWPOSCHANGING, sent|optional },
1251     { HCBT_SETFOCUS, hook },
1252     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1253     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1254     { WM_SETFOCUS, sent|parent|defwinproc },
1255     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1256     { HCBT_DESTROYWND, hook },
1257     { 0x0090, sent|optional },
1258     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1259     { WM_DESTROY, sent },
1260     { WM_NCDESTROY, sent },
1261     { 0 }
1262 };
1263 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1264 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1265     /* (inside dialog proc, handling WM_INITDIALOG) */
1266     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1267     { WM_NCCALCSIZE, sent },
1268     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1269     { WM_GETTEXT, sent|defwinproc },
1270     { WM_ACTIVATE, sent|parent|wparam, 0 },
1271     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1272     { WM_WINDOWPOSCHANGING, sent|parent },
1273     { WM_NCACTIVATE, sent|wparam, 1 },
1274     { WM_ACTIVATE, sent|wparam, 1 },
1275     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1276     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1277     /* (setting focus) */
1278     { WM_SHOWWINDOW, sent|wparam, 1 },
1279     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1280     { WM_NCPAINT, sent },
1281     { WM_GETTEXT, sent|defwinproc },
1282     { WM_ERASEBKGND, sent },
1283     { WM_CTLCOLORDLG, sent|defwinproc },
1284     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1285     { WM_PAINT, sent },
1286     /* (bunch of WM_CTLCOLOR* for each control) */
1287     { WM_PAINT, sent|parent },
1288     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1289     { WM_SETCURSOR, sent|parent },
1290     { 0 }
1291 };
1292 /* SetMenu for NonVisible windows with size change*/
1293 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1294     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1295     { WM_NCCALCSIZE, sent|wparam, 1 },
1296     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1297     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1298     { WM_MOVE, sent|defwinproc },
1299     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1300     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1301     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1302     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1303     { WM_GETTEXT, sent|optional },
1304     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1305     { 0 }
1306 };
1307 /* SetMenu for NonVisible windows with no size change */
1308 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1309     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1310     { WM_NCCALCSIZE, sent|wparam, 1 },
1311     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1312     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1313     { 0 }
1314 };
1315 /* SetMenu for Visible windows with size change */
1316 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1317     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1318     { WM_NCCALCSIZE, sent|wparam, 1 },
1319     { 0x0093, sent|defwinproc|optional },
1320     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1321     { WM_NCPAINT, sent }, /* wparam != 1 */
1322     { 0x0093, sent|defwinproc|optional },
1323     { 0x0093, sent|defwinproc|optional },
1324     { 0x0091, sent|defwinproc|optional },
1325     { 0x0092, sent|defwinproc|optional },
1326     { WM_GETTEXT, sent|defwinproc|optional },
1327     { WM_ERASEBKGND, sent|optional },
1328     { WM_ACTIVATE, sent|optional },
1329     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1330     { WM_MOVE, sent|defwinproc },
1331     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1332     { 0x0093, sent|optional },
1333     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1334     { 0x0093, sent|defwinproc|optional },
1335     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1336     { 0x0093, sent|defwinproc|optional },
1337     { 0x0093, sent|defwinproc|optional },
1338     { 0x0091, sent|defwinproc|optional },
1339     { 0x0092, sent|defwinproc|optional },
1340     { WM_ERASEBKGND, sent|optional },
1341     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1342     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1343     { 0 }
1344 };
1345 /* SetMenu for Visible windows with no size change */
1346 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1347     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1348     { WM_NCCALCSIZE, sent|wparam, 1 },
1349     { WM_NCPAINT, sent }, /* wparam != 1 */
1350     { WM_GETTEXT, sent|defwinproc|optional },
1351     { WM_ERASEBKGND, sent|optional },
1352     { WM_ACTIVATE, sent|optional },
1353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1354     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1355     { 0 }
1356 };
1357 /* DrawMenuBar for a visible window */
1358 static const struct message WmDrawMenuBarSeq[] =
1359 {
1360     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1361     { WM_NCCALCSIZE, sent|wparam, 1 },
1362     { 0x0093, sent|defwinproc|optional },
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_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1371     { 0x0093, sent|optional },
1372     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1373     { 0 }
1374 };
1375
1376 static const struct message WmSetRedrawFalseSeq[] =
1377 {
1378     { WM_SETREDRAW, sent|wparam, 0 },
1379     { 0 }
1380 };
1381
1382 static const struct message WmSetRedrawTrueSeq[] =
1383 {
1384     { WM_SETREDRAW, sent|wparam, 1 },
1385     { 0 }
1386 };
1387
1388 static const struct message WmEnableWindowSeq_1[] =
1389 {
1390     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1391     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1392     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1393     { 0 }
1394 };
1395
1396 static const struct message WmEnableWindowSeq_2[] =
1397 {
1398     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1399     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1400     { 0 }
1401 };
1402
1403 static const struct message WmGetScrollRangeSeq[] =
1404 {
1405     { SBM_GETRANGE, sent },
1406     { 0 }
1407 };
1408 static const struct message WmGetScrollInfoSeq[] =
1409 {
1410     { SBM_GETSCROLLINFO, sent },
1411     { 0 }
1412 };
1413 static const struct message WmSetScrollRangeSeq[] =
1414 {
1415     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1416        sends SBM_SETSCROLLINFO.
1417      */
1418     { SBM_SETSCROLLINFO, sent },
1419     { 0 }
1420 };
1421 /* SetScrollRange for a window without a non-client area */
1422 static const struct message WmSetScrollRangeHSeq_empty[] =
1423 {
1424     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1425     { 0 }
1426 };
1427 static const struct message WmSetScrollRangeVSeq_empty[] =
1428 {
1429     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1430     { 0 }
1431 };
1432 static const struct message WmSetScrollRangeHVSeq[] =
1433 {
1434     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1435     { WM_NCCALCSIZE, sent|wparam, 1 },
1436     { WM_GETTEXT, sent|defwinproc|optional },
1437     { WM_ERASEBKGND, sent|optional },
1438     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1439     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1440     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1441     { 0 }
1442 };
1443 /* SetScrollRange for a window with a non-client area */
1444 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1445 {
1446     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1447     { WM_NCCALCSIZE, sent|wparam, 1 },
1448     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1449     { WM_NCPAINT, sent|optional },
1450     { WM_STYLECHANGING, sent|defwinproc|optional },
1451     { WM_STYLECHANGED, sent|defwinproc|optional },
1452     { WM_STYLECHANGING, sent|defwinproc|optional },
1453     { WM_STYLECHANGED, sent|defwinproc|optional },
1454     { WM_STYLECHANGING, sent|defwinproc|optional },
1455     { WM_STYLECHANGED, sent|defwinproc|optional },
1456     { WM_STYLECHANGING, sent|defwinproc|optional },
1457     { WM_STYLECHANGED, sent|defwinproc|optional },
1458     { WM_GETTEXT, sent|defwinproc|optional },
1459     { WM_GETTEXT, sent|defwinproc|optional },
1460     { WM_ERASEBKGND, sent|optional },
1461     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1462     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1463     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1464     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1465     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1466     { WM_GETTEXT, sent|optional },
1467     { WM_GETTEXT, sent|optional },
1468     { WM_GETTEXT, sent|optional },
1469     { WM_GETTEXT, sent|optional },
1470     { 0 }
1471 };
1472 /* test if we receive the right sequence of messages */
1473 /* after calling ShowWindow( SW_SHOWNA) */
1474 static const struct message WmSHOWNAChildInvisParInvis[] = {
1475     { WM_SHOWWINDOW, sent|wparam, 1 },
1476     { 0 }
1477 };
1478 static const struct message WmSHOWNAChildVisParInvis[] = {
1479     { WM_SHOWWINDOW, sent|wparam, 1 },
1480     { 0 }
1481 };
1482 static const struct message WmSHOWNAChildVisParVis[] = {
1483     { WM_SHOWWINDOW, sent|wparam, 1 },
1484     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1485     { 0 }
1486 };
1487 static const struct message WmSHOWNAChildInvisParVis[] = {
1488     { WM_SHOWWINDOW, sent|wparam, 1 },
1489     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1490     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1491     { WM_ERASEBKGND, sent|optional },
1492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1493     { 0 }
1494 };
1495 static const struct message WmSHOWNATopVisible[] = {
1496     { WM_SHOWWINDOW, sent|wparam, 1 },
1497     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1498     { 0 }
1499 };
1500 static const struct message WmSHOWNATopInvisible[] = {
1501     { WM_SHOWWINDOW, sent|wparam, 1 },
1502     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1503     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1504     { WM_NCPAINT, sent|wparam, 1 },
1505     { WM_GETTEXT, sent|defwinproc|optional },
1506     { WM_ERASEBKGND, sent|optional },
1507     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1508     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1509     { WM_NCPAINT, sent|wparam|optional, 1 },
1510     { WM_ERASEBKGND, sent|optional },
1511     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1512     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1513     { WM_MOVE, sent },
1514     { 0 }
1515 };
1516
1517 static int after_end_dialog, test_def_id;
1518 static int sequence_cnt, sequence_size;
1519 static struct message* sequence;
1520 static int log_all_parent_messages;
1521
1522 /* user32 functions */
1523 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1524 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1525 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1526 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1527 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1528 /* kernel32 functions */
1529 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1530
1531 static void init_procs(void)
1532 {
1533     HMODULE user32 = GetModuleHandleA("user32.dll");
1534     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1535
1536 #define GET_PROC(dll, func) \
1537     p ## func = (void*)GetProcAddress(dll, #func); \
1538     if(!p ## func) { \
1539       trace("GetProcAddress(%s) failed\n", #func); \
1540     }
1541
1542     GET_PROC(user32, GetAncestor)
1543     GET_PROC(user32, NotifyWinEvent)
1544     GET_PROC(user32, SetWinEventHook)
1545     GET_PROC(user32, TrackMouseEvent)
1546     GET_PROC(user32, UnhookWinEvent)
1547
1548     GET_PROC(kernel32, GetCPInfoExA)
1549
1550 #undef GET_PROC
1551 }
1552
1553 static void add_message(const struct message *msg)
1554 {
1555     if (!sequence) 
1556     {
1557         sequence_size = 10;
1558         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1559     }
1560     if (sequence_cnt == sequence_size) 
1561     {
1562         sequence_size *= 2;
1563         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1564     }
1565     assert(sequence);
1566
1567     sequence[sequence_cnt].message = msg->message;
1568     sequence[sequence_cnt].flags = msg->flags;
1569     sequence[sequence_cnt].wParam = msg->wParam;
1570     sequence[sequence_cnt].lParam = msg->lParam;
1571
1572     sequence_cnt++;
1573 }
1574
1575 /* try to make sure pending X events have been processed before continuing */
1576 static void flush_events(void)
1577 {
1578     MSG msg;
1579     int diff = 200;
1580     int min_timeout = 50;
1581     DWORD time = GetTickCount() + diff;
1582
1583     while (diff > 0)
1584     {
1585         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1586         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1587         diff = time - GetTickCount();
1588         min_timeout = 10;
1589     }
1590 }
1591
1592 static void flush_sequence(void)
1593 {
1594     HeapFree(GetProcessHeap(), 0, sequence);
1595     sequence = 0;
1596     sequence_cnt = sequence_size = 0;
1597 }
1598
1599 #define ok_sequence( exp, contx, todo) \
1600         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1601
1602
1603 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1604         const char *file, int line)
1605 {
1606     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1607     const struct message *actual;
1608     int failcount = 0;
1609     
1610     add_message(&end_of_sequence);
1611
1612     actual = sequence;
1613
1614     while (expected->message && actual->message)
1615     {
1616         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1617
1618         if (expected->message == actual->message)
1619         {
1620             if (expected->flags & wparam)
1621             {
1622                 if (expected->wParam != actual->wParam && todo)
1623                 {
1624                     todo_wine {
1625                         failcount ++;
1626                         ok_( file, line) (FALSE,
1627                             "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1628                             context, expected->message, expected->wParam, actual->wParam);
1629                     }
1630                 }
1631                 else
1632                 ok_( file, line) (expected->wParam == actual->wParam,
1633                      "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1634                      context, expected->message, expected->wParam, actual->wParam);
1635             }
1636             if (expected->flags & lparam)
1637             {
1638                 if (expected->lParam != actual->lParam && todo)
1639                 {
1640                     todo_wine {
1641                         failcount ++;
1642                         ok_( file, line) (FALSE,
1643                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1644                             context, expected->message, expected->lParam, actual->lParam);
1645                     }
1646                 }
1647                 else
1648                  ok_( file, line) (expected->lParam == actual->lParam,
1649                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1650                      context, expected->message, expected->lParam, actual->lParam);
1651             }
1652             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1653             {
1654                     todo_wine {
1655                         failcount ++;
1656                         ok_( file, line) (FALSE,
1657                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1658                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1659                     }
1660             }
1661             else
1662                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1663                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1664                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1665             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1666                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1667                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1668             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1669                 "%s: the msg 0x%04x should have been %s\n",
1670                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1671             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1672                 "%s: the msg 0x%04x was expected in %s\n",
1673                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1674             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1675                 "%s: the msg 0x%04x should have been sent by a hook\n",
1676                 context, expected->message);
1677             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1678                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1679                 context, expected->message);
1680             expected++;
1681             actual++;
1682         }
1683         /* silently drop winevent messages if there is no support for them */
1684         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1685             expected++;
1686         else if (todo)
1687         {
1688             failcount++;
1689             todo_wine {
1690                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1691                     context, expected->message, actual->message);
1692             }
1693             flush_sequence();
1694             return;
1695         }
1696         else
1697         {
1698             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1699                 context, expected->message, actual->message);
1700             expected++;
1701             actual++;
1702         }
1703     }
1704
1705     /* skip all optional trailing messages */
1706     while (expected->message && ((expected->flags & optional) ||
1707             ((expected->flags & winevent_hook) && !hEvent_hook)))
1708         expected++;
1709
1710     if (todo)
1711     {
1712         todo_wine {
1713             if (expected->message || actual->message) {
1714                 failcount++;
1715                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1716                     context, expected->message, actual->message);
1717             }
1718         }
1719     }
1720     else
1721     {
1722         if (expected->message || actual->message)
1723             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1724                 context, expected->message, actual->message);
1725     }
1726     if( todo && !failcount) /* succeeded yet marked todo */
1727         todo_wine {
1728             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1729         }
1730
1731     flush_sequence();
1732 }
1733
1734 /******************************** MDI test **********************************/
1735
1736 /* CreateWindow for MDI frame window, initially visible */
1737 static const struct message WmCreateMDIframeSeq[] = {
1738     { HCBT_CREATEWND, hook },
1739     { WM_GETMINMAXINFO, sent },
1740     { WM_NCCREATE, sent },
1741     { WM_NCCALCSIZE, sent|wparam, 0 },
1742     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1743     { WM_CREATE, sent },
1744     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1745     { WM_SHOWWINDOW, sent|wparam, 1 },
1746     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1747     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1748     { HCBT_ACTIVATE, hook },
1749     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1750     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1751     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1752     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1753     { WM_NCACTIVATE, sent|wparam, 1 },
1754     { WM_GETTEXT, sent|defwinproc|optional },
1755     { WM_ACTIVATE, sent|wparam, 1 },
1756     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1757     { HCBT_SETFOCUS, hook },
1758     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1759     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1760     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1761     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1762     /* Win9x adds SWP_NOZORDER below */
1763     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1764     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1765     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1766     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1767     { WM_MOVE, sent },
1768     { 0 }
1769 };
1770 /* DestroyWindow for MDI frame window, initially visible */
1771 static const struct message WmDestroyMDIframeSeq[] = {
1772     { HCBT_DESTROYWND, hook },
1773     { 0x0090, sent|optional },
1774     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1775     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1776     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1777     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1778     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1779     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1780     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1781     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1782     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1783     { WM_DESTROY, sent },
1784     { WM_NCDESTROY, sent },
1785     { 0 }
1786 };
1787 /* CreateWindow for MDI client window, initially visible */
1788 static const struct message WmCreateMDIclientSeq[] = {
1789     { HCBT_CREATEWND, hook },
1790     { WM_NCCREATE, sent },
1791     { WM_NCCALCSIZE, sent|wparam, 0 },
1792     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1793     { WM_CREATE, sent },
1794     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1795     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1796     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1797     { WM_MOVE, sent },
1798     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1799     { WM_SHOWWINDOW, sent|wparam, 1 },
1800     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1801     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1802     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1803     { 0 }
1804 };
1805 /* ShowWindow(SW_SHOW) for MDI client window */
1806 static const struct message WmShowMDIclientSeq[] = {
1807     { WM_SHOWWINDOW, sent|wparam, 1 },
1808     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1809     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1810     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1811     { 0 }
1812 };
1813 /* ShowWindow(SW_HIDE) for MDI client window */
1814 static const struct message WmHideMDIclientSeq[] = {
1815     { WM_SHOWWINDOW, sent|wparam, 0 },
1816     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1817     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1818     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1819     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1820     { 0 }
1821 };
1822 /* DestroyWindow for MDI client window, initially visible */
1823 static const struct message WmDestroyMDIclientSeq[] = {
1824     { HCBT_DESTROYWND, hook },
1825     { 0x0090, sent|optional },
1826     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1827     { WM_SHOWWINDOW, sent|wparam, 0 },
1828     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1829     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1830     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1831     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1832     { WM_DESTROY, sent },
1833     { WM_NCDESTROY, sent },
1834     { 0 }
1835 };
1836 /* CreateWindow for MDI child window, initially visible */
1837 static const struct message WmCreateMDIchildVisibleSeq[] = {
1838     { HCBT_CREATEWND, hook },
1839     { WM_NCCREATE, sent }, 
1840     { WM_NCCALCSIZE, sent|wparam, 0 },
1841     { WM_CREATE, sent },
1842     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1843     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1844     { WM_MOVE, sent },
1845     /* Win2k sends wparam set to
1846      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1847      * while Win9x doesn't bother to set child window id according to
1848      * CLIENTCREATESTRUCT.idFirstChild
1849      */
1850     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1851     { WM_SHOWWINDOW, sent|wparam, 1 },
1852     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1853     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1854     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1855     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1856     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1857     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1858     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1859
1860     /* Win9x: message sequence terminates here. */
1861
1862     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1863     { HCBT_SETFOCUS, hook }, /* in MDI client */
1864     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1865     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1866     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1867     { WM_SETFOCUS, sent }, /* in MDI client */
1868     { HCBT_SETFOCUS, hook },
1869     { WM_KILLFOCUS, sent }, /* in MDI client */
1870     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1871     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1872     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1873     { WM_SETFOCUS, sent|defwinproc },
1874     { WM_MDIACTIVATE, sent|defwinproc },
1875     { 0 }
1876 };
1877 /* CreateWindow for MDI child window with invisible parent */
1878 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1879     { HCBT_CREATEWND, hook },
1880     { WM_GETMINMAXINFO, sent },
1881     { WM_NCCREATE, sent }, 
1882     { WM_NCCALCSIZE, sent|wparam, 0 },
1883     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1884     { WM_CREATE, sent },
1885     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1886     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1887     { WM_MOVE, sent },
1888     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1889     { WM_SHOWWINDOW, sent|wparam, 1 },
1890     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1891     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1892     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1893     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1894
1895     /* Win9x: message sequence terminates here. */
1896
1897     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1898     { HCBT_SETFOCUS, hook }, /* in MDI client */
1899     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1900     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1901     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1902     { WM_SETFOCUS, sent }, /* in MDI client */
1903     { HCBT_SETFOCUS, hook },
1904     { WM_KILLFOCUS, sent }, /* in MDI client */
1905     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1906     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1907     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1908     { WM_SETFOCUS, sent|defwinproc },
1909     { WM_MDIACTIVATE, sent|defwinproc },
1910     { 0 }
1911 };
1912 /* DestroyWindow for MDI child window, initially visible */
1913 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1914     { HCBT_DESTROYWND, hook },
1915     /* Win2k sends wparam set to
1916      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1917      * while Win9x doesn't bother to set child window id according to
1918      * CLIENTCREATESTRUCT.idFirstChild
1919      */
1920     { 0x0090, sent|optional },
1921     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1922     { WM_SHOWWINDOW, sent|wparam, 0 },
1923     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1924     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1925     { WM_ERASEBKGND, sent|parent|optional },
1926     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1927
1928     /* { WM_DESTROY, sent }
1929      * Win9x: message sequence terminates here.
1930      */
1931
1932     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1933     { WM_KILLFOCUS, sent },
1934     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1935     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1936     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1937     { WM_SETFOCUS, sent }, /* in MDI client */
1938
1939     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1940     { WM_KILLFOCUS, sent }, /* in MDI client */
1941     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1942     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1943     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1944     { WM_SETFOCUS, sent }, /* in MDI client */
1945
1946     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1947
1948     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1949     { WM_KILLFOCUS, sent },
1950     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1951     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1952     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1953     { WM_SETFOCUS, sent }, /* in MDI client */
1954
1955     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1956     { WM_KILLFOCUS, sent }, /* in MDI client */
1957     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1958     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1959     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1960     { WM_SETFOCUS, sent }, /* in MDI client */
1961
1962     { WM_DESTROY, sent },
1963
1964     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1965     { WM_KILLFOCUS, sent },
1966     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1967     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1968     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1969     { WM_SETFOCUS, sent }, /* in MDI client */
1970
1971     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1972     { WM_KILLFOCUS, sent }, /* in MDI client */
1973     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1974     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1975     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1976     { WM_SETFOCUS, sent }, /* in MDI client */
1977
1978     { WM_NCDESTROY, sent },
1979     { 0 }
1980 };
1981 /* CreateWindow for MDI child window, initially invisible */
1982 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1983     { HCBT_CREATEWND, hook },
1984     { WM_NCCREATE, sent }, 
1985     { WM_NCCALCSIZE, sent|wparam, 0 },
1986     { WM_CREATE, sent },
1987     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1988     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1989     { WM_MOVE, sent },
1990     /* Win2k sends wparam set to
1991      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1992      * while Win9x doesn't bother to set child window id according to
1993      * CLIENTCREATESTRUCT.idFirstChild
1994      */
1995     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1996     { 0 }
1997 };
1998 /* DestroyWindow for MDI child window, initially invisible */
1999 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2000     { HCBT_DESTROYWND, hook },
2001     /* Win2k sends wparam set to
2002      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2003      * while Win9x doesn't bother to set child window id according to
2004      * CLIENTCREATESTRUCT.idFirstChild
2005      */
2006     { 0x0090, sent|optional },
2007     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2008     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2009     { WM_DESTROY, sent },
2010     { WM_NCDESTROY, sent },
2011     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2012     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2013     { 0 }
2014 };
2015 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2016 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2017     { HCBT_CREATEWND, hook },
2018     { WM_NCCREATE, sent }, 
2019     { WM_NCCALCSIZE, sent|wparam, 0 },
2020     { WM_CREATE, sent },
2021     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2022     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2023     { WM_MOVE, sent },
2024     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2025     { WM_GETMINMAXINFO, sent },
2026     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2027     { WM_NCCALCSIZE, sent|wparam, 1 },
2028     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2029     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2030      /* in MDI frame */
2031     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2032     { WM_NCCALCSIZE, sent|wparam, 1 },
2033     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2034     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2035     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2036     /* Win2k sends wparam set to
2037      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2038      * while Win9x doesn't bother to set child window id according to
2039      * CLIENTCREATESTRUCT.idFirstChild
2040      */
2041     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2042     { WM_SHOWWINDOW, sent|wparam, 1 },
2043     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2044     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2045     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2046     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2047     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2048     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2049     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2050
2051     /* Win9x: message sequence terminates here. */
2052
2053     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2054     { HCBT_SETFOCUS, hook }, /* in MDI client */
2055     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2056     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2057     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2058     { WM_SETFOCUS, sent }, /* in MDI client */
2059     { HCBT_SETFOCUS, hook },
2060     { WM_KILLFOCUS, sent }, /* in MDI client */
2061     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2062     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2063     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2064     { WM_SETFOCUS, sent|defwinproc },
2065     { WM_MDIACTIVATE, sent|defwinproc },
2066      /* in MDI frame */
2067     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2068     { WM_NCCALCSIZE, sent|wparam, 1 },
2069     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2070     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2071     { 0 }
2072 };
2073 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2074 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2075     /* restore the 1st MDI child */
2076     { WM_SETREDRAW, sent|wparam, 0 },
2077     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2078     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2079     { WM_NCCALCSIZE, sent|wparam, 1 },
2080     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2081     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2082     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2083      /* in MDI frame */
2084     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2085     { WM_NCCALCSIZE, sent|wparam, 1 },
2086     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2087     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2088     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2089     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2090     /* create the 2nd MDI child */
2091     { HCBT_CREATEWND, hook },
2092     { WM_NCCREATE, sent }, 
2093     { WM_NCCALCSIZE, sent|wparam, 0 },
2094     { WM_CREATE, sent },
2095     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2096     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2097     { WM_MOVE, sent },
2098     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2099     { WM_GETMINMAXINFO, sent },
2100     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2101     { WM_NCCALCSIZE, sent|wparam, 1 },
2102     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2103     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2104     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2105      /* in MDI frame */
2106     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2107     { WM_NCCALCSIZE, sent|wparam, 1 },
2108     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2109     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2110     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2111     /* Win2k sends wparam set to
2112      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2113      * while Win9x doesn't bother to set child window id according to
2114      * CLIENTCREATESTRUCT.idFirstChild
2115      */
2116     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2117     { WM_SHOWWINDOW, sent|wparam, 1 },
2118     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2119     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2120     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2121     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2122     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2123     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2124
2125     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2126     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2127
2128     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2129
2130     /* Win9x: message sequence terminates here. */
2131
2132     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2133     { HCBT_SETFOCUS, hook },
2134     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
2135     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2136     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2137     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2138     { WM_SETFOCUS, sent }, /* in MDI client */
2139     { HCBT_SETFOCUS, hook },
2140     { WM_KILLFOCUS, sent }, /* in MDI client */
2141     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2142     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2143     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2144     { WM_SETFOCUS, sent|defwinproc },
2145
2146     { WM_MDIACTIVATE, sent|defwinproc },
2147      /* in MDI frame */
2148     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2149     { WM_NCCALCSIZE, sent|wparam, 1 },
2150     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2151     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2152     { 0 }
2153 };
2154 /* WM_MDICREATE MDI child window, initially visible and maximized */
2155 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2156     { WM_MDICREATE, sent },
2157     { HCBT_CREATEWND, hook },
2158     { WM_NCCREATE, sent }, 
2159     { WM_NCCALCSIZE, sent|wparam, 0 },
2160     { WM_CREATE, sent },
2161     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2162     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2163     { WM_MOVE, sent },
2164     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2165     { WM_GETMINMAXINFO, sent },
2166     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2167     { WM_NCCALCSIZE, sent|wparam, 1 },
2168     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2169     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2170
2171      /* in MDI frame */
2172     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2173     { WM_NCCALCSIZE, sent|wparam, 1 },
2174     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2175     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2176     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2177
2178     /* Win2k sends wparam set to
2179      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2180      * while Win9x doesn't bother to set child window id according to
2181      * CLIENTCREATESTRUCT.idFirstChild
2182      */
2183     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2184     { WM_SHOWWINDOW, sent|wparam, 1 },
2185     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2186
2187     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2188
2189     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2190     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2191     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2192
2193     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2194     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2195
2196     /* Win9x: message sequence terminates here. */
2197
2198     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2199     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2200     { HCBT_SETFOCUS, hook }, /* in MDI client */
2201     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2202     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2203     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2204     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2205     { HCBT_SETFOCUS, hook|optional },
2206     { WM_KILLFOCUS, sent }, /* in MDI client */
2207     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2208     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2209     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2210     { WM_SETFOCUS, sent|defwinproc },
2211
2212     { WM_MDIACTIVATE, sent|defwinproc },
2213
2214      /* in MDI child */
2215     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2216     { WM_NCCALCSIZE, sent|wparam, 1 },
2217     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2218     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2219
2220      /* in MDI frame */
2221     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2222     { WM_NCCALCSIZE, sent|wparam, 1 },
2223     { 0x0093, sent|defwinproc|optional },
2224     { 0x0093, sent|defwinproc|optional },
2225     { 0x0093, sent|defwinproc|optional },
2226     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2227     { WM_MOVE, sent|defwinproc },
2228     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2229
2230      /* in MDI client */
2231     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2232     { WM_NCCALCSIZE, sent|wparam, 1 },
2233     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2234     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2235
2236      /* in MDI child */
2237     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2238     { WM_NCCALCSIZE, sent|wparam, 1 },
2239     { 0x0093, sent|optional },
2240     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2241     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2242
2243     { 0x0093, sent|optional },
2244     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2245     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2246     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2247     { 0x0093, sent|defwinproc|optional },
2248     { 0x0093, sent|defwinproc|optional },
2249     { 0x0093, sent|defwinproc|optional },
2250     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2251     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2252
2253     { 0 }
2254 };
2255 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2256 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2257     { HCBT_CREATEWND, hook },
2258     { WM_GETMINMAXINFO, sent },
2259     { WM_NCCREATE, sent }, 
2260     { WM_NCCALCSIZE, sent|wparam, 0 },
2261     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2262     { WM_CREATE, sent },
2263     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2264     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2265     { WM_MOVE, sent },
2266     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2267     { WM_GETMINMAXINFO, sent },
2268     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2269     { WM_GETMINMAXINFO, sent|defwinproc },
2270     { WM_NCCALCSIZE, sent|wparam, 1 },
2271     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2272     { WM_MOVE, sent|defwinproc },
2273     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2274      /* in MDI frame */
2275     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276     { WM_NCCALCSIZE, sent|wparam, 1 },
2277     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2278     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2279     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2280     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2281     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2282     /* Win2k sends wparam set to
2283      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2284      * while Win9x doesn't bother to set child window id according to
2285      * CLIENTCREATESTRUCT.idFirstChild
2286      */
2287     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2288     { 0 }
2289 };
2290 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2291 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2292     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2293     { HCBT_SYSCOMMAND, hook },
2294     { WM_CLOSE, sent|defwinproc },
2295     { WM_MDIDESTROY, sent }, /* in MDI client */
2296
2297     /* bring the 1st MDI child to top */
2298     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2299     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2300
2301     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2302
2303     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2304     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2305     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2306
2307     /* maximize the 1st MDI child */
2308     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2309     { WM_GETMINMAXINFO, sent|defwinproc },
2310     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2311     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2312     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2313     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2314     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2315
2316     /* restore the 2nd MDI child */
2317     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2318     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2319     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2320     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2321
2322     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2323
2324     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2325     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2326
2327     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2328
2329     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2330      /* in MDI frame */
2331     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2332     { WM_NCCALCSIZE, sent|wparam, 1 },
2333     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2334     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2335     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2336
2337     /* bring the 1st MDI child to top */
2338     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2339     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2340     { HCBT_SETFOCUS, hook },
2341     { WM_KILLFOCUS, sent|defwinproc },
2342     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2343     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2344     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2345     { WM_SETFOCUS, sent }, /* in MDI client */
2346     { HCBT_SETFOCUS, hook },
2347     { WM_KILLFOCUS, sent }, /* in MDI client */
2348     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2349     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2350     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2351     { WM_SETFOCUS, sent|defwinproc },
2352     { WM_MDIACTIVATE, sent|defwinproc },
2353     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2354
2355     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2356     { WM_SHOWWINDOW, sent|wparam, 1 },
2357     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2358     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2359     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2360     { WM_MDIREFRESHMENU, sent },
2361
2362     { HCBT_DESTROYWND, hook },
2363     /* Win2k sends wparam set to
2364      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2365      * while Win9x doesn't bother to set child window id according to
2366      * CLIENTCREATESTRUCT.idFirstChild
2367      */
2368     { 0x0090, sent|defwinproc|optional },
2369     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2370     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2371     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2372     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2373     { WM_ERASEBKGND, sent|parent|optional },
2374     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2375
2376     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2377     { WM_DESTROY, sent|defwinproc },
2378     { WM_NCDESTROY, sent|defwinproc },
2379     { 0 }
2380 };
2381 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2382 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2383     { WM_MDIDESTROY, sent }, /* in MDI client */
2384     { WM_SHOWWINDOW, sent|wparam, 0 },
2385     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2386     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2387     { WM_ERASEBKGND, sent|parent|optional },
2388     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2389
2390     { HCBT_SETFOCUS, hook },
2391     { WM_KILLFOCUS, sent },
2392     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2393     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2394     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2395     { WM_SETFOCUS, sent }, /* in MDI client */
2396     { HCBT_SETFOCUS, hook },
2397     { WM_KILLFOCUS, sent }, /* in MDI client */
2398     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2399     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2400     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2401     { WM_SETFOCUS, sent },
2402
2403      /* in MDI child */
2404     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2405     { WM_NCCALCSIZE, sent|wparam, 1 },
2406     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2407     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2408
2409      /* in MDI frame */
2410     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2411     { WM_NCCALCSIZE, sent|wparam, 1 },
2412     { 0x0093, sent|defwinproc|optional },
2413     { 0x0093, sent|defwinproc|optional },
2414     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2415     { WM_MOVE, sent|defwinproc },
2416     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2417
2418      /* in MDI client */
2419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2420     { WM_NCCALCSIZE, sent|wparam, 1 },
2421     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2422     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2423
2424      /* in MDI child */
2425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2426     { WM_NCCALCSIZE, sent|wparam, 1 },
2427     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2428     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2429
2430      /* in MDI child */
2431     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2432     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2433     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2434     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2435
2436      /* in MDI frame */
2437     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2438     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2439     { 0x0093, sent|defwinproc|optional },
2440     { 0x0093, sent|defwinproc|optional },
2441     { 0x0093, sent|defwinproc|optional },
2442     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2443     { WM_MOVE, sent|defwinproc },
2444     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2445
2446      /* in MDI client */
2447     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2448     { WM_NCCALCSIZE, sent|wparam, 1 },
2449     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2450     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2451
2452      /* in MDI child */
2453     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2454     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2455     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2456     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2457     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2459
2460     { 0x0093, sent|defwinproc|optional },
2461     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2462     { 0x0093, sent|defwinproc|optional },
2463     { 0x0093, sent|defwinproc|optional },
2464     { 0x0093, sent|defwinproc|optional },
2465     { 0x0093, sent|optional },
2466
2467     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2468     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2469     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2470     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2471     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2472
2473      /* in MDI frame */
2474     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2475     { WM_NCCALCSIZE, sent|wparam, 1 },
2476     { 0x0093, sent|defwinproc|optional },
2477     { 0x0093, sent|defwinproc|optional },
2478     { 0x0093, sent|defwinproc|optional },
2479     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2480     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2481     { 0x0093, sent|optional },
2482
2483     { WM_NCACTIVATE, sent|wparam, 0 },
2484     { WM_MDIACTIVATE, sent },
2485
2486     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2487     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2488     { WM_NCCALCSIZE, sent|wparam, 1 },
2489
2490     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2491
2492     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2493     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2494     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2495
2496      /* in MDI child */
2497     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2498     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2499     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2500     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2501
2502      /* in MDI frame */
2503     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2504     { WM_NCCALCSIZE, sent|wparam, 1 },
2505     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2506     { WM_MOVE, sent|defwinproc },
2507     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2508
2509      /* in MDI client */
2510     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2511     { WM_NCCALCSIZE, sent|wparam, 1 },
2512     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2513     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2514     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2515     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2516     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2517     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2518     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2519
2520     { HCBT_SETFOCUS, hook },
2521     { WM_KILLFOCUS, sent },
2522     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2523     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2524     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2525     { WM_SETFOCUS, sent }, /* in MDI client */
2526
2527     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2528
2529     { HCBT_DESTROYWND, hook },
2530     /* Win2k sends wparam set to
2531      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2532      * while Win9x doesn't bother to set child window id according to
2533      * CLIENTCREATESTRUCT.idFirstChild
2534      */
2535     { 0x0090, sent|optional },
2536     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2537
2538     { WM_SHOWWINDOW, sent|wparam, 0 },
2539     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2540     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2541     { WM_ERASEBKGND, sent|parent|optional },
2542     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2543
2544     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2545     { WM_DESTROY, sent },
2546     { WM_NCDESTROY, sent },
2547     { 0 }
2548 };
2549 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2550 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2551     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2552     { WM_GETMINMAXINFO, sent },
2553     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2554     { WM_NCCALCSIZE, sent|wparam, 1 },
2555     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2556     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2557
2558     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2559     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2560     { HCBT_SETFOCUS, hook },
2561     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2562     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2563     { WM_SETFOCUS, sent }, /* in MDI client */
2564     { HCBT_SETFOCUS, hook },
2565     { WM_KILLFOCUS, sent }, /* in MDI client */
2566     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2567     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2568     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2569     { WM_SETFOCUS, sent|defwinproc },
2570     { WM_MDIACTIVATE, sent|defwinproc },
2571     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2572     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2573      /* in MDI frame */
2574     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2575     { WM_NCCALCSIZE, sent|wparam, 1 },
2576     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2577     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2578     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2579     { 0 }
2580 };
2581 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2582 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2583     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2584     { WM_GETMINMAXINFO, sent },
2585     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2586     { WM_GETMINMAXINFO, sent|defwinproc },
2587     { WM_NCCALCSIZE, sent|wparam, 1 },
2588     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2589     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2590
2591     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2592     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2593     { HCBT_SETFOCUS, hook },
2594     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2595     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2596     { WM_SETFOCUS, sent }, /* in MDI client */
2597     { HCBT_SETFOCUS, hook },
2598     { WM_KILLFOCUS, sent }, /* in MDI client */
2599     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2600     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2601     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2602     { WM_SETFOCUS, sent|defwinproc },
2603     { WM_MDIACTIVATE, sent|defwinproc },
2604     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2605     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2606     { 0 }
2607 };
2608 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2609 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2610     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2611     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2612     { WM_GETMINMAXINFO, sent },
2613     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2614     { WM_GETMINMAXINFO, sent|defwinproc },
2615     { WM_NCCALCSIZE, sent|wparam, 1 },
2616     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2617     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2618     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2619     { WM_MOVE, sent|defwinproc },
2620     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2621
2622     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2623     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2624     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2625     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2626     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2627     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2628      /* in MDI frame */
2629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2630     { WM_NCCALCSIZE, sent|wparam, 1 },
2631     { 0x0093, sent|defwinproc|optional },
2632     { 0x0094, sent|defwinproc|optional },
2633     { 0x0094, sent|defwinproc|optional },
2634     { 0x0094, sent|defwinproc|optional },
2635     { 0x0094, sent|defwinproc|optional },
2636     { 0x0093, sent|defwinproc|optional },
2637     { 0x0093, sent|defwinproc|optional },
2638     { 0x0091, sent|defwinproc|optional },
2639     { 0x0092, sent|defwinproc|optional },
2640     { 0x0092, sent|defwinproc|optional },
2641     { 0x0092, sent|defwinproc|optional },
2642     { 0x0092, sent|defwinproc|optional },
2643     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2644     { WM_MOVE, sent|defwinproc },
2645     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2646     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2647      /* in MDI client */
2648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2649     { WM_NCCALCSIZE, sent|wparam, 1 },
2650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2651     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2652      /* in MDI child */
2653     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2654     { WM_GETMINMAXINFO, sent|defwinproc },
2655     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2656     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2657     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2658     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2659     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2660     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2661     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2662     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2663      /* in MDI frame */
2664     { 0x0093, sent|optional },
2665     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2666     { 0x0093, sent|defwinproc|optional },
2667     { 0x0093, sent|defwinproc|optional },
2668     { 0x0093, sent|defwinproc|optional },
2669     { 0x0091, sent|defwinproc|optional },
2670     { 0x0092, sent|defwinproc|optional },
2671     { 0x0092, sent|defwinproc|optional },
2672     { 0x0092, sent|defwinproc|optional },
2673     { 0x0092, sent|defwinproc|optional },
2674     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2675     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2676     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2677     { 0 }
2678 };
2679 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2680 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2681     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2682     { WM_GETMINMAXINFO, sent },
2683     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2684     { WM_NCCALCSIZE, sent|wparam, 1 },
2685     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2686     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2687     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2688      /* in MDI frame */
2689     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2690     { WM_NCCALCSIZE, sent|wparam, 1 },
2691     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2692     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2693     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2694     { 0 }
2695 };
2696 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2697 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2698     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2699     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2700     { WM_NCCALCSIZE, sent|wparam, 1 },
2701     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2702     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2703     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2704      /* in MDI frame */
2705     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2706     { WM_NCCALCSIZE, sent|wparam, 1 },
2707     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2708     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2709     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2710     { 0 }
2711 };
2712 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2713 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2714     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2715     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2716     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
2717     { WM_NCCALCSIZE, sent|wparam, 1 },
2718     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2719     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2720     { WM_MOVE, sent|defwinproc },
2721     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2722     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2723     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2724     { HCBT_SETFOCUS, hook },
2725     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2726     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2727     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2728     { WM_SETFOCUS, sent },
2729     { 0 }
2730 };
2731 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2732 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2733     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2734     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
2735     { WM_NCCALCSIZE, sent|wparam, 1 },
2736     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2737     { WM_MOVE, sent|defwinproc },
2738     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2739     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2740     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2741     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2742     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2743     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2744     { 0 }
2745 };
2746 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2747 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2748     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2749     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
2750     { WM_NCCALCSIZE, sent|wparam, 1 },
2751     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2752     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2753     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2754     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2755      /* in MDI frame */
2756     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2757     { WM_NCCALCSIZE, sent|wparam, 1 },
2758     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2759     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2760     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2761     { 0 }
2762 };
2763
2764 static HWND mdi_client;
2765 static WNDPROC old_mdi_client_proc;
2766
2767 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2768 {
2769     struct message msg;
2770
2771     /* do not log painting messages */
2772     if (message != WM_PAINT &&
2773         message != WM_NCPAINT &&
2774         message != WM_SYNCPAINT &&
2775         message != WM_ERASEBKGND &&
2776         message != WM_NCHITTEST &&
2777         message != WM_GETTEXT &&
2778         message != WM_MDIGETACTIVE &&
2779         message != WM_GETICON &&
2780         message != WM_DEVICECHANGE)
2781     {
2782         trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2783
2784         switch (message)
2785         {
2786             case WM_WINDOWPOSCHANGING:
2787             case WM_WINDOWPOSCHANGED:
2788             {
2789                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2790
2791                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2792                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2793                       winpos->hwnd, winpos->hwndInsertAfter,
2794                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2795                 dump_winpos_flags(winpos->flags);
2796
2797                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2798                  * in the high word for internal purposes
2799                  */
2800                 wParam = winpos->flags & 0xffff;
2801                 /* We are not interested in the flags that don't match under XP and Win9x */
2802                 wParam &= ~(SWP_NOZORDER);
2803                 break;
2804             }
2805         }
2806
2807         msg.message = message;
2808         msg.flags = sent|wparam|lparam;
2809         msg.wParam = wParam;
2810         msg.lParam = lParam;
2811         add_message(&msg);
2812     }
2813
2814     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2815 }
2816
2817 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2818 {
2819     static long defwndproc_counter = 0;
2820     LRESULT ret;
2821     struct message msg;
2822
2823     /* do not log painting messages */
2824     if (message != WM_PAINT &&
2825         message != WM_NCPAINT &&
2826         message != WM_SYNCPAINT &&
2827         message != WM_ERASEBKGND &&
2828         message != WM_NCHITTEST &&
2829         message != WM_GETTEXT &&
2830         message != WM_GETICON &&
2831         message != WM_DEVICECHANGE)
2832     {
2833         trace("mdi child: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2834
2835         switch (message)
2836         {
2837             case WM_WINDOWPOSCHANGING:
2838             case WM_WINDOWPOSCHANGED:
2839             {
2840                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2841
2842                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2843                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2844                       winpos->hwnd, winpos->hwndInsertAfter,
2845                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2846                 dump_winpos_flags(winpos->flags);
2847
2848                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2849                  * in the high word for internal purposes
2850                  */
2851                 wParam = winpos->flags & 0xffff;
2852                 /* We are not interested in the flags that don't match under XP and Win9x */
2853                 wParam &= ~(SWP_NOZORDER);
2854                 break;
2855             }
2856
2857             case WM_MDIACTIVATE:
2858             {
2859                 HWND active, client = GetParent(hwnd);
2860
2861                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2862
2863                 if (hwnd == (HWND)lParam) /* if we are being activated */
2864                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2865                 else
2866                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2867                 break;
2868             }
2869         }
2870
2871         msg.message = message;
2872         msg.flags = sent|wparam|lparam;
2873         if (defwndproc_counter) msg.flags |= defwinproc;
2874         msg.wParam = wParam;
2875         msg.lParam = lParam;
2876         add_message(&msg);
2877     }
2878
2879     defwndproc_counter++;
2880     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2881     defwndproc_counter--;
2882
2883     return ret;
2884 }
2885
2886 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2887 {
2888     static long defwndproc_counter = 0;
2889     LRESULT ret;
2890     struct message msg;
2891
2892     /* do not log painting messages */
2893     if (message != WM_PAINT &&
2894         message != WM_NCPAINT &&
2895         message != WM_SYNCPAINT &&
2896         message != WM_ERASEBKGND &&
2897         message != WM_NCHITTEST &&
2898         message != WM_GETTEXT &&
2899         message != WM_GETICON &&
2900         message != WM_DEVICECHANGE)
2901     {
2902         trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2903
2904         switch (message)
2905         {
2906             case WM_WINDOWPOSCHANGING:
2907             case WM_WINDOWPOSCHANGED:
2908             {
2909                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2910
2911                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2912                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2913                       winpos->hwnd, winpos->hwndInsertAfter,
2914                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2915                 dump_winpos_flags(winpos->flags);
2916
2917                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2918                  * in the high word for internal purposes
2919                  */
2920                 wParam = winpos->flags & 0xffff;
2921                 /* We are not interested in the flags that don't match under XP and Win9x */
2922                 wParam &= ~(SWP_NOZORDER);
2923                 break;
2924             }
2925         }
2926
2927         msg.message = message;
2928         msg.flags = sent|wparam|lparam;
2929         if (defwndproc_counter) msg.flags |= defwinproc;
2930         msg.wParam = wParam;
2931         msg.lParam = lParam;
2932         add_message(&msg);
2933     }
2934
2935     defwndproc_counter++;
2936     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2937     defwndproc_counter--;
2938
2939     return ret;
2940 }
2941
2942 static BOOL mdi_RegisterWindowClasses(void)
2943 {
2944     WNDCLASSA cls;
2945
2946     cls.style = 0;
2947     cls.lpfnWndProc = mdi_frame_wnd_proc;
2948     cls.cbClsExtra = 0;
2949     cls.cbWndExtra = 0;
2950     cls.hInstance = GetModuleHandleA(0);
2951     cls.hIcon = 0;
2952     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2953     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2954     cls.lpszMenuName = NULL;
2955     cls.lpszClassName = "MDI_frame_class";
2956     if (!RegisterClassA(&cls)) return FALSE;
2957
2958     cls.lpfnWndProc = mdi_child_wnd_proc;
2959     cls.lpszClassName = "MDI_child_class";
2960     if (!RegisterClassA(&cls)) return FALSE;
2961
2962     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2963     old_mdi_client_proc = cls.lpfnWndProc;
2964     cls.hInstance = GetModuleHandleA(0);
2965     cls.lpfnWndProc = mdi_client_hook_proc;
2966     cls.lpszClassName = "MDI_client_class";
2967     if (!RegisterClassA(&cls)) assert(0);
2968
2969     return TRUE;
2970 }
2971
2972 static void test_mdi_messages(void)
2973 {
2974     MDICREATESTRUCTA mdi_cs;
2975     CLIENTCREATESTRUCT client_cs;
2976     HWND mdi_frame, mdi_child, mdi_child2, active_child;
2977     BOOL zoomed;
2978     HMENU hMenu = CreateMenu();
2979
2980     assert(mdi_RegisterWindowClasses());
2981
2982     flush_sequence();
2983
2984     trace("creating MDI frame window\n");
2985     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2986                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2987                                 WS_MAXIMIZEBOX | WS_VISIBLE,
2988                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2989                                 GetDesktopWindow(), hMenu,
2990                                 GetModuleHandleA(0), NULL);
2991     assert(mdi_frame);
2992     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
2993
2994     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2995     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2996
2997     trace("creating MDI client window\n");
2998     client_cs.hWindowMenu = 0;
2999     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3000     mdi_client = CreateWindowExA(0, "MDI_client_class",
3001                                  NULL,
3002                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3003                                  0, 0, 0, 0,
3004                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3005     assert(mdi_client);
3006     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3007
3008     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3009     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3010
3011     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3012     ok(!active_child, "wrong active MDI child %p\n", active_child);
3013     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3014
3015     SetFocus(0);
3016     flush_sequence();
3017
3018     trace("creating invisible MDI child window\n");
3019     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3020                                 WS_CHILD,
3021                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3022                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3023     assert(mdi_child);
3024
3025     flush_sequence();
3026     ShowWindow(mdi_child, SW_SHOWNORMAL);
3027     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3028
3029     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3030     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3031
3032     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3033     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3034
3035     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3036     ok(!active_child, "wrong active MDI child %p\n", active_child);
3037     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3038
3039     ShowWindow(mdi_child, SW_HIDE);
3040     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3041     flush_sequence();
3042
3043     ShowWindow(mdi_child, SW_SHOW);
3044     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3045
3046     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3047     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3048
3049     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3050     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3051
3052     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3053     ok(!active_child, "wrong active MDI child %p\n", active_child);
3054     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3055
3056     DestroyWindow(mdi_child);
3057     flush_sequence();
3058
3059     trace("creating visible MDI child window\n");
3060     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3061                                 WS_CHILD | WS_VISIBLE,
3062                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3063                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3064     assert(mdi_child);
3065     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3066
3067     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3068     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3069
3070     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3071     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3072
3073     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3074     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3075     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3076     flush_sequence();
3077
3078     DestroyWindow(mdi_child);
3079     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3080
3081     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3082     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3083
3084     /* Win2k: MDI client still returns a just destroyed child as active
3085      * Win9x: MDI client returns 0
3086      */
3087     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3088     ok(active_child == mdi_child || /* win2k */
3089        !active_child, /* win9x */
3090        "wrong active MDI child %p\n", active_child);
3091     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3092
3093     flush_sequence();
3094
3095     trace("creating invisible MDI child window\n");
3096     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3097                                 WS_CHILD,
3098                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3099                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3100     assert(mdi_child2);
3101     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3102
3103     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3104     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3105
3106     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3107     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3108
3109     /* Win2k: MDI client still returns a just destroyed child as active
3110      * Win9x: MDI client returns mdi_child2
3111      */
3112     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3113     ok(active_child == mdi_child || /* win2k */
3114        active_child == mdi_child2, /* win9x */
3115        "wrong active MDI child %p\n", active_child);
3116     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3117     flush_sequence();
3118
3119     ShowWindow(mdi_child2, SW_MAXIMIZE);
3120     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3121
3122     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3123     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3124
3125     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3126     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3127     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3128     flush_sequence();
3129
3130     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3131     ok(GetFocus() == mdi_child2 || /* win2k */
3132        GetFocus() == 0, /* win9x */
3133        "wrong focus window %p\n", GetFocus());
3134
3135     SetFocus(0);
3136     flush_sequence();
3137
3138     ShowWindow(mdi_child2, SW_HIDE);
3139     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3140
3141     ShowWindow(mdi_child2, SW_RESTORE);
3142     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3143     flush_sequence();
3144
3145     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3146     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3147
3148     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3149     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3150     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3151     flush_sequence();
3152
3153     SetFocus(0);
3154     flush_sequence();
3155
3156     ShowWindow(mdi_child2, SW_HIDE);
3157     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3158
3159     ShowWindow(mdi_child2, SW_SHOW);
3160     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3161
3162     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3163     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3164
3165     ShowWindow(mdi_child2, SW_MAXIMIZE);
3166     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3167
3168     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3169     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3170
3171     ShowWindow(mdi_child2, SW_RESTORE);
3172     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3173
3174     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3175     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3176
3177     ShowWindow(mdi_child2, SW_MINIMIZE);
3178     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3179
3180     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3181     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3182
3183     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3184     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3185     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3186     flush_sequence();
3187
3188     ShowWindow(mdi_child2, SW_RESTORE);
3189     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3190
3191     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3192     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3193
3194     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3195     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3196     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3197     flush_sequence();
3198
3199     SetFocus(0);
3200     flush_sequence();
3201
3202     ShowWindow(mdi_child2, SW_HIDE);
3203     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3204
3205     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3206     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3207
3208     DestroyWindow(mdi_child2);
3209     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3210
3211     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3212     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3213
3214     /* test for maximized MDI children */
3215     trace("creating maximized visible MDI child window 1\n");
3216     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3217                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3218                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3219                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3220     assert(mdi_child);
3221     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3222     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3223
3224     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3225     ok(GetFocus() == mdi_child || /* win2k */
3226        GetFocus() == 0, /* win9x */
3227        "wrong focus window %p\n", GetFocus());
3228
3229     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3230     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3231     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3232     flush_sequence();
3233
3234     trace("creating maximized visible MDI child window 2\n");
3235     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3236                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3237                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3238                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3239     assert(mdi_child2);
3240     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3241     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3242     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3243
3244     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3245     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3246
3247     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3248     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3249     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3250     flush_sequence();
3251
3252     trace("destroying maximized visible MDI child window 2\n");
3253     DestroyWindow(mdi_child2);
3254     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3255
3256     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3257
3258     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3259     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3260
3261     /* Win2k: MDI client still returns a just destroyed child as active
3262      * Win9x: MDI client returns 0
3263      */
3264     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3265     ok(active_child == mdi_child2 || /* win2k */
3266        !active_child, /* win9x */
3267        "wrong active MDI child %p\n", active_child);
3268     flush_sequence();
3269
3270     ShowWindow(mdi_child, SW_MAXIMIZE);
3271     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3272     flush_sequence();
3273
3274     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3275     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3276
3277     trace("re-creating maximized visible MDI child window 2\n");
3278     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3279                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3280                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3281                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3282     assert(mdi_child2);
3283     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3284     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3285     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3286
3287     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3288     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3289
3290     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3291     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3292     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3293     flush_sequence();
3294
3295     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3296     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3297     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3298
3299     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3300     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3301     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3302
3303     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3304     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3305     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3306     flush_sequence();
3307
3308     DestroyWindow(mdi_child);
3309     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3310
3311     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3312     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3313
3314     /* Win2k: MDI client still returns a just destroyed child as active
3315      * Win9x: MDI client returns 0
3316      */
3317     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3318     ok(active_child == mdi_child || /* win2k */
3319        !active_child, /* win9x */
3320        "wrong active MDI child %p\n", active_child);
3321     flush_sequence();
3322
3323     trace("creating maximized invisible MDI child window\n");
3324     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3325                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3326                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3327                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3328     assert(mdi_child2);
3329     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", TRUE);
3330     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3331     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3332     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3333
3334     /* Win2k: MDI client still returns a just destroyed child as active
3335      * Win9x: MDI client returns 0
3336      */
3337     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3338     ok(active_child == mdi_child || /* win2k */
3339        !active_child, /* win9x */
3340        "wrong active MDI child %p\n", active_child);
3341     flush_sequence();
3342
3343     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3344     ShowWindow(mdi_child2, SW_MAXIMIZE);
3345     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3346     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3347     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3348     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3349
3350     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3351     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3352     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3353     flush_sequence();
3354
3355     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3356     flush_sequence();
3357
3358     /* end of test for maximized MDI children */
3359     SetFocus(0);
3360     flush_sequence();
3361     trace("creating maximized visible MDI child window 1(Switch test)\n");
3362     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3363                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3364                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3365                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3366     assert(mdi_child);
3367     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3368     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3369
3370     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3371     ok(GetFocus() == mdi_child || /* win2k */
3372        GetFocus() == 0, /* win9x */
3373        "wrong focus window %p(Switch test)\n", GetFocus());
3374
3375     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3376     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3377     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3378     flush_sequence();
3379
3380     trace("creating maximized visible MDI child window 2(Switch test)\n");
3381     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3382                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3383                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3384                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3385     assert(mdi_child2);
3386     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3387
3388     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3389     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3390
3391     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3392     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3393
3394     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3395     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3396     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3397     flush_sequence();
3398
3399     trace("Switch child window.\n");
3400     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3401     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3402     trace("end of test for switch maximized MDI children\n");
3403     flush_sequence();
3404
3405     /* Prepare for switching test of not maximized MDI children  */
3406     ShowWindow( mdi_child, SW_NORMAL );
3407     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3408     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3409     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3410     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3411     flush_sequence();
3412
3413     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3414     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3415     trace("end of test for switch not maximized MDI children\n");
3416     flush_sequence();
3417
3418     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3419     flush_sequence();
3420
3421     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3422     flush_sequence();
3423
3424     SetFocus(0);
3425     flush_sequence();
3426     /* end of tests for switch maximized/not maximized MDI children */
3427
3428     mdi_cs.szClass = "MDI_child_Class";
3429     mdi_cs.szTitle = "MDI child";
3430     mdi_cs.hOwner = GetModuleHandleA(0);
3431     mdi_cs.x = 0;
3432     mdi_cs.y = 0;
3433     mdi_cs.cx = CW_USEDEFAULT;
3434     mdi_cs.cy = CW_USEDEFAULT;
3435     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3436     mdi_cs.lParam = 0;
3437     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3438     ok(mdi_child != 0, "MDI child creation failed\n");
3439     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3440
3441     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3442
3443     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3444     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3445
3446     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3447     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3448     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3449
3450     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3451     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3452     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3453     flush_sequence();
3454
3455     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3456     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3457
3458     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3459     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3460     ok(!active_child, "wrong active MDI child %p\n", active_child);
3461
3462     SetFocus(0);
3463     flush_sequence();
3464
3465     DestroyWindow(mdi_client);
3466     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3467
3468     /* test maximization of MDI child with invisible parent */
3469     client_cs.hWindowMenu = 0;
3470     mdi_client = CreateWindow("MDI_client_class",
3471                                  NULL,
3472                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3473                                  0, 0, 660, 430,
3474                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3475     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3476
3477     ShowWindow(mdi_client, SW_HIDE);
3478     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3479
3480     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3481                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3482                                 0, 0, 650, 440,
3483                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3484     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3485
3486     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3487     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3488     zoomed = IsZoomed(mdi_child);
3489     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3490     
3491     ShowWindow(mdi_client, SW_SHOW);
3492     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3493
3494     DestroyWindow(mdi_child);
3495     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3496
3497     /* end of test for maximization of MDI child with invisible parent */
3498
3499     DestroyWindow(mdi_client);
3500     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3501
3502     DestroyWindow(mdi_frame);
3503     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3504 }
3505 /************************* End of MDI test **********************************/
3506
3507 static void test_WM_SETREDRAW(HWND hwnd)
3508 {
3509     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3510
3511     flush_sequence();
3512
3513     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3514     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3515
3516     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3517     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3518
3519     flush_sequence();
3520     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3521     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3522
3523     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3524     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3525
3526     /* restore original WS_VISIBLE state */
3527     SetWindowLongA(hwnd, GWL_STYLE, style);
3528
3529     flush_sequence();
3530 }
3531
3532 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3533 {
3534     struct message msg;
3535
3536     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3537
3538     /* explicitly ignore WM_GETICON message */
3539     if (message == WM_GETICON) return 0;
3540
3541     switch (message)
3542     {
3543         /* ignore */
3544         case WM_MOUSEMOVE:
3545         case WM_SETCURSOR:
3546         case WM_DEVICECHANGE:
3547             return 0;
3548         case WM_NCHITTEST:
3549             return HTCLIENT;
3550
3551         case WM_WINDOWPOSCHANGING:
3552         case WM_WINDOWPOSCHANGED:
3553         {
3554             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3555
3556             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3557             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
3558                   winpos->hwnd, winpos->hwndInsertAfter,
3559                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3560             dump_winpos_flags(winpos->flags);
3561
3562             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3563              * in the high word for internal purposes
3564              */
3565             wParam = winpos->flags & 0xffff;
3566             /* We are not interested in the flags that don't match under XP and Win9x */
3567             wParam &= ~(SWP_NOZORDER);
3568             break;
3569         }
3570     }
3571
3572     msg.message = message;
3573     msg.flags = sent|wparam|lparam;
3574     msg.wParam = wParam;
3575     msg.lParam = lParam;
3576     add_message(&msg);
3577
3578     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3579     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3580     return 0;
3581 }
3582
3583 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3584 {
3585     DWORD style, exstyle;
3586     INT xmin, xmax;
3587     BOOL ret;
3588
3589     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3590     style = GetWindowLongA(hwnd, GWL_STYLE);
3591     /* do not be confused by WS_DLGFRAME set */
3592     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3593
3594     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3595     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3596
3597     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3598     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3599     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3600         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3601     else
3602         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3603
3604     style = GetWindowLongA(hwnd, GWL_STYLE);
3605     if (set) ok(style & set, "style %08x should be set\n", set);
3606     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3607
3608     /* a subsequent call should do nothing */
3609     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3610     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3611     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3612
3613     xmin = 0xdeadbeef;
3614     xmax = 0xdeadbeef;
3615     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3616     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3617     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3618     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3619     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3620     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3621 }
3622
3623 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3624 {
3625     DWORD style, exstyle;
3626     SCROLLINFO si;
3627     BOOL ret;
3628
3629     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3630     style = GetWindowLongA(hwnd, GWL_STYLE);
3631     /* do not be confused by WS_DLGFRAME set */
3632     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3633
3634     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3635     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3636
3637     si.cbSize = sizeof(si);
3638     si.fMask = SIF_RANGE;
3639     si.nMin = min;
3640     si.nMax = max;
3641     SetScrollInfo(hwnd, ctl, &si, TRUE);
3642     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3643         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3644     else
3645         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3646
3647     style = GetWindowLongA(hwnd, GWL_STYLE);
3648     if (set) ok(style & set, "style %08x should be set\n", set);
3649     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3650
3651     /* a subsequent call should do nothing */
3652     SetScrollInfo(hwnd, ctl, &si, TRUE);
3653     if (style & WS_HSCROLL)
3654         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3655     else if (style & WS_VSCROLL)
3656         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3657     else
3658         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3659
3660     si.fMask = SIF_PAGE;
3661     si.nPage = 5;
3662     SetScrollInfo(hwnd, ctl, &si, FALSE);
3663     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3664
3665     si.fMask = SIF_POS;
3666     si.nPos = max - 1;
3667     SetScrollInfo(hwnd, ctl, &si, FALSE);
3668     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3669
3670     si.fMask = SIF_RANGE;
3671     si.nMin = 0xdeadbeef;
3672     si.nMax = 0xdeadbeef;
3673     ret = GetScrollInfo(hwnd, ctl, &si);
3674     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3675     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3676     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3677     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3678 }
3679
3680 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3681 static void test_scroll_messages(HWND hwnd)
3682 {
3683     SCROLLINFO si;
3684     INT min, max;
3685     BOOL ret;
3686
3687     min = 0xdeadbeef;
3688     max = 0xdeadbeef;
3689     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3690     ok( ret, "GetScrollRange error %d\n", GetLastError());
3691     if (sequence->message != WmGetScrollRangeSeq[0].message)
3692         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3693     /* values of min and max are undefined */
3694     flush_sequence();
3695
3696     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3697     ok( ret, "SetScrollRange error %d\n", GetLastError());
3698     if (sequence->message != WmSetScrollRangeSeq[0].message)
3699         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3700     flush_sequence();
3701
3702     min = 0xdeadbeef;
3703     max = 0xdeadbeef;
3704     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3705     ok( ret, "GetScrollRange error %d\n", GetLastError());
3706     if (sequence->message != WmGetScrollRangeSeq[0].message)
3707         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3708     /* values of min and max are undefined */
3709     flush_sequence();
3710
3711     si.cbSize = sizeof(si);
3712     si.fMask = SIF_RANGE;
3713     si.nMin = 20;
3714     si.nMax = 160;
3715     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3716     if (sequence->message != WmSetScrollRangeSeq[0].message)
3717         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3718     flush_sequence();
3719
3720     si.fMask = SIF_PAGE;
3721     si.nPage = 10;
3722     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3723     if (sequence->message != WmSetScrollRangeSeq[0].message)
3724         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3725     flush_sequence();
3726
3727     si.fMask = SIF_POS;
3728     si.nPos = 20;
3729     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3730     if (sequence->message != WmSetScrollRangeSeq[0].message)
3731         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3732     flush_sequence();
3733
3734     si.fMask = SIF_RANGE;
3735     si.nMin = 0xdeadbeef;
3736     si.nMax = 0xdeadbeef;
3737     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3738     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3739     if (sequence->message != WmGetScrollInfoSeq[0].message)
3740         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3741     /* values of min and max are undefined */
3742     flush_sequence();
3743
3744     /* set WS_HSCROLL */
3745     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3746     /* clear WS_HSCROLL */
3747     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3748
3749     /* set WS_HSCROLL */
3750     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3751     /* clear WS_HSCROLL */
3752     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3753
3754     /* set WS_VSCROLL */
3755     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3756     /* clear WS_VSCROLL */
3757     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3758
3759     /* set WS_VSCROLL */
3760     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3761     /* clear WS_VSCROLL */
3762     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3763 }
3764
3765 static void test_showwindow(void)
3766 {
3767     HWND hwnd, hchild;
3768     RECT rc;
3769
3770     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3771                            100, 100, 200, 200, 0, 0, 0, NULL);
3772     ok (hwnd != 0, "Failed to create overlapped window\n");
3773     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3774                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3775     ok (hchild != 0, "Failed to create child\n");
3776     flush_sequence();
3777
3778     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3779     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3780     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3781     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3782     trace("done\n");
3783
3784     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3785     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3786     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3787     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3788     trace("done\n");
3789     /* back to invisible */
3790     ShowWindow(hchild, SW_HIDE);
3791     ShowWindow(hwnd, SW_HIDE);
3792     flush_sequence();
3793     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3794     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3795     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3796     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3797     trace("done\n");
3798     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3799     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3800     flush_sequence();
3801     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3802     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3803     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3804     trace("done\n");
3805     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3806     ShowWindow( hwnd, SW_SHOW);
3807     flush_sequence();
3808     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3809     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3810     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3811     trace("done\n");
3812
3813     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3814     ShowWindow( hchild, SW_HIDE);
3815     flush_sequence();
3816     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3817     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3818     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3819     trace("done\n");
3820
3821     SetCapture(hchild);
3822     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3823     DestroyWindow(hchild);
3824     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3825
3826     DestroyWindow(hwnd);
3827     flush_sequence();
3828
3829     /* Popup windows */
3830     /* Test 1:
3831      * 1. Create invisible maximized popup window.
3832      * 2. Move and resize it.
3833      * 3. Show it maximized.
3834      */
3835     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3836     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3837                            100, 100, 200, 200, 0, 0, 0, NULL);
3838     ok (hwnd != 0, "Failed to create popup window\n");
3839     ok(IsZoomed(hwnd), "window should be maximized\n");
3840     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3841     trace("done\n");
3842
3843     GetWindowRect(hwnd, &rc);
3844     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3845         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3846         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3847         rc.left, rc.top, rc.right, rc.bottom);
3848     /* Reset window's size & position */
3849     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3850     ok(IsZoomed(hwnd), "window should be maximized\n");
3851     flush_sequence();
3852
3853     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3854     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3855     ok(IsZoomed(hwnd), "window should be maximized\n");
3856     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3857     trace("done\n");
3858
3859     GetWindowRect(hwnd, &rc);
3860     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3861         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3862         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3863         rc.left, rc.top, rc.right, rc.bottom);
3864     DestroyWindow(hwnd);
3865     flush_sequence();
3866
3867     /* Test 2:
3868      * 1. Create invisible maximized popup window.
3869      * 2. Show it maximized.
3870      */
3871     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3872     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3873                            100, 100, 200, 200, 0, 0, 0, NULL);
3874     ok (hwnd != 0, "Failed to create popup window\n");
3875     ok(IsZoomed(hwnd), "window should be maximized\n");
3876     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3877     trace("done\n");
3878
3879     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3880     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3881     ok(IsZoomed(hwnd), "window should be maximized\n");
3882     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3883     trace("done\n");
3884     DestroyWindow(hwnd);
3885     flush_sequence();
3886
3887     /* Test 3:
3888      * 1. Create visible maximized popup window.
3889      */
3890     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3891     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3892                            100, 100, 200, 200, 0, 0, 0, NULL);
3893     ok (hwnd != 0, "Failed to create popup window\n");
3894     ok(IsZoomed(hwnd), "window should be maximized\n");
3895     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3896     trace("done\n");
3897     DestroyWindow(hwnd);
3898     flush_sequence();
3899
3900     /* Test 4:
3901      * 1. Create visible popup window.
3902      * 2. Maximize it.
3903      */
3904     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3905     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3906                            100, 100, 200, 200, 0, 0, 0, NULL);
3907     ok (hwnd != 0, "Failed to create popup window\n");
3908     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3909     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
3910     trace("done\n");
3911
3912     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3913     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3914     ok(IsZoomed(hwnd), "window should be maximized\n");
3915     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3916     trace("done\n");
3917     DestroyWindow(hwnd);
3918     flush_sequence();
3919 }
3920
3921 static void test_sys_menu(void)
3922 {
3923     HWND hwnd;
3924     HMENU hmenu;
3925     UINT state;
3926
3927     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3928                            100, 100, 200, 200, 0, 0, 0, NULL);
3929     ok (hwnd != 0, "Failed to create overlapped window\n");
3930
3931     flush_sequence();
3932
3933     /* test existing window without CS_NOCLOSE style */
3934     hmenu = GetSystemMenu(hwnd, FALSE);
3935     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3936
3937     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3938     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3939     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3940
3941     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3942     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3943
3944     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3945     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3946     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3947
3948     EnableMenuItem(hmenu, SC_CLOSE, 0);
3949     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3950
3951     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3952     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3953     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3954
3955     /* test whether removing WS_SYSMENU destroys a system menu */
3956     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
3957     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3958     flush_sequence();
3959     hmenu = GetSystemMenu(hwnd, FALSE);
3960     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3961
3962     DestroyWindow(hwnd);
3963
3964     /* test new window with CS_NOCLOSE style */
3965     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3966                            100, 100, 200, 200, 0, 0, 0, NULL);
3967     ok (hwnd != 0, "Failed to create overlapped window\n");
3968
3969     hmenu = GetSystemMenu(hwnd, FALSE);
3970     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3971
3972     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3973     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3974
3975     DestroyWindow(hwnd);
3976
3977     /* test new window without WS_SYSMENU style */
3978     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
3979                            100, 100, 200, 200, 0, 0, 0, NULL);
3980     ok(hwnd != 0, "Failed to create overlapped window\n");
3981
3982     hmenu = GetSystemMenu(hwnd, FALSE);
3983     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
3984
3985     DestroyWindow(hwnd);
3986 }
3987
3988 /* For shown WS_OVERLAPPEDWINDOW */
3989 static const struct message WmSetIcon_1[] = {
3990     { WM_SETICON, sent },
3991     { 0x00AE, sent|defwinproc|optional }, /* XP */
3992     { WM_GETTEXT, sent|defwinproc|optional },
3993     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
3994     { 0 }
3995 };
3996
3997 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
3998 static const struct message WmSetIcon_2[] = {
3999     { WM_SETICON, sent },
4000     { 0 }
4001 };
4002
4003 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4004 static const struct message WmInitEndSession[] = {
4005     { 0x003B, sent },
4006     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4007     { 0 }
4008 };
4009
4010 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4011 static const struct message WmInitEndSession_2[] = {
4012     { 0x003B, sent },
4013     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4014     { 0 }
4015 };
4016
4017 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4018 static const struct message WmInitEndSession_3[] = {
4019     { 0x003B, sent },
4020     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4021     { 0 }
4022 };
4023
4024 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4025 static const struct message WmInitEndSession_4[] = {
4026     { 0x003B, sent },
4027     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4028     { 0 }
4029 };
4030
4031 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4032 static const struct message WmInitEndSession_5[] = {
4033     { 0x003B, sent },
4034     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 1, ENDSESSION_LOGOFF },
4035     { 0 }
4036 };
4037
4038 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4039 {
4040     DWORD ret;
4041     MSG msg;
4042
4043     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4044     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4045
4046     PostMessageA(hwnd, WM_USER, 0, 0);
4047
4048     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4049     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4050
4051     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4052     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4053
4054     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4055     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4056
4057     PostMessageA(hwnd, WM_USER, 0, 0);
4058
4059     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4060     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4061
4062     ok(PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4063     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4064
4065     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4066     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4067     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4068
4069     PostMessageA(hwnd, WM_USER, 0, 0);
4070
4071     /* new incoming message causes it to become signaled again */
4072     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4073     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4074
4075     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4076     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4077     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4078     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4079 }
4080
4081 /* test if we receive the right sequence of messages */
4082 static void test_messages(void)
4083 {
4084     HWND hwnd, hparent, hchild;
4085     HWND hchild2, hbutton;
4086     HMENU hmenu;
4087     MSG msg;
4088     LRESULT res;
4089
4090     flush_sequence();
4091
4092     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4093                            100, 100, 200, 200, 0, 0, 0, NULL);
4094     ok (hwnd != 0, "Failed to create overlapped window\n");
4095     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4096
4097     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4098     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4099     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4100
4101     /* test WM_SETREDRAW on a not visible top level window */
4102     test_WM_SETREDRAW(hwnd);
4103
4104     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4105     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4106     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4107
4108     ok(GetActiveWindow() == hwnd, "window should be active\n");
4109     ok(GetFocus() == hwnd, "window should have input focus\n");
4110     ShowWindow(hwnd, SW_HIDE);
4111     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
4112
4113     ShowWindow(hwnd, SW_SHOW);
4114     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4115
4116     ShowWindow(hwnd, SW_HIDE);
4117     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4118
4119     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4120     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4121
4122     ShowWindow(hwnd, SW_RESTORE);
4123     /* FIXME: add ok_sequence() here */
4124     flush_sequence();
4125
4126     ShowWindow(hwnd, SW_MINIMIZE);
4127     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4128     flush_sequence();
4129
4130     ShowWindow(hwnd, SW_RESTORE);
4131     /* FIXME: add ok_sequence() here */
4132     flush_sequence();
4133
4134     ShowWindow(hwnd, SW_SHOW);
4135     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4136
4137     ok(GetActiveWindow() == hwnd, "window should be active\n");
4138     ok(GetFocus() == hwnd, "window should have input focus\n");
4139     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4140     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4141     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4142     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4143
4144     /* test WM_SETREDRAW on a visible top level window */
4145     ShowWindow(hwnd, SW_SHOW);
4146     test_WM_SETREDRAW(hwnd);
4147
4148     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4149     test_scroll_messages(hwnd);
4150
4151     /* test resizing and moving */
4152     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4153     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4154     flush_events();
4155     flush_sequence();
4156     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4157     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4158     flush_events();
4159     flush_sequence();
4160     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER );
4161     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4162     flush_events();
4163     flush_sequence();
4164
4165     /* popups don't get WM_GETMINMAXINFO */
4166     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4167     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4168     flush_sequence();
4169     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4170     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4171
4172     DestroyWindow(hwnd);
4173     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4174
4175     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4176                               100, 100, 200, 200, 0, 0, 0, NULL);
4177     ok (hparent != 0, "Failed to create parent window\n");
4178     flush_sequence();
4179
4180     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4181                              0, 0, 10, 10, hparent, 0, 0, NULL);
4182     ok (hchild != 0, "Failed to create child window\n");
4183     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4184     DestroyWindow(hchild);
4185     flush_sequence();
4186
4187     /* visible child window with a caption */
4188     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4189                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4190                              0, 0, 10, 10, hparent, 0, 0, NULL);
4191     ok (hchild != 0, "Failed to create child window\n");
4192     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4193
4194     trace("testing scroll APIs on a visible child window %p\n", hchild);
4195     test_scroll_messages(hchild);
4196
4197     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4198     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4199
4200     DestroyWindow(hchild);
4201     flush_sequence();
4202
4203     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4204                              0, 0, 10, 10, hparent, 0, 0, NULL);
4205     ok (hchild != 0, "Failed to create child window\n");
4206     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4207     
4208     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4209                                100, 100, 50, 50, hparent, 0, 0, NULL);
4210     ok (hchild2 != 0, "Failed to create child2 window\n");
4211     flush_sequence();
4212
4213     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4214                               0, 100, 50, 50, hchild, 0, 0, NULL);
4215     ok (hbutton != 0, "Failed to create button window\n");
4216
4217     /* test WM_SETREDRAW on a not visible child window */
4218     test_WM_SETREDRAW(hchild);
4219
4220     ShowWindow(hchild, SW_SHOW);
4221     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4222
4223     /* check parent messages too */
4224     log_all_parent_messages++;
4225     ShowWindow(hchild, SW_HIDE);
4226     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4227     log_all_parent_messages--;
4228
4229     ShowWindow(hchild, SW_SHOW);
4230     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4231
4232     ShowWindow(hchild, SW_HIDE);
4233     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4234
4235     ShowWindow(hchild, SW_SHOW);
4236     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4237
4238     /* test WM_SETREDRAW on a visible child window */
4239     test_WM_SETREDRAW(hchild);
4240
4241     log_all_parent_messages++;
4242     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4243     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4244     log_all_parent_messages--;
4245
4246     ShowWindow(hchild, SW_HIDE);
4247     flush_sequence();
4248     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4249     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4250
4251     ShowWindow(hchild, SW_HIDE);
4252     flush_sequence();
4253     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4254     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4255
4256     /* DestroyWindow sequence below expects that a child has focus */
4257     SetFocus(hchild);
4258     flush_sequence();
4259
4260     DestroyWindow(hchild);
4261     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4262     DestroyWindow(hchild2);
4263     DestroyWindow(hbutton);
4264
4265     flush_sequence();
4266     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4267                              0, 0, 100, 100, hparent, 0, 0, NULL);
4268     ok (hchild != 0, "Failed to create child popup window\n");
4269     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4270     DestroyWindow(hchild);
4271
4272     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4273     flush_sequence();
4274     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4275                              0, 0, 100, 100, hparent, 0, 0, NULL);
4276     ok (hchild != 0, "Failed to create popup window\n");
4277     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4278     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4279     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4280     flush_sequence();
4281     ShowWindow(hchild, SW_SHOW);
4282     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4283     flush_sequence();
4284     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4285     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4286     flush_sequence();
4287     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4288     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", TRUE);
4289     DestroyWindow(hchild);
4290
4291     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4292      * changes nothing in message sequences.
4293      */
4294     flush_sequence();
4295     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4296                              0, 0, 100, 100, hparent, 0, 0, NULL);
4297     ok (hchild != 0, "Failed to create popup window\n");
4298     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4299     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4300     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4301     flush_sequence();
4302     ShowWindow(hchild, SW_SHOW);
4303     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4304     flush_sequence();
4305     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4306     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4307     DestroyWindow(hchild);
4308
4309     flush_sequence();
4310     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4311                            0, 0, 100, 100, hparent, 0, 0, NULL);
4312     ok(hwnd != 0, "Failed to create custom dialog window\n");
4313     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4314
4315     /*
4316     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4317     test_scroll_messages(hwnd);
4318     */
4319
4320     flush_sequence();
4321
4322     test_def_id = 1;
4323     SendMessage(hwnd, WM_NULL, 0, 0);
4324
4325     flush_sequence();
4326     after_end_dialog = 1;
4327     EndDialog( hwnd, 0 );
4328     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4329
4330     DestroyWindow(hwnd);
4331     after_end_dialog = 0;
4332     test_def_id = 0;
4333
4334     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4335                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4336     ok(hwnd != 0, "Failed to create custom dialog window\n");
4337     flush_sequence();
4338     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4339     ShowWindow(hwnd, SW_SHOW);
4340     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4341     DestroyWindow(hwnd);
4342
4343     flush_sequence();
4344     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4345     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4346
4347     DestroyWindow(hparent);
4348     flush_sequence();
4349
4350     /* Message sequence for SetMenu */
4351     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4352     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4353
4354     hmenu = CreateMenu();
4355     ok (hmenu != 0, "Failed to create menu\n");
4356     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4357     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4358                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4359     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4360     ok (SetMenu(hwnd, 0), "SetMenu\n");
4361     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4362     ok (SetMenu(hwnd, 0), "SetMenu\n");
4363     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4364     ShowWindow(hwnd, SW_SHOW);
4365     UpdateWindow( hwnd );
4366     flush_events();
4367     flush_sequence();
4368     ok (SetMenu(hwnd, 0), "SetMenu\n");
4369     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4370     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4371     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4372
4373     UpdateWindow( hwnd );
4374     flush_events();
4375     flush_sequence();
4376     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4377     flush_events();
4378     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4379
4380     DestroyWindow(hwnd);
4381     flush_sequence();
4382
4383     /* Message sequence for EnableWindow */
4384     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4385                               100, 100, 200, 200, 0, 0, 0, NULL);
4386     ok (hparent != 0, "Failed to create parent window\n");
4387     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4388                              0, 0, 10, 10, hparent, 0, 0, NULL);
4389     ok (hchild != 0, "Failed to create child window\n");
4390
4391     SetFocus(hchild);
4392     flush_events();
4393     flush_sequence();
4394
4395     EnableWindow(hparent, FALSE);
4396     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4397
4398     EnableWindow(hparent, TRUE);
4399     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4400
4401     flush_events();
4402     flush_sequence();
4403
4404     test_MsgWaitForMultipleObjects(hparent);
4405
4406     /* the following test causes an exception in user.exe under win9x */
4407     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4408     {
4409         DestroyWindow(hparent);
4410         flush_sequence();
4411         return;
4412     }
4413     PostMessageW( hparent, WM_USER+1, 0, 0 );
4414     /* PeekMessage(NULL) fails, but still removes the message */
4415     SetLastError(0xdeadbeef);
4416     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4417     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4418         GetLastError() == 0xdeadbeef, /* NT4 */
4419         "last error is %d\n", GetLastError() );
4420     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4421     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4422
4423     DestroyWindow(hchild);
4424     DestroyWindow(hparent);
4425     flush_sequence();
4426
4427     /* Message sequences for WM_SETICON */
4428     trace("testing WM_SETICON\n");
4429     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4430                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4431                            NULL, NULL, 0);
4432     ShowWindow(hwnd, SW_SHOW);
4433     UpdateWindow(hwnd);
4434     flush_events();
4435     flush_sequence();
4436     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4437     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4438
4439     ShowWindow(hwnd, SW_HIDE);
4440     flush_events();
4441     flush_sequence();
4442     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4443     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4444     DestroyWindow(hwnd);
4445     flush_sequence();
4446
4447     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4448                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4449                            NULL, NULL, 0);
4450     ShowWindow(hwnd, SW_SHOW);
4451     UpdateWindow(hwnd);
4452     flush_events();
4453     flush_sequence();
4454     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4455     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4456
4457     ShowWindow(hwnd, SW_HIDE);
4458     flush_events();
4459     flush_sequence();
4460     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4461     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4462
4463     flush_sequence();
4464     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4465     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4466     todo_wine
4467     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4468     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4469     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4470     todo_wine
4471     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4472     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4473     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4474     todo_wine
4475     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4476
4477     flush_sequence();
4478     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4479     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4480     todo_wine
4481     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4482     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4483     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4484     todo_wine
4485     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4486
4487     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4488     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4489     todo_wine
4490     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4491
4492     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4493     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4494     todo_wine
4495     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4496
4497     DestroyWindow(hwnd);
4498     flush_sequence();
4499 }
4500
4501 static void invisible_parent_tests(void)
4502 {
4503     HWND hparent, hchild;
4504
4505     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4506                               100, 100, 200, 200, 0, 0, 0, NULL);
4507     ok (hparent != 0, "Failed to create parent window\n");
4508     flush_sequence();
4509
4510     /* test showing child with hidden parent */
4511
4512     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4513                              0, 0, 10, 10, hparent, 0, 0, NULL);
4514     ok (hchild != 0, "Failed to create child window\n");
4515     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4516
4517     ShowWindow( hchild, SW_MINIMIZE );
4518     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4519     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4520     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4521
4522     /* repeat */
4523     flush_events();
4524     flush_sequence();
4525     ShowWindow( hchild, SW_MINIMIZE );
4526     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4527
4528     DestroyWindow(hchild);
4529     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4530                              0, 0, 10, 10, hparent, 0, 0, NULL);
4531     flush_sequence();
4532
4533     ShowWindow( hchild, SW_MAXIMIZE );
4534     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4535     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4536     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4537
4538     /* repeat */
4539     flush_events();
4540     flush_sequence();
4541     ShowWindow( hchild, SW_MAXIMIZE );
4542     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4543
4544     DestroyWindow(hchild);
4545     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4546                              0, 0, 10, 10, hparent, 0, 0, NULL);
4547     flush_sequence();
4548
4549     ShowWindow( hchild, SW_RESTORE );
4550     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4551     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4552     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4553
4554     DestroyWindow(hchild);
4555     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4556                              0, 0, 10, 10, hparent, 0, 0, NULL);
4557     flush_sequence();
4558
4559     ShowWindow( hchild, SW_SHOWMINIMIZED );
4560     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4561     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4562     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4563
4564     /* repeat */
4565     flush_events();
4566     flush_sequence();
4567     ShowWindow( hchild, SW_SHOWMINIMIZED );
4568     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4569
4570     DestroyWindow(hchild);
4571     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4572                              0, 0, 10, 10, hparent, 0, 0, NULL);
4573     flush_sequence();
4574
4575     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4576     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4577     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4578     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4579     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4580
4581     DestroyWindow(hchild);
4582     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4583                              0, 0, 10, 10, hparent, 0, 0, NULL);
4584     flush_sequence();
4585
4586     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4587     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4588     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4589     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4590
4591     /* repeat */
4592     flush_events();
4593     flush_sequence();
4594     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4595     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4596
4597     DestroyWindow(hchild);
4598     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4599                              0, 0, 10, 10, hparent, 0, 0, NULL);
4600     flush_sequence();
4601
4602     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4603     ShowWindow( hchild, SW_FORCEMINIMIZE );
4604     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4605 todo_wine {
4606     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4607 }
4608     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4609
4610     DestroyWindow(hchild);
4611     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4612                              0, 0, 10, 10, hparent, 0, 0, NULL);
4613     flush_sequence();
4614
4615     ShowWindow( hchild, SW_SHOWNA );
4616     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4617     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4618     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4619
4620     /* repeat */
4621     flush_events();
4622     flush_sequence();
4623     ShowWindow( hchild, SW_SHOWNA );
4624     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4625
4626     DestroyWindow(hchild);
4627     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4628                              0, 0, 10, 10, hparent, 0, 0, NULL);
4629     flush_sequence();
4630
4631     ShowWindow( hchild, SW_SHOW );
4632     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4633     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4634     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4635
4636     /* repeat */
4637     flush_events();
4638     flush_sequence();
4639     ShowWindow( hchild, SW_SHOW );
4640     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4641
4642     ShowWindow( hchild, SW_HIDE );
4643     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4644     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4645     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4646
4647     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4648     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4649     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4650     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4651
4652     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4653     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4654     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4655     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4656
4657     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4658     flush_sequence();
4659     DestroyWindow(hchild);
4660     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4661
4662     DestroyWindow(hparent);
4663     flush_sequence();
4664 }
4665
4666 /****************** button message test *************************/
4667 static const struct message WmSetFocusButtonSeq[] =
4668 {
4669     { HCBT_SETFOCUS, hook },
4670     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4671     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4672     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4673     { WM_SETFOCUS, sent|wparam, 0 },
4674     { WM_CTLCOLORBTN, sent|defwinproc },
4675     { 0 }
4676 };
4677 static const struct message WmKillFocusButtonSeq[] =
4678 {
4679     { HCBT_SETFOCUS, hook },
4680     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4681     { WM_KILLFOCUS, sent|wparam, 0 },
4682     { WM_CTLCOLORBTN, sent|defwinproc },
4683     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4684     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4685     { 0 }
4686 };
4687 static const struct message WmSetFocusStaticSeq[] =
4688 {
4689     { HCBT_SETFOCUS, hook },
4690     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4691     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4692     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4693     { WM_SETFOCUS, sent|wparam, 0 },
4694     { WM_CTLCOLORSTATIC, sent|defwinproc },
4695     { 0 }
4696 };
4697 static const struct message WmKillFocusStaticSeq[] =
4698 {
4699     { HCBT_SETFOCUS, hook },
4700     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4701     { WM_KILLFOCUS, sent|wparam, 0 },
4702     { WM_CTLCOLORSTATIC, sent|defwinproc },
4703     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4704     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4705     { 0 }
4706 };
4707 static const struct message WmLButtonDownSeq[] =
4708 {
4709     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4710     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4711     { HCBT_SETFOCUS, hook },
4712     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4713     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4714     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4715     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4716     { WM_CTLCOLORBTN, sent|defwinproc },
4717     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4718     { WM_CTLCOLORBTN, sent|defwinproc },
4719     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4720     { 0 }
4721 };
4722 static const struct message WmLButtonUpSeq[] =
4723 {
4724     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4725     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4726     { WM_CTLCOLORBTN, sent|defwinproc },
4727     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4728     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4729     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4730     { 0 }
4731 };
4732 static const struct message WmSetFontButtonSeq[] =
4733 {
4734     { WM_SETFONT, sent },
4735     { WM_PAINT, sent },
4736     { WM_ERASEBKGND, sent|defwinproc|optional },
4737     { WM_CTLCOLORBTN, sent|defwinproc },
4738     { 0 }
4739 };
4740
4741 static WNDPROC old_button_proc;
4742
4743 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4744 {
4745     static long defwndproc_counter = 0;
4746     LRESULT ret;
4747     struct message msg;
4748
4749     trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4750
4751     /* explicitly ignore WM_GETICON message */
4752     if (message == WM_GETICON) return 0;
4753
4754     msg.message = message;
4755     msg.flags = sent|wparam|lparam;
4756     if (defwndproc_counter) msg.flags |= defwinproc;
4757     msg.wParam = wParam;
4758     msg.lParam = lParam;
4759     add_message(&msg);
4760
4761     if (message == BM_SETSTATE)
4762         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4763
4764     defwndproc_counter++;
4765     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4766     defwndproc_counter--;
4767
4768     return ret;
4769 }
4770
4771 static void subclass_button(void)
4772 {
4773     WNDCLASSA cls;
4774
4775     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4776
4777     old_button_proc = cls.lpfnWndProc;
4778
4779     cls.hInstance = GetModuleHandle(0);
4780     cls.lpfnWndProc = button_hook_proc;
4781     cls.lpszClassName = "my_button_class";
4782     UnregisterClass(cls.lpszClassName, cls.hInstance);
4783     if (!RegisterClassA(&cls)) assert(0);
4784 }
4785
4786 static void test_button_messages(void)
4787 {
4788     static const struct
4789     {
4790         DWORD style;
4791         DWORD dlg_code;
4792         const struct message *setfocus;
4793         const struct message *killfocus;
4794     } button[] = {
4795         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4796           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4797         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4798           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4799         { BS_CHECKBOX, DLGC_BUTTON,
4800           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4801         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4802           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4803         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4804           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4805         { BS_3STATE, DLGC_BUTTON,
4806           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4807         { BS_AUTO3STATE, DLGC_BUTTON,
4808           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4809         { BS_GROUPBOX, DLGC_STATIC,
4810           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4811         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4812           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4813         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4814           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4815         { BS_OWNERDRAW, DLGC_BUTTON,
4816           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4817     };
4818     unsigned int i;
4819     HWND hwnd;
4820     DWORD dlg_code;
4821     HFONT zfont;
4822
4823     subclass_button();
4824
4825     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4826     {
4827         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4828                                0, 0, 50, 14, 0, 0, 0, NULL);
4829         ok(hwnd != 0, "Failed to create button window\n");
4830
4831         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4832         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4833
4834         ShowWindow(hwnd, SW_SHOW);
4835         UpdateWindow(hwnd);
4836         SetFocus(0);
4837         flush_sequence();
4838
4839         trace("button style %08x\n", button[i].style);
4840         SetFocus(hwnd);
4841         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4842
4843         SetFocus(0);
4844         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4845
4846         DestroyWindow(hwnd);
4847     }
4848
4849     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4850                            0, 0, 50, 14, 0, 0, 0, NULL);
4851     ok(hwnd != 0, "Failed to create button window\n");
4852
4853     SetFocus(0);
4854     flush_events();
4855     flush_sequence();
4856
4857     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4858     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4859
4860     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4861     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4862
4863     flush_sequence();
4864     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4865     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4866     UpdateWindow(hwnd);
4867     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4868
4869     DestroyWindow(hwnd);
4870 }
4871
4872 /****************** static message test *************************/
4873 static const struct message WmSetFontStaticSeq[] =
4874 {
4875     { WM_SETFONT, sent },
4876     { WM_PAINT, sent|defwinproc },
4877     { WM_ERASEBKGND, sent|defwinproc|optional },
4878     { WM_CTLCOLORSTATIC, sent|defwinproc },
4879     { 0 }
4880 };
4881
4882 static WNDPROC old_static_proc;
4883
4884 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4885 {
4886     static long defwndproc_counter = 0;
4887     LRESULT ret;
4888     struct message msg;
4889
4890     trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4891
4892     /* explicitly ignore WM_GETICON message */
4893     if (message == WM_GETICON) return 0;
4894
4895     msg.message = message;
4896     msg.flags = sent|wparam|lparam;
4897     if (defwndproc_counter) msg.flags |= defwinproc;
4898     msg.wParam = wParam;
4899     msg.lParam = lParam;
4900     add_message(&msg);
4901
4902     defwndproc_counter++;
4903     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
4904     defwndproc_counter--;
4905
4906     return ret;
4907 }
4908
4909 static void subclass_static(void)
4910 {
4911     WNDCLASSA cls;
4912
4913     if (!GetClassInfoA(0, "static", &cls)) assert(0);
4914
4915     old_static_proc = cls.lpfnWndProc;
4916
4917     cls.hInstance = GetModuleHandle(0);
4918     cls.lpfnWndProc = static_hook_proc;
4919     cls.lpszClassName = "my_static_class";
4920     UnregisterClass(cls.lpszClassName, cls.hInstance);
4921     if (!RegisterClassA(&cls)) assert(0);
4922 }
4923
4924 static void test_static_messages(void)
4925 {
4926     /* FIXME: make as comprehensive as the button message test */
4927     static const struct
4928     {
4929         DWORD style;
4930         DWORD dlg_code;
4931         const struct message *setfont;
4932     } static_ctrl[] = {
4933         { SS_LEFT, DLGC_STATIC,
4934           WmSetFontStaticSeq }
4935     };
4936     unsigned int i;
4937     HWND hwnd;
4938     DWORD dlg_code;
4939
4940     subclass_static();
4941
4942     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
4943     {
4944         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
4945                                0, 0, 50, 14, 0, 0, 0, NULL);
4946         ok(hwnd != 0, "Failed to create static window\n");
4947
4948         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4949         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4950
4951         ShowWindow(hwnd, SW_SHOW);
4952         UpdateWindow(hwnd);
4953         SetFocus(0);
4954         flush_sequence();
4955
4956         trace("static style %08x\n", static_ctrl[i].style);
4957         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
4958         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
4959
4960         DestroyWindow(hwnd);
4961     }
4962 }
4963
4964 /****************** ComboBox message test *************************/
4965 #define ID_COMBOBOX 0x000f
4966
4967 static const struct message WmKeyDownComboSeq[] =
4968 {
4969     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
4970     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
4971     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
4972     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
4973     { WM_CTLCOLOREDIT, sent|parent },
4974     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
4975     { 0 }
4976 };
4977
4978 static WNDPROC old_combobox_proc;
4979
4980 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4981 {
4982     static long defwndproc_counter = 0;
4983     LRESULT ret;
4984     struct message msg;
4985
4986     /* do not log painting messages */
4987     if (message != WM_PAINT &&
4988         message != WM_NCPAINT &&
4989         message != WM_SYNCPAINT &&
4990         message != WM_ERASEBKGND &&
4991         message != WM_NCHITTEST &&
4992         message != WM_GETTEXT &&
4993         message != WM_GETICON &&
4994         message != WM_DEVICECHANGE)
4995     {
4996         trace("combo: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4997
4998         msg.message = message;
4999         msg.flags = sent|wparam|lparam;
5000         if (defwndproc_counter) msg.flags |= defwinproc;
5001         msg.wParam = wParam;
5002         msg.lParam = lParam;
5003         add_message(&msg);
5004     }
5005
5006     defwndproc_counter++;
5007     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5008     defwndproc_counter--;
5009
5010     return ret;
5011 }
5012
5013 static void subclass_combobox(void)
5014 {
5015     WNDCLASSA cls;
5016
5017     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5018
5019     old_combobox_proc = cls.lpfnWndProc;
5020
5021     cls.hInstance = GetModuleHandle(0);
5022     cls.lpfnWndProc = combobox_hook_proc;
5023     cls.lpszClassName = "my_combobox_class";
5024     UnregisterClass(cls.lpszClassName, cls.hInstance);
5025     if (!RegisterClassA(&cls)) assert(0);
5026 }
5027
5028 static void test_combobox_messages(void)
5029 {
5030     HWND parent, combo;
5031     LRESULT ret;
5032
5033     subclass_combobox();
5034
5035     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5036                              100, 100, 200, 200, 0, 0, 0, NULL);
5037     ok(parent != 0, "Failed to create parent window\n");
5038     flush_sequence();
5039
5040     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5041                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5042     ok(combo != 0, "Failed to create combobox window\n");
5043
5044     UpdateWindow(combo);
5045
5046     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5047     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5048
5049     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5050     ok(ret == 0, "expected 0, got %ld\n", ret);
5051     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5052     ok(ret == 1, "expected 1, got %ld\n", ret);
5053     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5054     ok(ret == 2, "expected 2, got %ld\n", ret);
5055
5056     SendMessage(combo, CB_SETCURSEL, 0, 0);
5057     SetFocus(combo);
5058     flush_sequence();
5059
5060     log_all_parent_messages++;
5061     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5062     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5063     log_all_parent_messages--;
5064     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5065
5066     DestroyWindow(combo);
5067     DestroyWindow(parent);
5068 }
5069
5070 /****************** WM_IME_KEYDOWN message test *******************/
5071
5072 static const struct message WmImeKeydownMsgSeq_0[] =
5073 {
5074     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5075     { WM_CHAR, wparam, 'A' },
5076     { 0 }
5077 };
5078
5079 static const struct message WmImeKeydownMsgSeq_1[] =
5080 {
5081     { WM_KEYDOWN, wparam, VK_RETURN },
5082     { WM_CHAR,    wparam, VK_RETURN },
5083     { 0 }
5084 };
5085
5086 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5087 {
5088     struct message msg;
5089
5090     trace("wmime_keydown_procA: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5091
5092     msg.message = message;
5093     msg.flags = wparam|lparam;
5094     msg.wParam = wParam;
5095     msg.lParam = lParam;
5096     add_message(&msg);
5097
5098     return DefWindowProcA(hwnd, message, wParam, lParam);
5099 }
5100
5101 static void register_wmime_keydown_class(void)
5102 {
5103     WNDCLASSA cls;
5104
5105     ZeroMemory(&cls, sizeof(WNDCLASSA));
5106     cls.lpfnWndProc = wmime_keydown_procA;
5107     cls.hInstance = GetModuleHandleA(0);
5108     cls.lpszClassName = "wmime_keydown_class";
5109     if (!RegisterClassA(&cls)) assert(0);
5110 }
5111
5112 void test_wmime_keydown_message(void)
5113 {
5114     HWND hwnd;
5115     MSG msg;
5116
5117     trace("Message sequences by WM_IME_KEYDOWN\n");
5118
5119     register_wmime_keydown_class();
5120     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5121                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5122                            NULL, NULL, 0);
5123     flush_events();
5124     flush_sequence();
5125
5126     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5127     SendMessage(hwnd, WM_CHAR, 'A', 1);
5128     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5129
5130     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5131     {
5132         TranslateMessage(&msg);
5133         DispatchMessage(&msg);
5134     }
5135     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5136
5137     DestroyWindow(hwnd);
5138 }
5139
5140 /************* painting message test ********************/
5141
5142 void dump_region(HRGN hrgn)
5143 {
5144     DWORD i, size;
5145     RGNDATA *data = NULL;
5146     RECT *rect;
5147
5148     if (!hrgn)
5149     {
5150         printf( "null region\n" );
5151         return;
5152     }
5153     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5154     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5155     GetRegionData( hrgn, size, data );
5156     printf("%d rects:", data->rdh.nCount );
5157     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5158         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5159     printf("\n");
5160     HeapFree( GetProcessHeap(), 0, data );
5161 }
5162
5163 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5164 {
5165     INT ret;
5166     RECT r1, r2;
5167     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5168     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5169
5170     ret = GetUpdateRgn( hwnd, update, FALSE );
5171     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5172     if (ret == NULLREGION)
5173     {
5174         ok( !hrgn, "Update region shouldn't be empty\n" );
5175     }
5176     else
5177     {
5178         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5179         {
5180             ok( 0, "Regions are different\n" );
5181             if (winetest_debug > 0)
5182             {
5183                 printf( "Update region: " );
5184                 dump_region( update );
5185                 printf( "Wanted region: " );
5186                 dump_region( hrgn );
5187             }
5188         }
5189     }
5190     GetRgnBox( update, &r1 );
5191     GetUpdateRect( hwnd, &r2, FALSE );
5192     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5193         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5194         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5195
5196     DeleteObject( tmp );
5197     DeleteObject( update );
5198 }
5199
5200 static const struct message WmInvalidateRgn[] = {
5201     { WM_NCPAINT, sent },
5202     { WM_GETTEXT, sent|defwinproc|optional },
5203     { 0 }
5204 };
5205
5206 static const struct message WmGetUpdateRect[] = {
5207     { WM_NCPAINT, sent },
5208     { WM_GETTEXT, sent|defwinproc|optional },
5209     { WM_PAINT, sent },
5210     { 0 }
5211 };
5212
5213 static const struct message WmInvalidateFull[] = {
5214     { WM_NCPAINT, sent|wparam, 1 },
5215     { WM_GETTEXT, sent|defwinproc|optional },
5216     { 0 }
5217 };
5218
5219 static const struct message WmInvalidateErase[] = {
5220     { WM_NCPAINT, sent|wparam, 1 },
5221     { WM_GETTEXT, sent|defwinproc|optional },
5222     { WM_ERASEBKGND, sent },
5223     { 0 }
5224 };
5225
5226 static const struct message WmInvalidatePaint[] = {
5227     { WM_PAINT, sent },
5228     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5229     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5230     { 0 }
5231 };
5232
5233 static const struct message WmInvalidateErasePaint[] = {
5234     { WM_PAINT, sent },
5235     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5236     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5237     { WM_ERASEBKGND, sent|beginpaint },
5238     { 0 }
5239 };
5240
5241 static const struct message WmInvalidateErasePaint2[] = {
5242     { WM_PAINT, sent },
5243     { WM_NCPAINT, sent|beginpaint },
5244     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5245     { WM_ERASEBKGND, sent|beginpaint },
5246     { 0 }
5247 };
5248
5249 static const struct message WmErase[] = {
5250     { WM_ERASEBKGND, sent },
5251     { 0 }
5252 };
5253
5254 static const struct message WmPaint[] = {
5255     { WM_PAINT, sent },
5256     { 0 }
5257 };
5258
5259 static const struct message WmParentOnlyPaint[] = {
5260     { WM_PAINT, sent|parent },
5261     { 0 }
5262 };
5263
5264 static const struct message WmInvalidateParent[] = {
5265     { WM_NCPAINT, sent|parent },
5266     { WM_GETTEXT, sent|defwinproc|parent|optional },
5267     { WM_ERASEBKGND, sent|parent },
5268     { 0 }
5269 };
5270
5271 static const struct message WmInvalidateParentChild[] = {
5272     { WM_NCPAINT, sent|parent },
5273     { WM_GETTEXT, sent|defwinproc|parent|optional },
5274     { WM_ERASEBKGND, sent|parent },
5275     { WM_NCPAINT, sent },
5276     { WM_GETTEXT, sent|defwinproc|optional },
5277     { WM_ERASEBKGND, sent },
5278     { 0 }
5279 };
5280
5281 static const struct message WmInvalidateParentChild2[] = {
5282     { WM_ERASEBKGND, sent|parent },
5283     { WM_NCPAINT, sent },
5284     { WM_GETTEXT, sent|defwinproc|optional },
5285     { WM_ERASEBKGND, sent },
5286     { 0 }
5287 };
5288
5289 static const struct message WmParentPaint[] = {
5290     { WM_PAINT, sent|parent },
5291     { WM_PAINT, sent },
5292     { 0 }
5293 };
5294
5295 static const struct message WmParentPaintNc[] = {
5296     { WM_PAINT, sent|parent },
5297     { WM_PAINT, sent },
5298     { WM_NCPAINT, sent|beginpaint },
5299     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5300     { WM_ERASEBKGND, sent|beginpaint },
5301     { 0 }
5302 };
5303
5304 static const struct message WmChildPaintNc[] = {
5305     { WM_PAINT, sent },
5306     { WM_NCPAINT, sent|beginpaint },
5307     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5308     { WM_ERASEBKGND, sent|beginpaint },
5309     { 0 }
5310 };
5311
5312 static const struct message WmParentErasePaint[] = {
5313     { WM_PAINT, sent|parent },
5314     { WM_NCPAINT, sent|parent|beginpaint },
5315     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5316     { WM_ERASEBKGND, sent|parent|beginpaint },
5317     { WM_PAINT, sent },
5318     { WM_NCPAINT, sent|beginpaint },
5319     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5320     { WM_ERASEBKGND, sent|beginpaint },
5321     { 0 }
5322 };
5323
5324 static const struct message WmParentOnlyNcPaint[] = {
5325     { WM_PAINT, sent|parent },
5326     { WM_NCPAINT, sent|parent|beginpaint },
5327     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5328     { 0 }
5329 };
5330
5331 static const struct message WmSetParentStyle[] = {
5332     { WM_STYLECHANGING, sent|parent },
5333     { WM_STYLECHANGED, sent|parent },
5334     { 0 }
5335 };
5336
5337 static void test_paint_messages(void)
5338 {
5339     BOOL ret;
5340     RECT rect;
5341     POINT pt;
5342     MSG msg;
5343     HWND hparent, hchild;
5344     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5345     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5346     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5347                                 100, 100, 200, 200, 0, 0, 0, NULL);
5348     ok (hwnd != 0, "Failed to create overlapped window\n");
5349
5350     ShowWindow( hwnd, SW_SHOW );
5351     UpdateWindow( hwnd );
5352     flush_events();
5353     flush_sequence();
5354
5355     check_update_rgn( hwnd, 0 );
5356     SetRectRgn( hrgn, 10, 10, 20, 20 );
5357     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5358     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5359     check_update_rgn( hwnd, hrgn );
5360     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5361     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5362     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5363     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5364     check_update_rgn( hwnd, hrgn );
5365     /* validate everything */
5366     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5367     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5368     check_update_rgn( hwnd, 0 );
5369
5370     /* test empty region */
5371     SetRectRgn( hrgn, 10, 10, 10, 15 );
5372     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5373     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5374     check_update_rgn( hwnd, 0 );
5375     /* test empty rect */
5376     SetRect( &rect, 10, 10, 10, 15 );
5377     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5378     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5379     check_update_rgn( hwnd, 0 );
5380
5381     /* flush pending messages */
5382     flush_events();
5383     flush_sequence();
5384
5385     GetClientRect( hwnd, &rect );
5386     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5387     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5388      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5389      */
5390     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5391     SetRectEmpty( &rect );
5392     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5393     check_update_rgn( hwnd, hrgn );
5394     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5395     flush_events();
5396     ok_sequence( WmPaint, "Paint", FALSE );
5397     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5398     check_update_rgn( hwnd, 0 );
5399
5400     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5401      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5402      */
5403     trace("testing ValidateRect(0, NULL)\n");
5404     SetRectEmpty( &rect );
5405     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5406     check_update_rgn( hwnd, hrgn );
5407     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5408     flush_events();
5409     ok_sequence( WmPaint, "Paint", FALSE );
5410     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5411     check_update_rgn( hwnd, 0 );
5412
5413     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5414     SetLastError(0xdeadbeef);
5415     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5416     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5417        "wrong error code %d\n", GetLastError());
5418     check_update_rgn( hwnd, 0 );
5419     flush_events();
5420     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5421
5422     trace("testing ValidateRgn(0, NULL)\n");
5423     SetLastError(0xdeadbeef);
5424     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5425     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5426     check_update_rgn( hwnd, 0 );
5427     flush_events();
5428     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5429
5430     /* now with frame */
5431     SetRectRgn( hrgn, -5, -5, 20, 20 );
5432
5433     /* flush pending messages */
5434     flush_events();
5435     flush_sequence();
5436     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5437     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5438
5439     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5440     check_update_rgn( hwnd, hrgn );
5441
5442     flush_sequence();
5443     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5444     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5445
5446     flush_sequence();
5447     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5448     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5449
5450     GetClientRect( hwnd, &rect );
5451     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5452     check_update_rgn( hwnd, hrgn );
5453
5454     flush_sequence();
5455     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5456     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5457
5458     flush_sequence();
5459     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5460     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5461     check_update_rgn( hwnd, 0 );
5462
5463     flush_sequence();
5464     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5465     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5466     check_update_rgn( hwnd, 0 );
5467
5468     flush_sequence();
5469     SetRectRgn( hrgn, 0, 0, 100, 100 );
5470     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5471     SetRectRgn( hrgn, 0, 0, 50, 100 );
5472     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5473     SetRectRgn( hrgn, 50, 0, 100, 100 );
5474     check_update_rgn( hwnd, hrgn );
5475     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5476     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5477     check_update_rgn( hwnd, 0 );
5478
5479     flush_sequence();
5480     SetRectRgn( hrgn, 0, 0, 100, 100 );
5481     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5482     SetRectRgn( hrgn, 0, 0, 100, 50 );
5483     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5484     ok_sequence( WmErase, "Erase", FALSE );
5485     SetRectRgn( hrgn, 0, 50, 100, 100 );
5486     check_update_rgn( hwnd, hrgn );
5487
5488     flush_sequence();
5489     SetRectRgn( hrgn, 0, 0, 100, 100 );
5490     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5491     SetRectRgn( hrgn, 0, 0, 50, 50 );
5492     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5493     ok_sequence( WmPaint, "Paint", FALSE );
5494
5495     flush_sequence();
5496     SetRectRgn( hrgn, -4, -4, -2, -2 );
5497     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5498     SetRectRgn( hrgn, -200, -200, -198, -198 );
5499     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5500     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5501
5502     flush_sequence();
5503     SetRectRgn( hrgn, -4, -4, -2, -2 );
5504     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5505     SetRectRgn( hrgn, -4, -4, -3, -3 );
5506     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5507     SetRectRgn( hrgn, 0, 0, 1, 1 );
5508     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5509     ok_sequence( WmPaint, "Paint", FALSE );
5510
5511     flush_sequence();
5512     SetRectRgn( hrgn, -4, -4, -1, -1 );
5513     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5514     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5515     /* make sure no WM_PAINT was generated */
5516     flush_events();
5517     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5518
5519     flush_sequence();
5520     SetRectRgn( hrgn, -4, -4, -1, -1 );
5521     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5522     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5523     {
5524         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5525         {
5526             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5527             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5528             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5529             ret = GetUpdateRect( hwnd, &rect, FALSE );
5530             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5531             /* this will send WM_NCPAINT and validate the non client area */
5532             ret = GetUpdateRect( hwnd, &rect, TRUE );
5533             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5534         }
5535         DispatchMessage( &msg );
5536     }
5537     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5538
5539     DestroyWindow( hwnd );
5540
5541     /* now test with a child window */
5542
5543     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5544                               100, 100, 200, 200, 0, 0, 0, NULL);
5545     ok (hparent != 0, "Failed to create parent window\n");
5546
5547     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5548                            10, 10, 100, 100, hparent, 0, 0, NULL);
5549     ok (hchild != 0, "Failed to create child window\n");
5550
5551     ShowWindow( hparent, SW_SHOW );
5552     UpdateWindow( hparent );
5553     UpdateWindow( hchild );
5554     flush_events();
5555     flush_sequence();
5556     log_all_parent_messages++;
5557
5558     SetRect( &rect, 0, 0, 50, 50 );
5559     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5560     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5561     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5562
5563     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5564     pt.x = pt.y = 0;
5565     MapWindowPoints( hchild, hparent, &pt, 1 );
5566     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5567     check_update_rgn( hchild, hrgn );
5568     SetRectRgn( hrgn, 0, 0, 50, 50 );
5569     check_update_rgn( hparent, hrgn );
5570     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5571     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5572     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5573     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5574
5575     flush_events();
5576     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5577
5578     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5579     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5580     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5581     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5582     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5583
5584     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5585     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5586     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5587
5588     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5589     flush_sequence();
5590     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5591     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5592     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5593
5594     /* flush all paint messages */
5595     flush_events();
5596     flush_sequence();
5597
5598     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5599     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5600     SetRectRgn( hrgn, 0, 0, 50, 50 );
5601     check_update_rgn( hparent, hrgn );
5602     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5603     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5604     SetRectRgn( hrgn, 0, 0, 50, 50 );
5605     check_update_rgn( hparent, hrgn );
5606
5607     /* flush all paint messages */
5608     flush_events();
5609     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5610     flush_sequence();
5611
5612     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5613     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5614     SetRectRgn( hrgn, 0, 0, 50, 50 );
5615     check_update_rgn( hparent, hrgn );
5616     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5617     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5618     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5619     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5620     check_update_rgn( hparent, hrgn );
5621     /* flush all paint messages */
5622     flush_events();
5623     flush_sequence();
5624
5625     /* same as above but parent gets completely validated */
5626     SetRect( &rect, 20, 20, 30, 30 );
5627     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5628     SetRectRgn( hrgn, 20, 20, 30, 30 );
5629     check_update_rgn( hparent, hrgn );
5630     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5631     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5632     check_update_rgn( hparent, 0 );  /* no update region */
5633     flush_events();
5634     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5635
5636     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5637     flush_sequence();
5638     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5639     SetRectRgn( hrgn, 20, 20, 30, 30 );
5640     check_update_rgn( hparent, hrgn );
5641     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5642     SetRectRgn( hrgn, 20, 20, 30, 30 );
5643     check_update_rgn( hparent, hrgn );
5644
5645     /* same as above but normal WM_PAINT doesn't validate parent */
5646     flush_sequence();
5647     SetRect( &rect, 20, 20, 30, 30 );
5648     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5649     SetRectRgn( hrgn, 20, 20, 30, 30 );
5650     check_update_rgn( hparent, hrgn );
5651     /* no WM_PAINT in child while parent still pending */
5652     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5653     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5654     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5655     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5656
5657     flush_sequence();
5658     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5659     /* no WM_PAINT in child while parent still pending */
5660     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5661     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5662     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5663     /* now that parent is valid child should get WM_PAINT */
5664     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5665     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5666     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5667     ok_sequence( WmEmptySeq, "No other message", FALSE );
5668
5669     /* same thing with WS_CLIPCHILDREN in parent */
5670     flush_sequence();
5671     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5672     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5673     /* changing style invalidates non client area, but we need to invalidate something else to see it */
5674     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5675     ok_sequence( WmEmptySeq, "No message", FALSE );
5676     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5677     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5678
5679     flush_sequence();
5680     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5681     SetRectRgn( hrgn, 20, 20, 30, 30 );
5682     check_update_rgn( hparent, hrgn );
5683     /* no WM_PAINT in child while parent still pending */
5684     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5685     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5686     /* WM_PAINT in parent first */
5687     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5688     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5689
5690     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5691     flush_sequence();
5692     SetRect( &rect, 0, 0, 30, 30 );
5693     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5694     SetRectRgn( hrgn, 0, 0, 30, 30 );
5695     check_update_rgn( hparent, hrgn );
5696     flush_events();
5697     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5698
5699     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5700     flush_sequence();
5701     SetRect( &rect, -10, 0, 30, 30 );
5702     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5703     SetRect( &rect, 0, 0, 20, 20 );
5704     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5705     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5706     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5707
5708     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5709     flush_sequence();
5710     SetRect( &rect, -10, 0, 30, 30 );
5711     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5712     SetRect( &rect, 0, 0, 100, 100 );
5713     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5714     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5715     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5716     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5717     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5718
5719     /* test RDW_INTERNALPAINT behavior */
5720
5721     flush_sequence();
5722     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5723     flush_events();
5724     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5725
5726     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5727     flush_events();
5728     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5729
5730     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5731     flush_events();
5732     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5733
5734     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5735     UpdateWindow( hparent );
5736     flush_events();
5737     flush_sequence();
5738     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5739     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5740     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5741                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5742     flush_events();
5743     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5744
5745     UpdateWindow( hparent );
5746     flush_events();
5747     flush_sequence();
5748     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5749     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5750     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5751                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5752     flush_events();
5753     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5754
5755     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5756     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5757     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5758     flush_events();
5759     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5760
5761     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5762     UpdateWindow( hparent );
5763     flush_events();
5764     flush_sequence();
5765     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5766     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5767     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5768                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5769     flush_events();
5770     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5771
5772     UpdateWindow( hparent );
5773     flush_events();
5774     flush_sequence();
5775     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5776     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5777     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5778                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5779     flush_events();
5780     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5781
5782     log_all_parent_messages--;
5783     DestroyWindow( hparent );
5784     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5785
5786     DeleteObject( hrgn );
5787     DeleteObject( hrgn2 );
5788 }
5789
5790 struct wnd_event
5791 {
5792     HWND hwnd;
5793     HANDLE event;
5794 };
5795
5796 static DWORD WINAPI thread_proc(void *param)
5797 {
5798     MSG msg;
5799     struct wnd_event *wnd_event = (struct wnd_event *)param;
5800
5801     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5802                                       100, 100, 200, 200, 0, 0, 0, NULL);
5803     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5804
5805     SetEvent(wnd_event->event);
5806
5807     while (GetMessage(&msg, 0, 0, 0))
5808     {
5809         TranslateMessage(&msg);
5810         DispatchMessage(&msg);
5811     }
5812
5813     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5814
5815     return 0;
5816 }
5817
5818 static void test_interthread_messages(void)
5819 {
5820     HANDLE hThread;
5821     DWORD tid;
5822     WNDPROC proc;
5823     MSG msg;
5824     char buf[256];
5825     int len, expected_len;
5826     struct wnd_event wnd_event;
5827     BOOL ret;
5828
5829     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
5830     if (!wnd_event.event)
5831     {
5832         trace("skipping interthread message test under win9x\n");
5833         return;
5834     }
5835
5836     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
5837     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
5838
5839     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5840
5841     CloseHandle(wnd_event.event);
5842
5843     SetLastError(0xdeadbeef);
5844     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
5845     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
5846        "wrong error code %d\n", GetLastError());
5847
5848     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5849     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
5850
5851     expected_len = lstrlenA("window caption text");
5852     memset(buf, 0, sizeof(buf));
5853     SetLastError(0xdeadbeef);
5854     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
5855     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
5856     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
5857
5858     msg.hwnd = wnd_event.hwnd;
5859     msg.message = WM_GETTEXT;
5860     msg.wParam = sizeof(buf);
5861     msg.lParam = (LPARAM)buf;
5862     memset(buf, 0, sizeof(buf));
5863     SetLastError(0xdeadbeef);
5864     len = DispatchMessageA(&msg);
5865     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
5866        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
5867
5868     /* the following test causes an exception in user.exe under win9x */
5869     msg.hwnd = wnd_event.hwnd;
5870     msg.message = WM_TIMER;
5871     msg.wParam = 0;
5872     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5873     SetLastError(0xdeadbeef);
5874     len = DispatchMessageA(&msg);
5875     ok(!len && GetLastError() == 0xdeadbeef,
5876        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
5877
5878     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
5879     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
5880
5881     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5882     CloseHandle(hThread);
5883
5884     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
5885 }
5886
5887
5888 static const struct message WmVkN[] = {
5889     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5890     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5891     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5892     { WM_CHAR, wparam|lparam, 'n', 1 },
5893     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
5894     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5895     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5896     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5897     { 0 }
5898 };
5899 static const struct message WmShiftVkN[] = {
5900     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5901     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5902     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5903     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5904     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5905     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5906     { WM_CHAR, wparam|lparam, 'N', 1 },
5907     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
5908     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5909     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5910     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5911     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5912     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5913     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5914     { 0 }
5915 };
5916 static const struct message WmCtrlVkN[] = {
5917     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5918     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5919     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5920     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5921     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5922     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5923     { WM_CHAR, wparam|lparam, 0x000e, 1 },
5924     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5925     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5926     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5927     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5928     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5929     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5930     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5931     { 0 }
5932 };
5933 static const struct message WmCtrlVkN_2[] = {
5934     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5935     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5936     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5937     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5938     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5939     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5940     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5941     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5942     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5943     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5944     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5945     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5946     { 0 }
5947 };
5948 static const struct message WmAltVkN[] = {
5949     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5950     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5951     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5952     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5953     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5954     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5955     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
5956     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
5957     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
5958     { HCBT_SYSCOMMAND, hook },
5959     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5960     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5961     { 0x00AE, sent|defwinproc|optional }, /* XP */
5962     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
5963     { WM_INITMENU, sent|defwinproc },
5964     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5965     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
5966     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5967     { WM_CAPTURECHANGED, sent|defwinproc },
5968     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
5969     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5970     { WM_EXITMENULOOP, sent|defwinproc },
5971     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
5972     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
5973     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5974     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5975     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5976     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5977     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5978     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5979     { 0 }
5980 };
5981 static const struct message WmAltVkN_2[] = {
5982     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5983     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5984     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5985     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5986     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5987     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
5988     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5989     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5990     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5991     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5992     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5993     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5994     { 0 }
5995 };
5996 static const struct message WmCtrlAltVkN[] = {
5997     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5998     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5999     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6000     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6001     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6002     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6003     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6004     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6005     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6006     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6007     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6008     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6009     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6010     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6011     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6012     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6013     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6014     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6015     { 0 }
6016 };
6017 static const struct message WmCtrlShiftVkN[] = {
6018     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6019     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6020     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6021     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6022     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6023     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6024     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6025     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6026     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6027     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6028     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6029     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6030     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6031     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6032     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6033     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6034     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6035     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6036     { 0 }
6037 };
6038 static const struct message WmCtrlAltShiftVkN[] = {
6039     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6040     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6041     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6042     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6043     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6044     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6045     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6046     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6047     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6048     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6049     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6050     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6051     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6052     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6053     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6054     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6055     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6056     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6057     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6058     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6059     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6060     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6061     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6062     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6063     { 0 }
6064 };
6065 static const struct message WmAltPressRelease[] = {
6066     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6067     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6068     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6069     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6070     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6071     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6072     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6073     { HCBT_SYSCOMMAND, hook },
6074     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6075     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6076     { WM_INITMENU, sent|defwinproc },
6077     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6078     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6079     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6080
6081     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6082
6083     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6084     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6085     { WM_CAPTURECHANGED, sent|defwinproc },
6086     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6087     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6088     { WM_EXITMENULOOP, sent|defwinproc },
6089     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6090     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6091     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6092     { 0 }
6093 };
6094 static const struct message WmAltMouseButton[] = {
6095     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6096     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6097     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6098     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6099     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6100     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6101     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6102     { WM_LBUTTONUP, wparam, 0, 0 },
6103     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6104     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6105     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6106     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6107     { 0 }
6108 };
6109 static const struct message WmF1Seq[] = {
6110     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6111     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6112     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6113     { WM_KEYF1, wparam|lparam, 0, 0 },
6114     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6115     { WM_HELP, sent|defwinproc },
6116     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6117     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6118     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6119     { 0 }
6120 };
6121 static const struct message WmVkAppsSeq[] = {
6122     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6123     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6124     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6125     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6126     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6127     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6128     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6129     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6130     { 0 }
6131 };
6132
6133 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6134 {
6135     MSG msg;
6136
6137     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6138     {
6139         struct message log_msg;
6140
6141         trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
6142
6143         /* ignore some unwanted messages */
6144         if (msg.message == WM_MOUSEMOVE ||
6145             msg.message == WM_GETICON ||
6146             msg.message == WM_DEVICECHANGE)
6147             continue;
6148
6149         log_msg.message = msg.message;
6150         log_msg.flags = wparam|lparam;
6151         log_msg.wParam = msg.wParam;
6152         log_msg.lParam = msg.lParam;
6153         add_message(&log_msg);
6154
6155         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6156         {
6157             TranslateMessage(&msg);
6158             DispatchMessage(&msg);
6159         }
6160     }
6161 }
6162
6163 static void test_accelerators(void)
6164 {
6165     RECT rc;
6166     SHORT state;
6167     HACCEL hAccel;
6168     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6169                                 100, 100, 200, 200, 0, 0, 0, NULL);
6170     BOOL ret;
6171
6172     assert(hwnd != 0);
6173     UpdateWindow(hwnd);
6174     flush_events();
6175     flush_sequence();
6176
6177     SetFocus(hwnd);
6178     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6179
6180     state = GetKeyState(VK_SHIFT);
6181     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6182     state = GetKeyState(VK_CAPITAL);
6183     ok(state == 0, "wrong CapsLock state %04x\n", state);
6184
6185     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6186     assert(hAccel != 0);
6187
6188     pump_msg_loop(hwnd, 0);
6189     flush_sequence();
6190
6191     trace("testing VK_N press/release\n");
6192     flush_sequence();
6193     keybd_event('N', 0, 0, 0);
6194     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6195     pump_msg_loop(hwnd, hAccel);
6196     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6197
6198     trace("testing Shift+VK_N press/release\n");
6199     flush_sequence();
6200     keybd_event(VK_SHIFT, 0, 0, 0);
6201     keybd_event('N', 0, 0, 0);
6202     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6203     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6204     pump_msg_loop(hwnd, hAccel);
6205     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6206
6207     trace("testing Ctrl+VK_N press/release\n");
6208     flush_sequence();
6209     keybd_event(VK_CONTROL, 0, 0, 0);
6210     keybd_event('N', 0, 0, 0);
6211     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6212     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6213     pump_msg_loop(hwnd, hAccel);
6214     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6215
6216     trace("testing Alt+VK_N press/release\n");
6217     flush_sequence();
6218     keybd_event(VK_MENU, 0, 0, 0);
6219     keybd_event('N', 0, 0, 0);
6220     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6221     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6222     pump_msg_loop(hwnd, hAccel);
6223     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6224
6225     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6226     flush_sequence();
6227     keybd_event(VK_CONTROL, 0, 0, 0);
6228     keybd_event(VK_MENU, 0, 0, 0);
6229     keybd_event('N', 0, 0, 0);
6230     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6231     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6232     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6233     pump_msg_loop(hwnd, hAccel);
6234     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6235
6236     ret = DestroyAcceleratorTable(hAccel);
6237     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6238
6239     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6240     assert(hAccel != 0);
6241
6242     trace("testing VK_N press/release\n");
6243     flush_sequence();
6244     keybd_event('N', 0, 0, 0);
6245     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6246     pump_msg_loop(hwnd, hAccel);
6247     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6248
6249     trace("testing Shift+VK_N press/release\n");
6250     flush_sequence();
6251     keybd_event(VK_SHIFT, 0, 0, 0);
6252     keybd_event('N', 0, 0, 0);
6253     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6254     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6255     pump_msg_loop(hwnd, hAccel);
6256     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6257
6258     trace("testing Ctrl+VK_N press/release 2\n");
6259     flush_sequence();
6260     keybd_event(VK_CONTROL, 0, 0, 0);
6261     keybd_event('N', 0, 0, 0);
6262     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6263     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6264     pump_msg_loop(hwnd, hAccel);
6265     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6266
6267     trace("testing Alt+VK_N press/release 2\n");
6268     flush_sequence();
6269     keybd_event(VK_MENU, 0, 0, 0);
6270     keybd_event('N', 0, 0, 0);
6271     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6272     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6273     pump_msg_loop(hwnd, hAccel);
6274     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6275
6276     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6277     flush_sequence();
6278     keybd_event(VK_CONTROL, 0, 0, 0);
6279     keybd_event(VK_MENU, 0, 0, 0);
6280     keybd_event('N', 0, 0, 0);
6281     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6282     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6283     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6284     pump_msg_loop(hwnd, hAccel);
6285     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6286
6287     trace("testing Ctrl+Shift+VK_N press/release\n");
6288     flush_sequence();
6289     keybd_event(VK_CONTROL, 0, 0, 0);
6290     keybd_event(VK_SHIFT, 0, 0, 0);
6291     keybd_event('N', 0, 0, 0);
6292     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6293     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6294     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6295     pump_msg_loop(hwnd, hAccel);
6296     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6297
6298     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6299     flush_sequence();
6300     keybd_event(VK_CONTROL, 0, 0, 0);
6301     keybd_event(VK_MENU, 0, 0, 0);
6302     keybd_event(VK_SHIFT, 0, 0, 0);
6303     keybd_event('N', 0, 0, 0);
6304     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6305     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6306     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6307     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6308     pump_msg_loop(hwnd, hAccel);
6309     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6310
6311     ret = DestroyAcceleratorTable(hAccel);
6312     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6313
6314     trace("testing Alt press/release\n");
6315     flush_sequence();
6316     keybd_event(VK_MENU, 0, 0, 0);
6317     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6318     keybd_event(VK_MENU, 0, 0, 0);
6319     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6320     pump_msg_loop(hwnd, 0);
6321     /* this test doesn't pass in Wine for managed windows */
6322     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6323
6324     trace("testing Alt+MouseButton press/release\n");
6325     /* first, move mouse pointer inside of the window client area */
6326     GetClientRect(hwnd, &rc);
6327     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6328     rc.left += (rc.right - rc.left)/2;
6329     rc.top += (rc.bottom - rc.top)/2;
6330     SetCursorPos(rc.left, rc.top);
6331
6332     flush_events();
6333     flush_sequence();
6334     keybd_event(VK_MENU, 0, 0, 0);
6335     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6336     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6337     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6338     pump_msg_loop(hwnd, 0);
6339     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6340
6341     trace("testing VK_F1 press/release\n");
6342     keybd_event(VK_F1, 0, 0, 0);
6343     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6344     pump_msg_loop(hwnd, 0);
6345     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6346
6347     trace("testing VK_APPS press/release\n");
6348     keybd_event(VK_APPS, 0, 0, 0);
6349     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6350     pump_msg_loop(hwnd, 0);
6351     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6352
6353     DestroyWindow(hwnd);
6354 }
6355
6356 /************* window procedures ********************/
6357
6358 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6359                              WPARAM wParam, LPARAM lParam)
6360 {
6361     static long defwndproc_counter = 0;
6362     static long beginpaint_counter = 0;
6363     LRESULT ret;
6364     struct message msg;
6365
6366     trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6367
6368     /* explicitly ignore WM_GETICON message */
6369     if (message == WM_GETICON) return 0;
6370
6371     switch (message)
6372     {
6373         case WM_ENABLE:
6374         {
6375             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6376             ok((BOOL)wParam == !(style & WS_DISABLED),
6377                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6378             break;
6379         }
6380
6381         case WM_CAPTURECHANGED:
6382             if (test_DestroyWindow_flag)
6383             {
6384                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6385                 if (style & WS_CHILD)
6386                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6387                 else if (style & WS_POPUP)
6388                     lParam = WND_POPUP_ID;
6389                 else
6390                     lParam = WND_PARENT_ID;
6391             }
6392             break;
6393
6394         case WM_NCDESTROY:
6395         {
6396             HWND capture;
6397
6398             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6399             capture = GetCapture();
6400             if (capture)
6401             {
6402                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6403                 trace("current capture %p, releasing...\n", capture);
6404                 ReleaseCapture();
6405             }
6406         }
6407         /* fall through */
6408         case WM_DESTROY:
6409             if (pGetAncestor)
6410                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6411             if (test_DestroyWindow_flag)
6412             {
6413                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6414                 if (style & WS_CHILD)
6415                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6416                 else if (style & WS_POPUP)
6417                     lParam = WND_POPUP_ID;
6418                 else
6419                     lParam = WND_PARENT_ID;
6420             }
6421             break;
6422
6423         /* test_accelerators() depends on this */
6424         case WM_NCHITTEST:
6425             return HTCLIENT;
6426     
6427         /* ignore */
6428         case WM_MOUSEMOVE:
6429         case WM_SETCURSOR:
6430         case WM_DEVICECHANGE:
6431             return 0;
6432
6433         case WM_WINDOWPOSCHANGING:
6434         case WM_WINDOWPOSCHANGED:
6435         {
6436             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6437
6438             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6439             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6440                   winpos->hwnd, winpos->hwndInsertAfter,
6441                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6442             dump_winpos_flags(winpos->flags);
6443
6444             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6445              * in the high word for internal purposes
6446              */
6447             wParam = winpos->flags & 0xffff;
6448             /* We are not interested in the flags that don't match under XP and Win9x */
6449             wParam &= ~(SWP_NOZORDER);
6450             break;
6451         }
6452     }
6453
6454     msg.message = message;
6455     msg.flags = sent|wparam|lparam;
6456     if (defwndproc_counter) msg.flags |= defwinproc;
6457     if (beginpaint_counter) msg.flags |= beginpaint;
6458     msg.wParam = wParam;
6459     msg.lParam = lParam;
6460     add_message(&msg);
6461
6462     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6463     {
6464         HWND parent = GetParent(hwnd);
6465         RECT rc;
6466         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6467
6468         GetClientRect(parent, &rc);
6469         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6470
6471         trace("ptReserved = (%d,%d)\n"
6472               "ptMaxSize = (%d,%d)\n"
6473               "ptMaxPosition = (%d,%d)\n"
6474               "ptMinTrackSize = (%d,%d)\n"
6475               "ptMaxTrackSize = (%d,%d)\n",
6476               minmax->ptReserved.x, minmax->ptReserved.y,
6477               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6478               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6479               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6480               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6481
6482         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6483            minmax->ptMaxSize.x, rc.right);
6484         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6485            minmax->ptMaxSize.y, rc.bottom);
6486     }
6487
6488     if (message == WM_PAINT)
6489     {
6490         PAINTSTRUCT ps;
6491         beginpaint_counter++;
6492         BeginPaint( hwnd, &ps );
6493         beginpaint_counter--;
6494         EndPaint( hwnd, &ps );
6495         return 0;
6496     }
6497
6498     defwndproc_counter++;
6499     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6500                   : DefWindowProcA(hwnd, message, wParam, lParam);
6501     defwndproc_counter--;
6502
6503     return ret;
6504 }
6505
6506 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6507 {
6508     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6509 }
6510
6511 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6512 {
6513     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6514 }
6515
6516 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6517 {
6518     static long defwndproc_counter = 0;
6519     LRESULT ret;
6520     struct message msg;
6521
6522     trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6523
6524     /* explicitly ignore WM_GETICON message */
6525     if (message == WM_GETICON) return 0;
6526
6527     msg.message = message;
6528     msg.flags = sent|wparam|lparam;
6529     if (defwndproc_counter) msg.flags |= defwinproc;
6530     msg.wParam = wParam;
6531     msg.lParam = lParam;
6532     add_message(&msg);
6533
6534     if (message == WM_CREATE)
6535     {
6536         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6537         SetWindowLongA(hwnd, GWL_STYLE, style);
6538     }
6539
6540     defwndproc_counter++;
6541     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6542     defwndproc_counter--;
6543
6544     return ret;
6545 }
6546
6547 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6548 {
6549     static long defwndproc_counter = 0;
6550     static long beginpaint_counter = 0;
6551     LRESULT ret;
6552     struct message msg;
6553     LPARAM logged_lParam;
6554
6555     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6556
6557     /* explicitly ignore WM_GETICON message */
6558     if (message == WM_GETICON) return 0;
6559
6560     logged_lParam=lParam;
6561     if (log_all_parent_messages ||
6562         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6563         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6564         message == WM_ENABLE || message == WM_ENTERIDLE ||
6565         message == WM_DRAWITEM ||
6566         message == WM_IME_SETCONTEXT)
6567     {
6568         switch (message)
6569         {
6570             /* ignore */
6571             case WM_NCHITTEST:
6572                 return HTCLIENT;
6573             case WM_SETCURSOR:
6574             case WM_MOUSEMOVE:
6575                 return 0;
6576
6577             case WM_ERASEBKGND:
6578             {
6579                 RECT rc;
6580                 INT ret = GetClipBox((HDC)wParam, &rc);
6581
6582                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6583                        ret, rc.left, rc.top, rc.right, rc.bottom);
6584                 break;
6585             }
6586
6587             case WM_WINDOWPOSCHANGING:
6588             case WM_WINDOWPOSCHANGED:
6589             {
6590                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6591
6592                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6593                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6594                       winpos->hwnd, winpos->hwndInsertAfter,
6595                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6596                 dump_winpos_flags(winpos->flags);
6597
6598                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6599                  * in the high word for internal purposes
6600                  */
6601                 wParam = winpos->flags & 0xffff;
6602                 /* We are not interested in the flags that don't match under XP and Win9x */
6603                 wParam &= ~(SWP_NOZORDER);
6604                 break;
6605             }
6606
6607             case WM_DRAWITEM:
6608             {
6609                 /* encode DRAWITEMSTRUCT into an LPARAM */
6610                 DRAW_ITEM_STRUCT di;
6611                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6612
6613                 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6614                       dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6615
6616                 di.u.item.type = dis->CtlType;
6617                 di.u.item.ctl_id = dis->CtlID;
6618                 di.u.item.item_id = dis->itemID;
6619                 di.u.item.action = dis->itemAction;
6620                 di.u.item.state = dis->itemState;
6621
6622                 logged_lParam = di.u.lp;
6623                 break;
6624             }
6625         }
6626
6627         msg.message = message;
6628         msg.flags = sent|parent|wparam|lparam;
6629         if (defwndproc_counter) msg.flags |= defwinproc;
6630         if (beginpaint_counter) msg.flags |= beginpaint;
6631         msg.wParam = wParam;
6632         msg.lParam = logged_lParam;
6633         add_message(&msg);
6634     }
6635
6636     if (message == WM_PAINT)
6637     {
6638         PAINTSTRUCT ps;
6639         beginpaint_counter++;
6640         BeginPaint( hwnd, &ps );
6641         beginpaint_counter--;
6642         EndPaint( hwnd, &ps );
6643         return 0;
6644     }
6645
6646     defwndproc_counter++;
6647     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6648     defwndproc_counter--;
6649
6650     return ret;
6651 }
6652
6653 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6654 {
6655     static long defwndproc_counter = 0;
6656     LRESULT ret;
6657     struct message msg;
6658
6659     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6660
6661     /* explicitly ignore WM_GETICON message */
6662     if (message == WM_GETICON) return 0;
6663
6664     if (test_def_id)
6665     {
6666         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6667         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6668         if (after_end_dialog)
6669             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6670         else
6671             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6672     }
6673
6674     switch (message)
6675     {
6676         case WM_WINDOWPOSCHANGING:
6677         case WM_WINDOWPOSCHANGED:
6678         {
6679             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6680
6681             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6682             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6683                   winpos->hwnd, winpos->hwndInsertAfter,
6684                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6685             dump_winpos_flags(winpos->flags);
6686
6687             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6688              * in the high word for internal purposes
6689              */
6690             wParam = winpos->flags & 0xffff;
6691             /* We are not interested in the flags that don't match under XP and Win9x */
6692             wParam &= ~(SWP_NOZORDER);
6693             break;
6694         }
6695     }
6696
6697     msg.message = message;
6698     msg.flags = sent|wparam|lparam;
6699     if (defwndproc_counter) msg.flags |= defwinproc;
6700     msg.wParam = wParam;
6701     msg.lParam = lParam;
6702     add_message(&msg);
6703
6704     defwndproc_counter++;
6705     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6706     defwndproc_counter--;
6707
6708     return ret;
6709 }
6710
6711 static void dump_winpos_flags(UINT flags)
6712 {
6713     if (!winetest_debug) return;
6714
6715     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6716     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6717     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6718     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6719     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6720     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6721     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6722     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6723     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6724     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6725     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6726     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6727     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6728     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6729     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6730
6731 #define DUMPED_FLAGS \
6732     (SWP_NOSIZE | \
6733     SWP_NOMOVE | \
6734     SWP_NOZORDER | \
6735     SWP_NOREDRAW | \
6736     SWP_NOACTIVATE | \
6737     SWP_FRAMECHANGED | \
6738     SWP_SHOWWINDOW | \
6739     SWP_HIDEWINDOW | \
6740     SWP_NOCOPYBITS | \
6741     SWP_NOOWNERZORDER | \
6742     SWP_NOSENDCHANGING | \
6743     SWP_DEFERERASE | \
6744     SWP_ASYNCWINDOWPOS | \
6745     SWP_NOCLIENTSIZE | \
6746     SWP_NOCLIENTMOVE)
6747
6748     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6749     printf("\n");
6750 #undef DUMPED_FLAGS
6751 }
6752
6753 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6754 {
6755     static long defwndproc_counter = 0;
6756     LRESULT ret;
6757     struct message msg;
6758
6759     /* log only specific messages we are interested in */
6760     switch (message)
6761     {
6762 #if 0 /* probably log these as well */
6763     case WM_ACTIVATE:
6764     case WM_SETFOCUS:
6765     case WM_KILLFOCUS:
6766 #endif
6767     case WM_SHOWWINDOW:
6768         trace("WM_SHOWWINDOW %ld\n", wParam);
6769         break;
6770     case WM_SIZE:
6771         trace("WM_SIZE %ld\n", wParam);
6772         break;
6773     case WM_MOVE:
6774         trace("WM_MOVE\n");
6775         break;
6776     case WM_GETMINMAXINFO:
6777         trace("WM_GETMINMAXINFO\n");
6778         break;
6779
6780     case WM_WINDOWPOSCHANGING:
6781     case WM_WINDOWPOSCHANGED:
6782     {
6783         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6784
6785         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6786         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6787               winpos->hwnd, winpos->hwndInsertAfter,
6788               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6789         trace("flags: ");
6790         dump_winpos_flags(winpos->flags);
6791
6792         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6793          * in the high word for internal purposes
6794          */
6795         wParam = winpos->flags & 0xffff;
6796         /* We are not interested in the flags that don't match under XP and Win9x */
6797         wParam &= ~(SWP_NOZORDER);
6798         break;
6799     }
6800
6801     default: /* ignore */
6802         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6803         return DefWindowProcA(hwnd, message, wParam, lParam);
6804     }
6805
6806     msg.message = message;
6807     msg.flags = sent|wparam|lparam;
6808     if (defwndproc_counter) msg.flags |= defwinproc;
6809     msg.wParam = wParam;
6810     msg.lParam = lParam;
6811     add_message(&msg);
6812
6813     defwndproc_counter++;
6814     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6815     defwndproc_counter--;
6816
6817     return ret;
6818 }
6819
6820 static BOOL RegisterWindowClasses(void)
6821 {
6822     WNDCLASSA cls;
6823     WNDCLASSW clsW;
6824
6825     cls.style = 0;
6826     cls.lpfnWndProc = MsgCheckProcA;
6827     cls.cbClsExtra = 0;
6828     cls.cbWndExtra = 0;
6829     cls.hInstance = GetModuleHandleA(0);
6830     cls.hIcon = 0;
6831     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6832     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6833     cls.lpszMenuName = NULL;
6834     cls.lpszClassName = "TestWindowClass";
6835     if(!RegisterClassA(&cls)) return FALSE;
6836
6837     cls.lpfnWndProc = ShowWindowProcA;
6838     cls.lpszClassName = "ShowWindowClass";
6839     if(!RegisterClassA(&cls)) return FALSE;
6840
6841     cls.lpfnWndProc = PopupMsgCheckProcA;
6842     cls.lpszClassName = "TestPopupClass";
6843     if(!RegisterClassA(&cls)) return FALSE;
6844
6845     cls.lpfnWndProc = ParentMsgCheckProcA;
6846     cls.lpszClassName = "TestParentClass";
6847     if(!RegisterClassA(&cls)) return FALSE;
6848
6849     cls.lpfnWndProc = DefWindowProcA;
6850     cls.lpszClassName = "SimpleWindowClass";
6851     if(!RegisterClassA(&cls)) return FALSE;
6852
6853     cls.style = CS_NOCLOSE;
6854     cls.lpszClassName = "NoCloseWindowClass";
6855     if(!RegisterClassA(&cls)) return FALSE;
6856
6857     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6858     cls.style = 0;
6859     cls.hInstance = GetModuleHandleA(0);
6860     cls.hbrBackground = 0;
6861     cls.lpfnWndProc = TestDlgProcA;
6862     cls.lpszClassName = "TestDialogClass";
6863     if(!RegisterClassA(&cls)) return FALSE;
6864
6865     clsW.style = 0;
6866     clsW.lpfnWndProc = MsgCheckProcW;
6867     clsW.cbClsExtra = 0;
6868     clsW.cbWndExtra = 0;
6869     clsW.hInstance = GetModuleHandleW(0);
6870     clsW.hIcon = 0;
6871     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6872     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
6873     clsW.lpszMenuName = NULL;
6874     clsW.lpszClassName = testWindowClassW;
6875     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
6876
6877     return TRUE;
6878 }
6879
6880 static HHOOK hCBT_hook;
6881 static DWORD cbt_hook_thread_id;
6882
6883 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6884
6885     static const char * const CBT_code_name[10] = {
6886         "HCBT_MOVESIZE",
6887         "HCBT_MINMAX",
6888         "HCBT_QS",
6889         "HCBT_CREATEWND",
6890         "HCBT_DESTROYWND",
6891         "HCBT_ACTIVATE",
6892         "HCBT_CLICKSKIPPED",
6893         "HCBT_KEYSKIPPED",
6894         "HCBT_SYSCOMMAND",
6895         "HCBT_SETFOCUS" };
6896     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6897     HWND hwnd;
6898     char buf[256];
6899
6900     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
6901
6902     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6903
6904     if (nCode == HCBT_CLICKSKIPPED)
6905     {
6906         /* ignore this event, XP sends it a lot when switching focus between windows */
6907         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6908     }
6909
6910     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6911     {
6912         struct message msg;
6913
6914         msg.message = nCode;
6915         msg.flags = hook|wparam|lparam;
6916         msg.wParam = wParam;
6917         msg.lParam = lParam;
6918         add_message(&msg);
6919
6920         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6921     }
6922
6923     if (nCode == HCBT_DESTROYWND)
6924     {
6925         if (test_DestroyWindow_flag)
6926         {
6927             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6928             if (style & WS_CHILD)
6929                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6930             else if (style & WS_POPUP)
6931                 lParam = WND_POPUP_ID;
6932             else
6933                 lParam = WND_PARENT_ID;
6934         }
6935     }
6936
6937     /* Log also SetFocus(0) calls */
6938     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6939
6940     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6941     {
6942         if (!lstrcmpiA(buf, "TestWindowClass") ||
6943             !lstrcmpiA(buf, "ShowWindowClass") ||
6944             !lstrcmpiA(buf, "TestParentClass") ||
6945             !lstrcmpiA(buf, "TestPopupClass") ||
6946             !lstrcmpiA(buf, "SimpleWindowClass") ||
6947             !lstrcmpiA(buf, "TestDialogClass") ||
6948             !lstrcmpiA(buf, "MDI_frame_class") ||
6949             !lstrcmpiA(buf, "MDI_client_class") ||
6950             !lstrcmpiA(buf, "MDI_child_class") ||
6951             !lstrcmpiA(buf, "my_button_class") ||
6952             !lstrcmpiA(buf, "my_edit_class") ||
6953             !lstrcmpiA(buf, "static") ||
6954             !lstrcmpiA(buf, "ListBox") ||
6955             !lstrcmpiA(buf, "ComboBox") ||
6956             !lstrcmpiA(buf, "MyDialogClass") ||
6957             !lstrcmpiA(buf, "#32770"))
6958         {
6959             struct message msg;
6960
6961             msg.message = nCode;
6962             msg.flags = hook|wparam|lparam;
6963             msg.wParam = wParam;
6964             msg.lParam = lParam;
6965             add_message(&msg);
6966         }
6967     }
6968     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6969 }
6970
6971 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6972                                     DWORD event,
6973                                     HWND hwnd,
6974                                     LONG object_id,
6975                                     LONG child_id,
6976                                     DWORD thread_id,
6977                                     DWORD event_time)
6978 {
6979     char buf[256];
6980
6981     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6982            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6983
6984     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6985
6986     /* ignore mouse cursor events */
6987     if (object_id == OBJID_CURSOR) return;
6988
6989     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6990     {
6991         if (!hwnd ||
6992             !lstrcmpiA(buf, "TestWindowClass") ||
6993             !lstrcmpiA(buf, "TestParentClass") ||
6994             !lstrcmpiA(buf, "TestPopupClass") ||
6995             !lstrcmpiA(buf, "SimpleWindowClass") ||
6996             !lstrcmpiA(buf, "TestDialogClass") ||
6997             !lstrcmpiA(buf, "MDI_frame_class") ||
6998             !lstrcmpiA(buf, "MDI_client_class") ||
6999             !lstrcmpiA(buf, "MDI_child_class") ||
7000             !lstrcmpiA(buf, "my_button_class") ||
7001             !lstrcmpiA(buf, "my_edit_class") ||
7002             !lstrcmpiA(buf, "static") ||
7003             !lstrcmpiA(buf, "ListBox") ||
7004             !lstrcmpiA(buf, "ComboBox") ||
7005             !lstrcmpiA(buf, "MyDialogClass") ||
7006             !lstrcmpiA(buf, "#32770"))
7007         {
7008             struct message msg;
7009
7010             msg.message = event;
7011             msg.flags = winevent_hook|wparam|lparam;
7012             msg.wParam = object_id;
7013             msg.lParam = child_id;
7014             add_message(&msg);
7015         }
7016     }
7017 }
7018
7019 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7020 static const WCHAR wszAnsi[] = {'U',0};
7021
7022 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7023 {
7024     switch (uMsg)
7025     {
7026     case CB_FINDSTRINGEXACT:
7027         trace("String: %p\n", (LPCWSTR)lParam);
7028         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7029             return 1;
7030         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7031             return 0;
7032         return -1;
7033     }
7034     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7035 }
7036
7037 static const struct message WmGetTextLengthAfromW[] = {
7038     { WM_GETTEXTLENGTH, sent },
7039     { WM_GETTEXT, sent },
7040     { 0 }
7041 };
7042
7043 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7044
7045 /* dummy window proc for WM_GETTEXTLENGTH test */
7046 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7047 {
7048     switch(msg)
7049     {
7050     case WM_GETTEXTLENGTH:
7051         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7052     case WM_GETTEXT:
7053         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7054         return lstrlenW( (LPWSTR)lp );
7055     default:
7056         return DefWindowProcW( hwnd, msg, wp, lp );
7057     }
7058 }
7059
7060 static void test_message_conversion(void)
7061 {
7062     static const WCHAR wszMsgConversionClass[] =
7063         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7064     WNDCLASSW cls;
7065     LRESULT lRes;
7066     HWND hwnd;
7067     WNDPROC wndproc, newproc;
7068     BOOL ret;
7069
7070     cls.style = 0;
7071     cls.lpfnWndProc = MsgConversionProcW;
7072     cls.cbClsExtra = 0;
7073     cls.cbWndExtra = 0;
7074     cls.hInstance = GetModuleHandleW(NULL);
7075     cls.hIcon = NULL;
7076     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7077     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7078     cls.lpszMenuName = NULL;
7079     cls.lpszClassName = wszMsgConversionClass;
7080     /* this call will fail on Win9x, but that doesn't matter as this test is
7081      * meaningless on those platforms */
7082     if(!RegisterClassW(&cls)) return;
7083
7084     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7085                            100, 100, 200, 200, 0, 0, 0, NULL);
7086     ok(hwnd != NULL, "Window creation failed\n");
7087
7088     /* {W, A} -> A */
7089
7090     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7091     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7092     ok(lRes == 0, "String should have been converted\n");
7093     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7094     ok(lRes == 1, "String shouldn't have been converted\n");
7095
7096     /* {W, A} -> W */
7097
7098     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7099     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7100     ok(lRes == 1, "String shouldn't have been converted\n");
7101     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7102     ok(lRes == 1, "String shouldn't have been converted\n");
7103
7104     /* Synchronous messages */
7105
7106     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7107     ok(lRes == 0, "String should have been converted\n");
7108     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7109     ok(lRes == 1, "String shouldn't have been converted\n");
7110
7111     /* Asynchronous messages */
7112
7113     SetLastError(0);
7114     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7115     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7116         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7117     SetLastError(0);
7118     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7119     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7120         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7121     SetLastError(0);
7122     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7123     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7124         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7125     SetLastError(0);
7126     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7127     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7128         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7129     SetLastError(0);
7130     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7131     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7132         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7133     SetLastError(0);
7134     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7135     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7136         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7137     SetLastError(0);
7138     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7139     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7140         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7141     SetLastError(0);
7142     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7143     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7144         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7145
7146     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7147
7148     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7149                           WS_OVERLAPPEDWINDOW,
7150                           100, 100, 200, 200, 0, 0, 0, NULL);
7151     assert(hwnd);
7152     flush_sequence();
7153     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7154     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7155     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7156         "got bad length %ld\n", lRes );
7157
7158     flush_sequence();
7159     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7160                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7161     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7162     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7163         "got bad length %ld\n", lRes );
7164
7165     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7166     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7167     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7168     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7169                                      NULL, 0, NULL, NULL ),
7170         "got bad length %ld\n", lRes );
7171
7172     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7173     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7174     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7175                                      NULL, 0, NULL, NULL ),
7176         "got bad length %ld\n", lRes );
7177
7178     ret = DestroyWindow(hwnd);
7179     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7180 }
7181
7182 struct timer_info
7183 {
7184     HWND hWnd;
7185     HANDLE handles[2];
7186     DWORD id;
7187 };
7188
7189 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7190 {
7191 }
7192
7193 #define TIMER_ID  0x19
7194
7195 static DWORD WINAPI timer_thread_proc(LPVOID x)
7196 {
7197     struct timer_info *info = x;
7198     DWORD r;
7199
7200     r = KillTimer(info->hWnd, 0x19);
7201     ok(r,"KillTimer failed in thread\n");
7202     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7203     ok(r,"SetTimer failed in thread\n");
7204     ok(r==TIMER_ID,"SetTimer id different\n");
7205     r = SetEvent(info->handles[0]);
7206     ok(r,"SetEvent failed in thread\n");
7207     return 0;
7208 }
7209
7210 static void test_timers(void)
7211 {
7212     struct timer_info info;
7213     DWORD id;
7214
7215     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7216        WS_OVERLAPPEDWINDOW ,
7217        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7218        NULL, NULL, 0);
7219
7220     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7221     ok(info.id, "SetTimer failed\n");
7222     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7223     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7224     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7225
7226     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7227
7228     WaitForSingleObject(info.handles[1], INFINITE);
7229
7230     CloseHandle(info.handles[0]);
7231     CloseHandle(info.handles[1]);
7232
7233     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7234
7235     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7236 }
7237
7238 static int count = 0;
7239 static VOID CALLBACK callback_count(
7240     HWND hwnd,
7241     UINT uMsg,
7242     UINT_PTR idEvent,
7243     DWORD dwTime
7244 )
7245 {
7246     count++;
7247 }
7248
7249 static void test_timers_no_wnd(void)
7250 {
7251     UINT_PTR id, id2;
7252     MSG msg;
7253
7254     count = 0;
7255     id = SetTimer(NULL, 0, 100, callback_count);
7256     ok(id != 0, "did not get id from SetTimer.\n");
7257     id2 = SetTimer(NULL, id, 200, callback_count);
7258     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7259     Sleep(150);
7260     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7261     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7262     Sleep(150);
7263     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7264     ok(count == 1, "did not get one count as expected (%i).\n", count);
7265     KillTimer(NULL, id);
7266     Sleep(250);
7267     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7268     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7269 }
7270
7271 /* Various win events with arbitrary parameters */
7272 static const struct message WmWinEventsSeq[] = {
7273     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7274     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7275     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7276     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7277     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7278     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7279     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7280     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7281     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7282     /* our win event hook ignores OBJID_CURSOR events */
7283     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7284     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7285     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7286     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7287     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7288     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7289     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7290     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7291     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7292     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7293     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7294     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7295     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7296     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7297     { 0 }
7298 };
7299 static const struct message WmWinEventCaretSeq[] = {
7300     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7301     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7302     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7303     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7304     { 0 }
7305 };
7306 static const struct message WmWinEventCaretSeq_2[] = {
7307     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7308     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7309     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7310     { 0 }
7311 };
7312 static const struct message WmWinEventAlertSeq[] = {
7313     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7314     { 0 }
7315 };
7316 static const struct message WmWinEventAlertSeq_2[] = {
7317     /* create window in the thread proc */
7318     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7319     /* our test event */
7320     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7321     { 0 }
7322 };
7323 static const struct message WmGlobalHookSeq_1[] = {
7324     /* create window in the thread proc */
7325     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7326     /* our test events */
7327     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7328     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7329     { 0 }
7330 };
7331 static const struct message WmGlobalHookSeq_2[] = {
7332     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7333     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7334     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7335     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7336     { 0 }
7337 };
7338
7339 static const struct message WmMouseLLHookSeq[] = {
7340     { WM_MOUSEMOVE, hook },
7341     { WM_LBUTTONUP, hook },
7342     { WM_MOUSEMOVE, hook },
7343     { 0 }
7344 };
7345
7346 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7347                                          DWORD event,
7348                                          HWND hwnd,
7349                                          LONG object_id,
7350                                          LONG child_id,
7351                                          DWORD thread_id,
7352                                          DWORD event_time)
7353 {
7354     char buf[256];
7355
7356     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7357            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7358
7359     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7360     {
7361         if (!lstrcmpiA(buf, "TestWindowClass") ||
7362             !lstrcmpiA(buf, "static"))
7363         {
7364             struct message msg;
7365
7366             msg.message = event;
7367             msg.flags = winevent_hook|wparam|lparam;
7368             msg.wParam = object_id;
7369             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7370             add_message(&msg);
7371         }
7372     }
7373 }
7374
7375 static HHOOK hCBT_global_hook;
7376 static DWORD cbt_global_hook_thread_id;
7377
7378 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7379
7380     HWND hwnd;
7381     char buf[256];
7382
7383     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7384
7385     if (nCode == HCBT_SYSCOMMAND)
7386     {
7387         struct message msg;
7388
7389         msg.message = nCode;
7390         msg.flags = hook|wparam|lparam;
7391         msg.wParam = wParam;
7392         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7393         add_message(&msg);
7394
7395         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7396     }
7397     /* WH_MOUSE_LL hook */
7398     if (nCode == HC_ACTION)
7399     {
7400         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7401
7402         /* we can't test for real mouse events */
7403         if (mhll->flags & LLMHF_INJECTED)
7404         {
7405             struct message msg;
7406
7407             memset (&msg, 0, sizeof (msg));
7408             msg.message = wParam;
7409             msg.flags = hook;
7410             add_message(&msg);
7411         }
7412         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7413     }
7414
7415     /* Log also SetFocus(0) calls */
7416     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7417
7418     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7419     {
7420         if (!lstrcmpiA(buf, "TestWindowClass") ||
7421             !lstrcmpiA(buf, "static"))
7422         {
7423             struct message msg;
7424
7425             msg.message = nCode;
7426             msg.flags = hook|wparam|lparam;
7427             msg.wParam = wParam;
7428             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7429             add_message(&msg);
7430         }
7431     }
7432     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7433 }
7434
7435 static DWORD WINAPI win_event_global_thread_proc(void *param)
7436 {
7437     HWND hwnd;
7438     MSG msg;
7439     HANDLE hevent = *(HANDLE *)param;
7440
7441     assert(pNotifyWinEvent);
7442
7443     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7444     assert(hwnd);
7445     trace("created thread window %p\n", hwnd);
7446
7447     *(HWND *)param = hwnd;
7448
7449     flush_sequence();
7450     /* this event should be received only by our new hook proc,
7451      * an old one does not expect an event from another thread.
7452      */
7453     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7454     SetEvent(hevent);
7455
7456     while (GetMessage(&msg, 0, 0, 0))
7457     {
7458         TranslateMessage(&msg);
7459         DispatchMessage(&msg);
7460     }
7461     return 0;
7462 }
7463
7464 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7465 {
7466     HWND hwnd;
7467     MSG msg;
7468     HANDLE hevent = *(HANDLE *)param;
7469
7470     flush_sequence();
7471     /* these events should be received only by our new hook proc,
7472      * an old one does not expect an event from another thread.
7473      */
7474
7475     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7476     assert(hwnd);
7477     trace("created thread window %p\n", hwnd);
7478
7479     *(HWND *)param = hwnd;
7480
7481     /* Windows doesn't like when a thread plays games with the focus,
7482        that leads to all kinds of misbehaviours and failures to activate
7483        a window. So, better keep next lines commented out.
7484     SetFocus(0);
7485     SetFocus(hwnd);*/
7486
7487     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7488     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7489
7490     SetEvent(hevent);
7491
7492     while (GetMessage(&msg, 0, 0, 0))
7493     {
7494         TranslateMessage(&msg);
7495         DispatchMessage(&msg);
7496     }
7497     return 0;
7498 }
7499
7500 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7501 {
7502     HWND hwnd;
7503     MSG msg;
7504     HANDLE hevent = *(HANDLE *)param;
7505
7506     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7507     assert(hwnd);
7508     trace("created thread window %p\n", hwnd);
7509
7510     *(HWND *)param = hwnd;
7511
7512     flush_sequence();
7513
7514     /* Windows doesn't like when a thread plays games with the focus,
7515      * that leads to all kinds of misbehaviours and failures to activate
7516      * a window. So, better don't generate a mouse click message below.
7517      */
7518     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7519     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7520     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7521
7522     SetEvent(hevent);
7523     while (GetMessage(&msg, 0, 0, 0))
7524     {
7525         TranslateMessage(&msg);
7526         DispatchMessage(&msg);
7527     }
7528     return 0;
7529 }
7530
7531 static void test_winevents(void)
7532 {
7533     BOOL ret;
7534     MSG msg;
7535     HWND hwnd, hwnd2;
7536     UINT i;
7537     HANDLE hthread, hevent;
7538     DWORD tid;
7539     HWINEVENTHOOK hhook;
7540     const struct message *events = WmWinEventsSeq;
7541
7542     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7543                            WS_OVERLAPPEDWINDOW,
7544                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7545                            NULL, NULL, 0);
7546     assert(hwnd);
7547
7548     /****** start of global hook test *************/
7549     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7550     if (!hCBT_global_hook)
7551     {
7552         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7553         skip( "cannot set global hook\n" );
7554         return;
7555     }
7556
7557     hevent = CreateEventA(NULL, 0, 0, NULL);
7558     assert(hevent);
7559     hwnd2 = (HWND)hevent;
7560
7561     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7562     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7563
7564     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7565
7566     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7567
7568     flush_sequence();
7569     /* this one should be received only by old hook proc */
7570     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7571     /* this one should be received only by old hook proc */
7572     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7573
7574     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7575
7576     ret = UnhookWindowsHookEx(hCBT_global_hook);
7577     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7578
7579     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7580     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7581     CloseHandle(hthread);
7582     CloseHandle(hevent);
7583     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7584     /****** end of global hook test *************/
7585
7586     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7587     {
7588         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7589         return;
7590     }
7591
7592     flush_sequence();
7593
7594     if (0)
7595     {
7596     /* this test doesn't pass under Win9x */
7597     /* win2k ignores events with hwnd == 0 */
7598     SetLastError(0xdeadbeef);
7599     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7600     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7601        GetLastError() == 0xdeadbeef, /* Win9x */
7602        "unexpected error %d\n", GetLastError());
7603     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7604     }
7605
7606     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7607         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7608
7609     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7610
7611     /****** start of event filtering test *************/
7612     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7613         EVENT_OBJECT_SHOW, /* 0x8002 */
7614         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7615         GetModuleHandleA(0), win_event_global_hook_proc,
7616         GetCurrentProcessId(), 0,
7617         WINEVENT_INCONTEXT);
7618     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7619
7620     hevent = CreateEventA(NULL, 0, 0, NULL);
7621     assert(hevent);
7622     hwnd2 = (HWND)hevent;
7623
7624     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7625     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7626
7627     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7628
7629     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7630
7631     flush_sequence();
7632     /* this one should be received only by old hook proc */
7633     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7634     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7635     /* this one should be received only by old hook proc */
7636     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7637
7638     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7639
7640     ret = pUnhookWinEvent(hhook);
7641     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7642
7643     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7644     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7645     CloseHandle(hthread);
7646     CloseHandle(hevent);
7647     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7648     /****** end of event filtering test *************/
7649
7650     /****** start of out of context event test *************/
7651     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7652         EVENT_MIN, EVENT_MAX,
7653         0, win_event_global_hook_proc,
7654         GetCurrentProcessId(), 0,
7655         WINEVENT_OUTOFCONTEXT);
7656     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7657
7658     hevent = CreateEventA(NULL, 0, 0, NULL);
7659     assert(hevent);
7660     hwnd2 = (HWND)hevent;
7661
7662     flush_sequence();
7663
7664     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7665     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7666
7667     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7668
7669     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7670     /* process pending winevent messages */
7671     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7672     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7673
7674     flush_sequence();
7675     /* this one should be received only by old hook proc */
7676     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7677     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7678     /* this one should be received only by old hook proc */
7679     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7680
7681     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7682     /* process pending winevent messages */
7683     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7684     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7685
7686     ret = pUnhookWinEvent(hhook);
7687     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7688
7689     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7690     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7691     CloseHandle(hthread);
7692     CloseHandle(hevent);
7693     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7694     /****** end of out of context event test *************/
7695
7696     /****** start of MOUSE_LL hook test *************/
7697     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7698     /* WH_MOUSE_LL is not supported on Win9x platforms */
7699     if (!hCBT_global_hook)
7700     {
7701         trace("Skipping WH_MOUSE_LL test on this platform\n");
7702         goto skip_mouse_ll_hook_test;
7703     }
7704
7705     hevent = CreateEventA(NULL, 0, 0, NULL);
7706     assert(hevent);
7707     hwnd2 = (HWND)hevent;
7708
7709     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7710     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7711
7712     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7713         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7714
7715     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7716     flush_sequence();
7717
7718     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7719     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7720     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7721
7722     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7723
7724     ret = UnhookWindowsHookEx(hCBT_global_hook);
7725     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7726
7727     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7728     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7729     CloseHandle(hthread);
7730     CloseHandle(hevent);
7731     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7732     /****** end of MOUSE_LL hook test *************/
7733 skip_mouse_ll_hook_test:
7734
7735     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7736 }
7737
7738 static void test_set_hook(void)
7739 {
7740     BOOL ret;
7741     HHOOK hhook;
7742     HWINEVENTHOOK hwinevent_hook;
7743
7744     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7745     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7746     UnhookWindowsHookEx(hhook);
7747
7748     if (0)
7749     {
7750     /* this test doesn't pass under Win9x: BUG! */
7751     SetLastError(0xdeadbeef);
7752     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7753     ok(!hhook, "global hook requires hModule != 0\n");
7754     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7755     }
7756
7757     SetLastError(0xdeadbeef);
7758     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7759     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7760     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7761        GetLastError() == 0xdeadbeef, /* Win9x */
7762        "unexpected error %d\n", GetLastError());
7763
7764     SetLastError(0xdeadbeef);
7765     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7766     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7767        GetLastError() == 0xdeadbeef, /* Win9x */
7768        "unexpected error %d\n", GetLastError());
7769
7770     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7771
7772     /* even process local incontext hooks require hmodule */
7773     SetLastError(0xdeadbeef);
7774     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7775         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7776     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7777     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7778        GetLastError() == 0xdeadbeef, /* Win9x */
7779        "unexpected error %d\n", GetLastError());
7780
7781     /* even thread local incontext hooks require hmodule */
7782     SetLastError(0xdeadbeef);
7783     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7784         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7785     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7786     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7787        GetLastError() == 0xdeadbeef, /* Win9x */
7788        "unexpected error %d\n", GetLastError());
7789
7790     if (0)
7791     {
7792     /* these 3 tests don't pass under Win9x */
7793     SetLastError(0xdeadbeef);
7794     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7795         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7796     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7797     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7798
7799     SetLastError(0xdeadbeef);
7800     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7801         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7802     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7803     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7804
7805     SetLastError(0xdeadbeef);
7806     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7807         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7808     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7809     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7810     }
7811
7812     SetLastError(0xdeadbeef);
7813     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7814         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7815     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7816     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7817     ret = pUnhookWinEvent(hwinevent_hook);
7818     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7819
7820 todo_wine {
7821     /* This call succeeds under win2k SP4, but fails under Wine.
7822        Does win2k test/use passed process id? */
7823     SetLastError(0xdeadbeef);
7824     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7825         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7826     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7827     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7828     ret = pUnhookWinEvent(hwinevent_hook);
7829     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7830 }
7831
7832     SetLastError(0xdeadbeef);
7833     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7834     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7835         GetLastError() == 0xdeadbeef, /* Win9x */
7836         "unexpected error %d\n", GetLastError());
7837 }
7838
7839 static const struct message ScrollWindowPaint1[] = {
7840     { WM_PAINT, sent },
7841     { WM_ERASEBKGND, sent|beginpaint },
7842     { 0 }
7843 };
7844
7845 static const struct message ScrollWindowPaint2[] = {
7846     { WM_PAINT, sent },
7847     { 0 }
7848 };
7849
7850 static void test_scrollwindowex(void)
7851 {
7852     HWND hwnd, hchild;
7853     RECT rect={0,0,130,130};
7854
7855     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7856             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7857             100, 100, 200, 200, 0, 0, 0, NULL);
7858     ok (hwnd != 0, "Failed to create overlapped window\n");
7859     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7860             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7861             10, 10, 150, 150, hwnd, 0, 0, NULL);
7862     ok (hchild != 0, "Failed to create child\n");
7863     UpdateWindow(hwnd);
7864     flush_events();
7865     flush_sequence();
7866
7867     /* scroll without the child window */
7868     trace("start scroll\n");
7869     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7870             SW_ERASE|SW_INVALIDATE);
7871     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7872     trace("end scroll\n");
7873     flush_sequence();
7874     flush_events();
7875     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7876     flush_events();
7877     flush_sequence();
7878
7879     /* Now without the SW_ERASE flag */
7880     trace("start scroll\n");
7881     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7882     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7883     trace("end scroll\n");
7884     flush_sequence();
7885     flush_events();
7886     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7887     flush_events();
7888     flush_sequence();
7889
7890     /* now scroll the child window as well */
7891     trace("start scroll\n");
7892     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7893             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7894     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7895                 /* windows sometimes a WM_MOVE */
7896         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7897     }
7898     trace("end scroll\n");
7899     flush_sequence();
7900     flush_events();
7901     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7902     flush_events();
7903     flush_sequence();
7904
7905     /* now scroll with ScrollWindow() */
7906     trace("start scroll with ScrollWindow\n");
7907     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7908     trace("end scroll\n");
7909     flush_sequence();
7910     flush_events();
7911     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7912
7913     ok(DestroyWindow(hchild), "failed to destroy window\n");
7914     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7915     flush_sequence();
7916 }
7917
7918 static const struct message destroy_window_with_children[] = {
7919     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7920     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7921     { 0x0090, sent|optional },
7922     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7923     { 0x0090, sent|optional },
7924     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7925     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7926     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7927     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7928     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7929     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7930     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7931     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7932     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7933     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7934     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7935     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7936     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7937     { 0 }
7938 };
7939
7940 static void test_DestroyWindow(void)
7941 {
7942     BOOL ret;
7943     HWND parent, child1, child2, child3, child4, test;
7944     UINT child_id = WND_CHILD_ID + 1;
7945
7946     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7947                              100, 100, 200, 200, 0, 0, 0, NULL);
7948     assert(parent != 0);
7949     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7950                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7951     assert(child1 != 0);
7952     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7953                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7954     assert(child2 != 0);
7955     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7956                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7957     assert(child3 != 0);
7958     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7959                              0, 0, 50, 50, parent, 0, 0, NULL);
7960     assert(child4 != 0);
7961
7962     /* test owner/parent of child2 */
7963     test = GetParent(child2);
7964     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7965     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7966     if(pGetAncestor) {
7967         test = pGetAncestor(child2, GA_PARENT);
7968         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7969     }
7970     test = GetWindow(child2, GW_OWNER);
7971     ok(!test, "wrong owner %p\n", test);
7972
7973     test = SetParent(child2, parent);
7974     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7975
7976     /* test owner/parent of the parent */
7977     test = GetParent(parent);
7978     ok(!test, "wrong parent %p\n", test);
7979     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7980     if(pGetAncestor) {
7981         test = pGetAncestor(parent, GA_PARENT);
7982         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7983     }
7984     test = GetWindow(parent, GW_OWNER);
7985     ok(!test, "wrong owner %p\n", test);
7986
7987     /* test owner/parent of child1 */
7988     test = GetParent(child1);
7989     ok(test == parent, "wrong parent %p\n", test);
7990     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7991     if(pGetAncestor) {
7992         test = pGetAncestor(child1, GA_PARENT);
7993         ok(test == parent, "wrong parent %p\n", test);
7994     }
7995     test = GetWindow(child1, GW_OWNER);
7996     ok(!test, "wrong owner %p\n", test);
7997
7998     /* test owner/parent of child2 */
7999     test = GetParent(child2);
8000     ok(test == parent, "wrong parent %p\n", test);
8001     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8002     if(pGetAncestor) {
8003         test = pGetAncestor(child2, GA_PARENT);
8004         ok(test == parent, "wrong parent %p\n", test);
8005     }
8006     test = GetWindow(child2, GW_OWNER);
8007     ok(!test, "wrong owner %p\n", test);
8008
8009     /* test owner/parent of child3 */
8010     test = GetParent(child3);
8011     ok(test == child1, "wrong parent %p\n", test);
8012     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8013     if(pGetAncestor) {
8014         test = pGetAncestor(child3, GA_PARENT);
8015         ok(test == child1, "wrong parent %p\n", test);
8016     }
8017     test = GetWindow(child3, GW_OWNER);
8018     ok(!test, "wrong owner %p\n", test);
8019
8020     /* test owner/parent of child4 */
8021     test = GetParent(child4);
8022     ok(test == parent, "wrong parent %p\n", test);
8023     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8024     if(pGetAncestor) {
8025         test = pGetAncestor(child4, GA_PARENT);
8026         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8027     }
8028     test = GetWindow(child4, GW_OWNER);
8029     ok(test == parent, "wrong owner %p\n", test);
8030
8031     flush_sequence();
8032
8033     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8034            parent, child1, child2, child3, child4);
8035
8036     SetCapture(child4);
8037     test = GetCapture();
8038     ok(test == child4, "wrong capture window %p\n", test);
8039
8040     test_DestroyWindow_flag = TRUE;
8041     ret = DestroyWindow(parent);
8042     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8043     test_DestroyWindow_flag = FALSE;
8044     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8045
8046     ok(!IsWindow(parent), "parent still exists\n");
8047     ok(!IsWindow(child1), "child1 still exists\n");
8048     ok(!IsWindow(child2), "child2 still exists\n");
8049     ok(!IsWindow(child3), "child3 still exists\n");
8050     ok(!IsWindow(child4), "child4 still exists\n");
8051
8052     test = GetCapture();
8053     ok(!test, "wrong capture window %p\n", test);
8054 }
8055
8056
8057 static const struct message WmDispatchPaint[] = {
8058     { WM_NCPAINT, sent },
8059     { WM_GETTEXT, sent|defwinproc|optional },
8060     { WM_GETTEXT, sent|defwinproc|optional },
8061     { WM_ERASEBKGND, sent },
8062     { 0 }
8063 };
8064
8065 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8066 {
8067     if (message == WM_PAINT) return 0;
8068     return MsgCheckProcA( hwnd, message, wParam, lParam );
8069 }
8070
8071 static void test_DispatchMessage(void)
8072 {
8073     RECT rect;
8074     MSG msg;
8075     int count;
8076     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8077                                100, 100, 200, 200, 0, 0, 0, NULL);
8078     ShowWindow( hwnd, SW_SHOW );
8079     UpdateWindow( hwnd );
8080     flush_events();
8081     flush_sequence();
8082     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8083
8084     SetRect( &rect, -5, -5, 5, 5 );
8085     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8086     count = 0;
8087     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8088     {
8089         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8090         else
8091         {
8092             flush_sequence();
8093             DispatchMessage( &msg );
8094             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8095             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8096             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8097             if (++count > 10) break;
8098         }
8099     }
8100     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8101
8102     trace("now without DispatchMessage\n");
8103     flush_sequence();
8104     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8105     count = 0;
8106     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8107     {
8108         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8109         else
8110         {
8111             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8112             flush_sequence();
8113             /* this will send WM_NCCPAINT just like DispatchMessage does */
8114             GetUpdateRgn( hwnd, hrgn, TRUE );
8115             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8116             DeleteObject( hrgn );
8117             GetClientRect( hwnd, &rect );
8118             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8119             ok( !count, "Got multiple WM_PAINTs\n" );
8120             if (++count > 10) break;
8121         }
8122     }
8123     DestroyWindow(hwnd);
8124 }
8125
8126
8127 static const struct message WmUser[] = {
8128     { WM_USER, sent },
8129     { 0 }
8130 };
8131
8132 struct sendmsg_info
8133 {
8134     HWND  hwnd;
8135     DWORD timeout;
8136     DWORD ret;
8137 };
8138
8139 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8140 {
8141     struct sendmsg_info *info = arg;
8142     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8143     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
8144     return 0;
8145 }
8146
8147 static void wait_for_thread( HANDLE thread )
8148 {
8149     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8150     {
8151         MSG msg;
8152         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8153     }
8154 }
8155
8156 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8157 {
8158     if (message == WM_USER) Sleep(200);
8159     return MsgCheckProcA( hwnd, message, wParam, lParam );
8160 }
8161
8162 static void test_SendMessageTimeout(void)
8163 {
8164     HANDLE thread;
8165     struct sendmsg_info info;
8166     DWORD tid;
8167
8168     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8169                                100, 100, 200, 200, 0, 0, 0, NULL);
8170     flush_events();
8171     flush_sequence();
8172
8173     info.timeout = 1000;
8174     info.ret = 0xdeadbeef;
8175     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8176     wait_for_thread( thread );
8177     CloseHandle( thread );
8178     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8179     ok_sequence( WmUser, "WmUser", FALSE );
8180
8181     info.timeout = 1;
8182     info.ret = 0xdeadbeef;
8183     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8184     Sleep(100);  /* SendMessageTimeout should time out here */
8185     wait_for_thread( thread );
8186     CloseHandle( thread );
8187     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8188     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8189
8190     /* 0 means infinite timeout */
8191     info.timeout = 0;
8192     info.ret = 0xdeadbeef;
8193     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8194     Sleep(100);
8195     wait_for_thread( thread );
8196     CloseHandle( thread );
8197     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8198     ok_sequence( WmUser, "WmUser", FALSE );
8199
8200     /* timeout is treated as signed despite the prototype */
8201     info.timeout = 0x7fffffff;
8202     info.ret = 0xdeadbeef;
8203     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8204     Sleep(100);
8205     wait_for_thread( thread );
8206     CloseHandle( thread );
8207     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8208     ok_sequence( WmUser, "WmUser", FALSE );
8209
8210     info.timeout = 0x80000000;
8211     info.ret = 0xdeadbeef;
8212     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8213     Sleep(100);
8214     wait_for_thread( thread );
8215     CloseHandle( thread );
8216     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8217     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8218
8219     /* now check for timeout during message processing */
8220     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8221     info.timeout = 100;
8222     info.ret = 0xdeadbeef;
8223     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8224     wait_for_thread( thread );
8225     CloseHandle( thread );
8226     /* we should time out but still get the message */
8227     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8228     ok_sequence( WmUser, "WmUser", FALSE );
8229
8230     DestroyWindow( info.hwnd );
8231 }
8232
8233
8234 /****************** edit message test *************************/
8235 #define ID_EDIT 0x1234
8236 static const struct message sl_edit_setfocus[] =
8237 {
8238     { HCBT_SETFOCUS, hook },
8239     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8240     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8241     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8242     { WM_SETFOCUS, sent|wparam, 0 },
8243     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8244     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8245     { WM_CTLCOLOREDIT, sent|parent },
8246     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8247     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8248     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8249     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8250     { 0 }
8251 };
8252 static const struct message ml_edit_setfocus[] =
8253 {
8254     { HCBT_SETFOCUS, hook },
8255     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8256     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8257     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8258     { WM_SETFOCUS, sent|wparam, 0 },
8259     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8260     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8261     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8262     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8263     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8264     { 0 }
8265 };
8266 static const struct message sl_edit_killfocus[] =
8267 {
8268     { HCBT_SETFOCUS, hook },
8269     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8270     { WM_KILLFOCUS, sent|wparam, 0 },
8271     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8272     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8273     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8274     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8275     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8276     { 0 }
8277 };
8278 static const struct message sl_edit_lbutton_dblclk[] =
8279 {
8280     { WM_LBUTTONDBLCLK, sent },
8281     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8282     { 0 }
8283 };
8284 static const struct message sl_edit_lbutton_down[] =
8285 {
8286     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8287     { HCBT_SETFOCUS, hook },
8288     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8289     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8290     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8291     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8292     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8293     { WM_CTLCOLOREDIT, sent|parent },
8294     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8295     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8296     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8297     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8298     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8299     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8300     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8301     { WM_CTLCOLOREDIT, sent|parent|optional },
8302     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8303     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8304     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8305     { 0 }
8306 };
8307 static const struct message ml_edit_lbutton_down[] =
8308 {
8309     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8310     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8311     { HCBT_SETFOCUS, hook },
8312     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8313     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8314     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8315     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8316     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8317     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8318     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8319     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8320     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8321     { 0 }
8322 };
8323 static const struct message sl_edit_lbutton_up[] =
8324 {
8325     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8326     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8327     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8328     { WM_CAPTURECHANGED, sent|defwinproc },
8329     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8330     { 0 }
8331 };
8332 static const struct message ml_edit_lbutton_up[] =
8333 {
8334     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8335     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8336     { WM_CAPTURECHANGED, sent|defwinproc },
8337     { 0 }
8338 };
8339
8340 static WNDPROC old_edit_proc;
8341
8342 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8343 {
8344     static long defwndproc_counter = 0;
8345     LRESULT ret;
8346     struct message msg;
8347
8348     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8349
8350     /* explicitly ignore WM_GETICON message */
8351     if (message == WM_GETICON) return 0;
8352
8353     msg.message = message;
8354     msg.flags = sent|wparam|lparam;
8355     if (defwndproc_counter) msg.flags |= defwinproc;
8356     msg.wParam = wParam;
8357     msg.lParam = lParam;
8358     add_message(&msg);
8359
8360     defwndproc_counter++;
8361     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8362     defwndproc_counter--;
8363
8364     return ret;
8365 }
8366
8367 static void subclass_edit(void)
8368 {
8369     WNDCLASSA cls;
8370
8371     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8372
8373     old_edit_proc = cls.lpfnWndProc;
8374
8375     cls.hInstance = GetModuleHandle(0);
8376     cls.lpfnWndProc = edit_hook_proc;
8377     cls.lpszClassName = "my_edit_class";
8378     UnregisterClass(cls.lpszClassName, cls.hInstance);
8379     if (!RegisterClassA(&cls)) assert(0);
8380 }
8381
8382 static void test_edit_messages(void)
8383 {
8384     HWND hwnd, parent;
8385     DWORD dlg_code;
8386
8387     subclass_edit();
8388     log_all_parent_messages++;
8389
8390     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8391                              100, 100, 200, 200, 0, 0, 0, NULL);
8392     ok (parent != 0, "Failed to create parent window\n");
8393
8394     /* test single line edit */
8395     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8396                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8397     ok(hwnd != 0, "Failed to create edit window\n");
8398
8399     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8400     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8401
8402     ShowWindow(hwnd, SW_SHOW);
8403     UpdateWindow(hwnd);
8404     SetFocus(0);
8405     flush_sequence();
8406
8407     SetFocus(hwnd);
8408     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8409
8410     SetFocus(0);
8411     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8412
8413     SetFocus(0);
8414     ReleaseCapture();
8415     flush_sequence();
8416
8417     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8418     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8419
8420     SetFocus(0);
8421     ReleaseCapture();
8422     flush_sequence();
8423
8424     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8425     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8426
8427     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8428     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8429
8430     DestroyWindow(hwnd);
8431
8432     /* test multiline edit */
8433     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8434                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8435     ok(hwnd != 0, "Failed to create edit window\n");
8436
8437     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8438     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8439        "wrong dlg_code %08x\n", dlg_code);
8440
8441     ShowWindow(hwnd, SW_SHOW);
8442     UpdateWindow(hwnd);
8443     SetFocus(0);
8444     flush_sequence();
8445
8446     SetFocus(hwnd);
8447     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8448
8449     SetFocus(0);
8450     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8451
8452     SetFocus(0);
8453     ReleaseCapture();
8454     flush_sequence();
8455
8456     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8457     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8458
8459     SetFocus(0);
8460     ReleaseCapture();
8461     flush_sequence();
8462
8463     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8464     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8465
8466     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8467     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8468
8469     DestroyWindow(hwnd);
8470     DestroyWindow(parent);
8471
8472     log_all_parent_messages--;
8473 }
8474
8475 /**************************** End of Edit test ******************************/
8476
8477 static const struct message WmKeyDownSkippedSeq[] =
8478 {
8479     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8480     { 0 }
8481 };
8482 static const struct message WmKeyUpSkippedSeq[] =
8483 {
8484     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8485     { 0 }
8486 };
8487
8488 #define EV_START_STOP 0
8489 #define EV_SENDMSG 1
8490 #define EV_ACK 2
8491
8492 struct peekmsg_info
8493 {
8494     HWND  hwnd;
8495     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8496 };
8497
8498 static DWORD CALLBACK send_msg_thread_2(void *param)
8499 {
8500     DWORD ret;
8501     struct peekmsg_info *info = param;
8502
8503     trace("thread: waiting for start\n");
8504     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8505     trace("thread: looping\n");
8506
8507     while (1)
8508     {
8509         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8510
8511         switch (ret)
8512         {
8513         case WAIT_OBJECT_0 + EV_START_STOP:
8514             trace("thread: exiting\n");
8515             return 0;
8516
8517         case WAIT_OBJECT_0 + EV_SENDMSG:
8518             trace("thread: sending message\n");
8519             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8520             SetEvent(info->hevent[EV_ACK]);
8521             break;
8522
8523         default:
8524             trace("unexpected return: %04x\n", ret);
8525             assert(0);
8526             break;
8527         }
8528     }
8529     return 0;
8530 }
8531
8532 static void test_PeekMessage(void)
8533 {
8534     MSG msg;
8535     HANDLE hthread;
8536     DWORD tid, qstatus;
8537     UINT qs_all_input = QS_ALLINPUT;
8538     UINT qs_input = QS_INPUT;
8539     BOOL ret;
8540     struct peekmsg_info info;
8541
8542     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8543                               100, 100, 200, 200, 0, 0, 0, NULL);
8544     assert(info.hwnd);
8545     ShowWindow(info.hwnd, SW_SHOW);
8546     UpdateWindow(info.hwnd);
8547     SetFocus(info.hwnd);
8548
8549     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8550     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8551     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8552
8553     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8554     Sleep(100);
8555
8556     trace("signalling to start looping\n");
8557     SetEvent(info.hevent[EV_START_STOP]);
8558
8559     flush_events();
8560     flush_sequence();
8561
8562     SetLastError(0xdeadbeef);
8563     qstatus = GetQueueStatus(qs_all_input);
8564     if (GetLastError() == ERROR_INVALID_FLAGS)
8565     {
8566         trace("QS_RAWINPUT not supported on this platform\n");
8567         qs_all_input &= ~QS_RAWINPUT;
8568         qs_input &= ~QS_RAWINPUT;
8569     }
8570     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8571
8572     trace("signalling to send message\n");
8573     SetEvent(info.hevent[EV_SENDMSG]);
8574     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8575
8576     /* pass invalid QS_xxxx flags */
8577     SetLastError(0xdeadbeef);
8578     qstatus = GetQueueStatus(0xffffffff);
8579     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8580     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8581
8582     qstatus = GetQueueStatus(qs_all_input);
8583     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8584        "wrong qstatus %08x\n", qstatus);
8585
8586     msg.message = 0;
8587     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8588     ok(!ret,
8589        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8590         msg.message);
8591     ok_sequence(WmUser, "WmUser", FALSE);
8592
8593     qstatus = GetQueueStatus(qs_all_input);
8594     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8595
8596     keybd_event('N', 0, 0, 0);
8597     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8598     qstatus = GetQueueStatus(qs_all_input);
8599     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8600        "wrong qstatus %08x\n", qstatus);
8601
8602     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8603     qstatus = GetQueueStatus(qs_all_input);
8604     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8605        "wrong qstatus %08x\n", qstatus);
8606
8607     InvalidateRect(info.hwnd, NULL, FALSE);
8608     qstatus = GetQueueStatus(qs_all_input);
8609     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8610        "wrong qstatus %08x\n", qstatus);
8611
8612     trace("signalling to send message\n");
8613     SetEvent(info.hevent[EV_SENDMSG]);
8614     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8615
8616     qstatus = GetQueueStatus(qs_all_input);
8617     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8618        "wrong qstatus %08x\n", qstatus);
8619
8620     msg.message = 0;
8621     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8622     ok(!ret,
8623        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8624         msg.message);
8625     ok_sequence(WmUser, "WmUser", FALSE);
8626
8627     qstatus = GetQueueStatus(qs_all_input);
8628     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8629        "wrong qstatus %08x\n", qstatus);
8630
8631     trace("signalling to send message\n");
8632     SetEvent(info.hevent[EV_SENDMSG]);
8633     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8634
8635     qstatus = GetQueueStatus(qs_all_input);
8636     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8637        "wrong qstatus %08x\n", qstatus);
8638
8639     msg.message = 0;
8640     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8641     ok(!ret,
8642        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8643         msg.message);
8644     ok_sequence(WmUser, "WmUser", FALSE);
8645
8646     qstatus = GetQueueStatus(qs_all_input);
8647     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8648        "wrong qstatus %08x\n", qstatus);
8649
8650     msg.message = 0;
8651     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8652     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8653        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8654        ret, msg.message, msg.wParam);
8655     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8656
8657     qstatus = GetQueueStatus(qs_all_input);
8658     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8659        "wrong qstatus %08x\n", qstatus);
8660
8661     msg.message = 0;
8662     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8663     ok(!ret,
8664        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8665         msg.message);
8666     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8667
8668     qstatus = GetQueueStatus(qs_all_input);
8669     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8670        "wrong qstatus %08x\n", qstatus);
8671
8672     msg.message = 0;
8673     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8674     ok(ret && msg.message == WM_PAINT,
8675        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8676     DispatchMessageA(&msg);
8677     ok_sequence(WmPaint, "WmPaint", FALSE);
8678
8679     qstatus = GetQueueStatus(qs_all_input);
8680     ok(qstatus == MAKELONG(0, QS_KEY),
8681        "wrong qstatus %08x\n", qstatus);
8682
8683     msg.message = 0;
8684     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8685     ok(!ret,
8686        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8687         msg.message);
8688     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8689
8690     qstatus = GetQueueStatus(qs_all_input);
8691     ok(qstatus == MAKELONG(0, QS_KEY),
8692        "wrong qstatus %08x\n", qstatus);
8693
8694     trace("signalling to send message\n");
8695     SetEvent(info.hevent[EV_SENDMSG]);
8696     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8697
8698     qstatus = GetQueueStatus(qs_all_input);
8699     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8700        "wrong qstatus %08x\n", qstatus);
8701
8702     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8703
8704     qstatus = GetQueueStatus(qs_all_input);
8705     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8706        "wrong qstatus %08x\n", qstatus);
8707
8708     msg.message = 0;
8709     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8710     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8711        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8712        ret, msg.message, msg.wParam);
8713     ok_sequence(WmUser, "WmUser", FALSE);
8714
8715     qstatus = GetQueueStatus(qs_all_input);
8716     ok(qstatus == MAKELONG(0, QS_KEY),
8717        "wrong qstatus %08x\n", qstatus);
8718
8719     msg.message = 0;
8720     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8721     ok(!ret,
8722        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8723         msg.message);
8724     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8725
8726     qstatus = GetQueueStatus(qs_all_input);
8727     ok(qstatus == MAKELONG(0, QS_KEY),
8728        "wrong qstatus %08x\n", qstatus);
8729
8730     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8731
8732     qstatus = GetQueueStatus(qs_all_input);
8733     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8734        "wrong qstatus %08x\n", qstatus);
8735
8736     trace("signalling to send message\n");
8737     SetEvent(info.hevent[EV_SENDMSG]);
8738     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8739
8740     qstatus = GetQueueStatus(qs_all_input);
8741     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8742        "wrong qstatus %08x\n", qstatus);
8743
8744     msg.message = 0;
8745     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8746     ok(!ret,
8747        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8748         msg.message);
8749     ok_sequence(WmUser, "WmUser", FALSE);
8750
8751     qstatus = GetQueueStatus(qs_all_input);
8752     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8753        "wrong qstatus %08x\n", qstatus);
8754
8755     msg.message = 0;
8756     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8757         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8758     else /* workaround for a missing QS_RAWINPUT support */
8759         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8760     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8761        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8762        ret, msg.message, msg.wParam);
8763     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8764
8765     qstatus = GetQueueStatus(qs_all_input);
8766     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8767        "wrong qstatus %08x\n", qstatus);
8768
8769     msg.message = 0;
8770     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8771         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8772     else /* workaround for a missing QS_RAWINPUT support */
8773         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8774     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8775        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8776        ret, msg.message, msg.wParam);
8777     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8778
8779     qstatus = GetQueueStatus(qs_all_input);
8780     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8781        "wrong qstatus %08x\n", qstatus);
8782
8783     msg.message = 0;
8784     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8785     ok(!ret,
8786        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8787         msg.message);
8788     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8789
8790     qstatus = GetQueueStatus(qs_all_input);
8791     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8792        "wrong qstatus %08x\n", qstatus);
8793
8794     msg.message = 0;
8795     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8796     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8797        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8798        ret, msg.message, msg.wParam);
8799     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8800
8801     qstatus = GetQueueStatus(qs_all_input);
8802     ok(qstatus == 0,
8803        "wrong qstatus %08x\n", qstatus);
8804
8805     msg.message = 0;
8806     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8807     ok(!ret,
8808        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8809         msg.message);
8810     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8811
8812     qstatus = GetQueueStatus(qs_all_input);
8813     ok(qstatus == 0,
8814        "wrong qstatus %08x\n", qstatus);
8815
8816     /* test whether presence of the quit flag in the queue affects
8817      * the queue state
8818      */
8819     PostQuitMessage(0x1234abcd);
8820
8821     qstatus = GetQueueStatus(qs_all_input);
8822     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8823        "wrong qstatus %08x\n", qstatus);
8824
8825     PostMessageA(info.hwnd, WM_USER, 0, 0);
8826
8827     qstatus = GetQueueStatus(qs_all_input);
8828     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8829        "wrong qstatus %08x\n", qstatus);
8830
8831     msg.message = 0;
8832     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8833     ok(ret && msg.message == WM_USER,
8834        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8835     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8836
8837     qstatus = GetQueueStatus(qs_all_input);
8838     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8839        "wrong qstatus %08x\n", qstatus);
8840
8841     msg.message = 0;
8842     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8843     ok(ret && msg.message == WM_QUIT,
8844        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8845     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8846     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8847     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8848
8849     qstatus = GetQueueStatus(qs_all_input);
8850 todo_wine {
8851     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8852        "wrong qstatus %08x\n", qstatus);
8853 }
8854
8855     msg.message = 0;
8856     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8857     ok(!ret,
8858        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8859         msg.message);
8860     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8861
8862     qstatus = GetQueueStatus(qs_all_input);
8863     ok(qstatus == 0,
8864        "wrong qstatus %08x\n", qstatus);
8865
8866     trace("signalling to exit\n");
8867     SetEvent(info.hevent[EV_START_STOP]);
8868
8869     WaitForSingleObject(hthread, INFINITE);
8870
8871     CloseHandle(hthread);
8872     CloseHandle(info.hevent[0]);
8873     CloseHandle(info.hevent[1]);
8874     CloseHandle(info.hevent[2]);
8875
8876     DestroyWindow(info.hwnd);
8877 }
8878
8879 static void wait_move_event(HWND hwnd, int x, int y)
8880 {
8881     MSG msg;
8882     DWORD time;
8883     BOOL  ret;
8884     int go = 0;
8885
8886     time = GetTickCount();
8887     while (GetTickCount() - time < 200 && !go) {
8888         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8889         go  = ret && msg.pt.x > x && msg.pt.y > y;
8890     }
8891 }
8892
8893 #define STEP 20
8894 static void test_PeekMessage2(void)
8895 {
8896     HWND hwnd;
8897     BOOL ret;
8898     MSG msg;
8899     UINT message;
8900     DWORD time1, time2, time3;
8901     int x1, y1, x2, y2, x3, y3;
8902     POINT pos;
8903
8904     time1 = time2 = time3 = 0;
8905     x1 = y1 = x2 = y2 = x3 = y3 = 0;
8906
8907     /* Initialise window and make sure it is ready for events */
8908     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
8909                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
8910     assert(hwnd);
8911     trace("Window for test_PeekMessage2 %p\n", hwnd);
8912     ShowWindow(hwnd, SW_SHOW);
8913     UpdateWindow(hwnd);
8914     SetFocus(hwnd);
8915     GetCursorPos(&pos);
8916     SetCursorPos(100, 100);
8917     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
8918     flush_events();
8919
8920     /* Do initial mousemove, wait until we can see it
8921        and then do our test peek with PM_NOREMOVE. */
8922     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8923     wait_move_event(hwnd, 80, 80);
8924
8925     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8926     ok(ret, "no message available\n");
8927     if (ret) {
8928         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8929         message = msg.message;
8930         time1 = msg.time;
8931         x1 = msg.pt.x;
8932         y1 = msg.pt.y;
8933         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8934     }
8935
8936     /* Allow time to advance a bit, and then simulate the user moving their
8937      * mouse around. After that we peek again with PM_NOREMOVE.
8938      * Although the previous mousemove message was never removed, the
8939      * mousemove we now peek should reflect the recent mouse movements
8940      * because the input queue will merge the move events. */
8941     Sleep(2);
8942     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8943     wait_move_event(hwnd, x1, y1);
8944
8945     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8946     ok(ret, "no message available\n");
8947     if (ret) {
8948         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8949         message = msg.message;
8950         time2 = msg.time;
8951         x2 = msg.pt.x;
8952         y2 = msg.pt.y;
8953         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8954         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
8955         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
8956     }
8957
8958     /* Have another go, to drive the point home */
8959     Sleep(2);
8960     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8961     wait_move_event(hwnd, x2, y2);
8962
8963     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8964     ok(ret, "no message available\n");
8965     if (ret) {
8966         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8967         message = msg.message;
8968         time3 = msg.time;
8969         x3 = msg.pt.x;
8970         y3 = msg.pt.y;
8971         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8972         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
8973         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
8974     }
8975
8976     DestroyWindow(hwnd);
8977     SetCursorPos(pos.x, pos.y);
8978     flush_events();
8979 }
8980
8981 static void test_quit_message(void)
8982 {
8983     MSG msg;
8984     BOOL ret;
8985
8986     /* test using PostQuitMessage */
8987     PostQuitMessage(0xbeef);
8988
8989     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8990     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8991     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8992     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8993
8994     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8995     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8996
8997     ret = GetMessage(&msg, NULL, 0, 0);
8998     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8999     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9000
9001     /* note: WM_QUIT message received after WM_USER message */
9002     ret = GetMessage(&msg, NULL, 0, 0);
9003     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9004     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9005     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9006
9007     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9008     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9009
9010     /* now test with PostThreadMessage - different behaviour! */
9011     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9012
9013     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9014     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9015     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9016     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9017
9018     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9019     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9020
9021     /* note: we receive the WM_QUIT message first this time */
9022     ret = GetMessage(&msg, NULL, 0, 0);
9023     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9024     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9025     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9026
9027     ret = GetMessage(&msg, NULL, 0, 0);
9028     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9029     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9030 }
9031
9032 static const struct message WmMouseHoverSeq[] = {
9033     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9034     { WM_MOUSEACTIVATE, sent|optional },
9035     { WM_TIMER, sent|optional }, /* XP sends it */
9036     { WM_SYSTIMER, sent },
9037     { WM_MOUSEHOVER, sent|wparam, 0 },
9038     { 0 }
9039 };
9040
9041 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9042 {
9043     MSG msg;
9044     DWORD start_ticks, end_ticks;
9045
9046     start_ticks = GetTickCount();
9047     /* add some deviation (5%) to cover not expected delays */
9048     start_ticks += timeout / 20;
9049
9050     do
9051     {
9052         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9053         {
9054             /* Timer proc messages are not dispatched to the window proc,
9055              * and therefore not logged.
9056              */
9057             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9058             {
9059                 struct message s_msg;
9060
9061                 s_msg.message = msg.message;
9062                 s_msg.flags = sent|wparam|lparam;
9063                 s_msg.wParam = msg.wParam;
9064                 s_msg.lParam = msg.lParam;
9065                 add_message(&s_msg);
9066             }
9067             DispatchMessage(&msg);
9068         }
9069
9070         end_ticks = GetTickCount();
9071
9072         /* inject WM_MOUSEMOVE to see how it changes tracking */
9073         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9074         {
9075             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9076             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9077
9078             inject_mouse_move = FALSE;
9079         }
9080     } while (start_ticks + timeout >= end_ticks);
9081 }
9082
9083 static void test_TrackMouseEvent(void)
9084 {
9085     TRACKMOUSEEVENT tme;
9086     BOOL ret;
9087     HWND hwnd, hchild;
9088     RECT rc_parent, rc_child;
9089     UINT default_hover_time, hover_width = 0, hover_height = 0;
9090
9091 #define track_hover(track_hwnd, track_hover_time) \
9092     tme.cbSize = sizeof(tme); \
9093     tme.dwFlags = TME_HOVER; \
9094     tme.hwndTrack = track_hwnd; \
9095     tme.dwHoverTime = track_hover_time; \
9096     SetLastError(0xdeadbeef); \
9097     ret = pTrackMouseEvent(&tme); \
9098     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9099
9100 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9101     tme.cbSize = sizeof(tme); \
9102     tme.dwFlags = TME_QUERY; \
9103     tme.hwndTrack = (HWND)0xdeadbeef; \
9104     tme.dwHoverTime = 0xdeadbeef; \
9105     SetLastError(0xdeadbeef); \
9106     ret = pTrackMouseEvent(&tme); \
9107     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9108     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9109     ok(tme.dwFlags == (expected_track_flags), \
9110        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9111     ok(tme.hwndTrack == (expected_track_hwnd), \
9112        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9113     ok(tme.dwHoverTime == (expected_hover_time), \
9114        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9115
9116 #define track_hover_cancel(track_hwnd) \
9117     tme.cbSize = sizeof(tme); \
9118     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9119     tme.hwndTrack = track_hwnd; \
9120     tme.dwHoverTime = 0xdeadbeef; \
9121     SetLastError(0xdeadbeef); \
9122     ret = pTrackMouseEvent(&tme); \
9123     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9124
9125     default_hover_time = 0xdeadbeef;
9126     SetLastError(0xdeadbeef);
9127     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9128     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9129     if (!ret) default_hover_time = 400;
9130     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9131
9132     SetLastError(0xdeadbeef);
9133     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9134     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9135     if (!ret) hover_width = 4;
9136     SetLastError(0xdeadbeef);
9137     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9138     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9139     if (!ret) hover_height = 4;
9140     trace("hover rect is %u x %d\n", hover_width, hover_height);
9141
9142     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9143                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9144                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9145                           NULL, NULL, 0);
9146     assert(hwnd);
9147
9148     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9149                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9150                           50, 50, 200, 200, hwnd,
9151                           NULL, NULL, 0);
9152     assert(hchild);
9153
9154     flush_events();
9155     flush_sequence();
9156
9157     tme.cbSize = 0;
9158     tme.dwFlags = TME_QUERY;
9159     tme.hwndTrack = (HWND)0xdeadbeef;
9160     tme.dwHoverTime = 0xdeadbeef;
9161     SetLastError(0xdeadbeef);
9162     ret = pTrackMouseEvent(&tme);
9163     ok(!ret, "TrackMouseEvent should fail\n");
9164     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
9165
9166     tme.cbSize = sizeof(tme);
9167     tme.dwFlags = TME_HOVER;
9168     tme.hwndTrack = (HWND)0xdeadbeef;
9169     tme.dwHoverTime = 0xdeadbeef;
9170     SetLastError(0xdeadbeef);
9171     ret = pTrackMouseEvent(&tme);
9172     ok(!ret, "TrackMouseEvent should fail\n");
9173     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9174
9175     tme.cbSize = sizeof(tme);
9176     tme.dwFlags = TME_HOVER | TME_CANCEL;
9177     tme.hwndTrack = (HWND)0xdeadbeef;
9178     tme.dwHoverTime = 0xdeadbeef;
9179     SetLastError(0xdeadbeef);
9180     ret = pTrackMouseEvent(&tme);
9181     ok(!ret, "TrackMouseEvent should fail\n");
9182     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9183
9184     GetWindowRect(hwnd, &rc_parent);
9185     GetWindowRect(hchild, &rc_child);
9186     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9187
9188     /* Process messages so that the system updates its internal current
9189      * window and hittest, otherwise TrackMouseEvent calls don't have any
9190      * effect.
9191      */
9192     flush_events();
9193     flush_sequence();
9194
9195     track_query(0, NULL, 0);
9196     track_hover(hchild, 0);
9197     track_query(0, NULL, 0);
9198
9199     flush_events();
9200     flush_sequence();
9201
9202     track_hover(hwnd, 0);
9203     track_query(TME_HOVER, hwnd, default_hover_time);
9204
9205     pump_msg_loop_timeout(default_hover_time, FALSE);
9206     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9207
9208     track_query(0, NULL, 0);
9209
9210     track_hover(hwnd, HOVER_DEFAULT);
9211     track_query(TME_HOVER, hwnd, default_hover_time);
9212
9213     Sleep(default_hover_time / 2);
9214     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9215     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9216
9217     track_query(TME_HOVER, hwnd, default_hover_time);
9218
9219     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9220     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9221
9222     track_query(0, NULL, 0);
9223
9224     track_hover(hwnd, HOVER_DEFAULT);
9225     track_query(TME_HOVER, hwnd, default_hover_time);
9226
9227     pump_msg_loop_timeout(default_hover_time, TRUE);
9228     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9229
9230     track_query(0, NULL, 0);
9231
9232     track_hover(hwnd, HOVER_DEFAULT);
9233     track_query(TME_HOVER, hwnd, default_hover_time);
9234     track_hover_cancel(hwnd);
9235
9236     DestroyWindow(hwnd);
9237
9238 #undef track_hover
9239 #undef track_query
9240 #undef track_hover_cancel
9241 }
9242
9243
9244 static const struct message WmSetWindowRgn[] = {
9245     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9246     { WM_NCCALCSIZE, sent|wparam, 1 },
9247     { WM_NCPAINT, sent }, /* wparam != 1 */
9248     { WM_GETTEXT, sent|defwinproc|optional },
9249     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9250     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9251     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9252     { 0 }
9253 };
9254
9255 static const struct message WmSetWindowRgn_no_redraw[] = {
9256     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9257     { WM_NCCALCSIZE, sent|wparam, 1 },
9258     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9259     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9260     { 0 }
9261 };
9262
9263 static const struct message WmSetWindowRgn_clear[] = {
9264     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9265     { WM_NCCALCSIZE, sent|wparam, 1 },
9266     { WM_NCPAINT, sent }, /* wparam != 1 */
9267     { WM_GETTEXT, sent|defwinproc|optional },
9268     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9269     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9270     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9271     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9272     { WM_GETTEXT, sent|defwinproc|optional },
9273     { WM_ERASEBKGND, sent|optional },
9274     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9275     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9276     { 0 }
9277 };
9278
9279 static void test_SetWindowRgn(void)
9280 {
9281     HRGN hrgn;
9282     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9283                                 100, 100, 200, 200, 0, 0, 0, NULL);
9284     ok( hwnd != 0, "Failed to create overlapped window\n" );
9285
9286     ShowWindow( hwnd, SW_SHOW );
9287     UpdateWindow( hwnd );
9288     flush_events();
9289     flush_sequence();
9290
9291     trace("testing SetWindowRgn\n");
9292     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9293     SetWindowRgn( hwnd, hrgn, TRUE );
9294     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9295
9296     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9297     SetWindowRgn( hwnd, hrgn, FALSE );
9298     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9299
9300     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9301     SetWindowRgn( hwnd, hrgn, TRUE );
9302     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9303
9304     SetWindowRgn( hwnd, 0, TRUE );
9305     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9306
9307     DestroyWindow( hwnd );
9308 }
9309
9310 /*************************** ShowWindow() test ******************************/
9311 static const struct message WmShowNormal[] = {
9312     { WM_SHOWWINDOW, sent|wparam, 1 },
9313     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9314     { HCBT_ACTIVATE, hook },
9315     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9316     { HCBT_SETFOCUS, hook },
9317     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9318     { 0 }
9319 };
9320 static const struct message WmShow[] = {
9321     { WM_SHOWWINDOW, sent|wparam, 1 },
9322     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9323     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9324     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9325     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9326     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9327     { 0 }
9328 };
9329 static const struct message WmShowNoActivate_1[] = {
9330     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9331     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9332     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9333     { WM_MOVE, sent|defwinproc },
9334     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9335     { 0 }
9336 };
9337 static const struct message WmShowNoActivate_2[] = {
9338     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9339     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9340     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9341     { WM_MOVE, sent|defwinproc },
9342     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9343     { HCBT_SETFOCUS, hook|optional },
9344     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9345     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9346     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9347     { 0 }
9348 };
9349 static const struct message WmShowNA_1[] = {
9350     { WM_SHOWWINDOW, sent|wparam, 1 },
9351     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9352     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9353     { 0 }
9354 };
9355 static const struct message WmShowNA_2[] = {
9356     { WM_SHOWWINDOW, sent|wparam, 1 },
9357     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9358     { 0 }
9359 };
9360 static const struct message WmRestore_1[] = {
9361     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9362     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9363     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9364     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9365     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9366     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9367     { WM_MOVE, sent|defwinproc },
9368     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9369     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9370     { 0 }
9371 };
9372 static const struct message WmRestore_2[] = {
9373     { WM_SHOWWINDOW, sent|wparam, 1 },
9374     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9375     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9376     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9377     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9378     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9379     { 0 }
9380 };
9381 static const struct message WmRestore_3[] = {
9382     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9383     { WM_GETMINMAXINFO, sent },
9384     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9385     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9386     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9387     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9388     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9389     { WM_MOVE, sent|defwinproc },
9390     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9391     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9392     { 0 }
9393 };
9394 static const struct message WmRestore_4[] = {
9395     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9397     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9398     { WM_MOVE, sent|defwinproc },
9399     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9400     { 0 }
9401 };
9402 static const struct message WmRestore_5[] = {
9403     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9404     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9405     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9406     { WM_MOVE, sent|defwinproc },
9407     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9408     { 0 }
9409 };
9410 static const struct message WmHide_1[] = {
9411     { WM_SHOWWINDOW, sent|wparam, 0 },
9412     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9413     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9414     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9415     { 0 }
9416 };
9417 static const struct message WmHide_2[] = {
9418     { WM_SHOWWINDOW, sent|wparam, 0 },
9419     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9420     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9421     { 0 }
9422 };
9423 static const struct message WmHide_3[] = {
9424     { WM_SHOWWINDOW, sent|wparam, 0 },
9425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9426     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9427     { HCBT_SETFOCUS, hook },
9428     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9429     { 0 }
9430 };
9431 static const struct message WmShowMinimized_1[] = {
9432     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9433     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9434     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9435     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9436     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9437     { WM_MOVE, sent|defwinproc },
9438     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9439     { 0 }
9440 };
9441 static const struct message WmMinimize_1[] = {
9442     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9443     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9444     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9445     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9446     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9447     { WM_MOVE, sent|defwinproc },
9448     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9449     { 0 }
9450 };
9451 static const struct message WmMinimize_2[] = {
9452     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9453     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9454     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9455     { WM_MOVE, sent|defwinproc },
9456     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9457     { 0 }
9458 };
9459 static const struct message WmMinimize_3[] = {
9460     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9461     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9462     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9463     { WM_MOVE, sent|defwinproc },
9464     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9465     { 0 }
9466 };
9467 static const struct message WmShowMinNoActivate[] = {
9468     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9469     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9470     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9471     { 0 }
9472 };
9473 static const struct message WmMinMax_1[] = {
9474     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9475     { 0 }
9476 };
9477 static const struct message WmMinMax_2[] = {
9478     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9479     { 0 }
9480 };
9481 static const struct message WmMinMax_3[] = {
9482     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9483     { 0 }
9484 };
9485 static const struct message WmMinMax_4[] = {
9486     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9487     { 0 }
9488 };
9489 static const struct message WmShowMaximized_1[] = {
9490     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9491     { WM_GETMINMAXINFO, sent },
9492     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9493     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9494     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9495     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9496     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9497     { WM_MOVE, sent|defwinproc },
9498     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9499     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9500     { 0 }
9501 };
9502 static const struct message WmShowMaximized_2[] = {
9503     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9504     { WM_GETMINMAXINFO, sent },
9505     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
9506     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9507     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9508     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9509     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9510     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9511     { WM_MOVE, sent|defwinproc },
9512     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9513     { HCBT_SETFOCUS, hook },
9514     { 0 }
9515 };
9516 static const struct message WmShowMaximized_3[] = {
9517     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9518     { WM_GETMINMAXINFO, sent },
9519     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9520     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9521     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9522     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9523     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9524     { WM_MOVE, sent|defwinproc },
9525     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9526     { 0 }
9527 };
9528
9529 static void test_ShowWindow(void)
9530 {
9531     /* ShowWindow commands in random order */
9532     static const struct
9533     {
9534         INT cmd; /* ShowWindow command */
9535         LPARAM ret; /* ShowWindow return value */
9536         DWORD style; /* window style after the command */
9537         const struct message *msg; /* message sequence the command produces */
9538         BOOL todo_msg; /* message sequence doesn't match what Wine does */
9539     } sw[] =
9540     {
9541 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9542 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9543 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9544 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9545 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9546 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9547 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9548 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9549 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9550 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9551 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9552 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9553 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9554 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9555 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9556 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9557 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9558 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9559 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9560 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9561 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9562 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9563 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9564 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9565 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9566 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9567 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9568 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9569 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9570 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9571 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9572 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
9573 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9574 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
9575 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
9576 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9577 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9578 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9579 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9580 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
9581 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9582 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9583 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9584 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9585 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9586 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9587 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9588 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9589 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9590 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9591 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9592 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9593 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9594 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
9595 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9596 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9597 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9598     };
9599     HWND hwnd;
9600     DWORD style;
9601     LPARAM ret;
9602     INT i;
9603
9604 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9605     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9606                           120, 120, 90, 90,
9607                           0, 0, 0, NULL);
9608     assert(hwnd);
9609
9610     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9611     ok(style == 0, "expected style 0, got %08x\n", style);
9612
9613     flush_events();
9614     flush_sequence();
9615
9616     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9617     {
9618         static const char * const sw_cmd_name[13] =
9619         {
9620             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9621             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9622             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9623             "SW_NORMALNA" /* 0xCC */
9624         };
9625         char comment[64];
9626         INT idx; /* index into the above array of names */
9627
9628         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9629
9630         style = GetWindowLong(hwnd, GWL_STYLE);
9631         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9632         ret = ShowWindow(hwnd, sw[i].cmd);
9633         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9634         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9635         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9636
9637         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9638         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9639
9640         flush_events();
9641         flush_sequence();
9642     }
9643
9644     DestroyWindow(hwnd);
9645 }
9646
9647 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9648 {
9649     struct message msg;
9650
9651     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9652
9653     switch (message)
9654     {
9655     case WM_WINDOWPOSCHANGING:
9656     case WM_WINDOWPOSCHANGED:
9657     {
9658         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9659
9660         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9661         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9662               winpos->hwnd, winpos->hwndInsertAfter,
9663               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9664         dump_winpos_flags(winpos->flags);
9665
9666         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9667          * in the high word for internal purposes
9668          */
9669         wParam = winpos->flags & 0xffff;
9670         /* We are not interested in the flags that don't match under XP and Win9x */
9671         wParam &= ~(SWP_NOZORDER);
9672         break;
9673     }
9674
9675     /* explicitly ignore WM_GETICON message */
9676     case WM_GETICON:
9677         return 0;
9678     }
9679
9680     msg.message = message;
9681     msg.flags = sent|wparam|lparam;
9682     msg.wParam = wParam;
9683     msg.lParam = lParam;
9684     add_message(&msg);
9685
9686     /* calling DefDlgProc leads to a recursion under XP */
9687
9688     switch (message)
9689     {
9690     case WM_INITDIALOG:
9691     case WM_GETDLGCODE:
9692         return 0;
9693     }
9694     return 1;
9695 }
9696
9697 static const struct message WmDefDlgSetFocus_1[] = {
9698     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9699     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9700     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9701     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9702     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9703     { HCBT_SETFOCUS, hook },
9704     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9705     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9706     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9707     { WM_SETFOCUS, sent|wparam, 0 },
9708     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9709     { WM_CTLCOLOREDIT, sent },
9710     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9711     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9712     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9713     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9714     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9715     { 0 }
9716 };
9717 static const struct message WmDefDlgSetFocus_2[] = {
9718     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9719     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9720     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9721     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9722     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9723     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9724     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9725     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9726     { 0 }
9727 };
9728 /* Creation of a dialog */
9729 static const struct message WmCreateDialogParamSeq_1[] = {
9730     { HCBT_CREATEWND, hook },
9731     { WM_NCCREATE, sent },
9732     { WM_NCCALCSIZE, sent|wparam, 0 },
9733     { WM_CREATE, sent },
9734     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9735     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9736     { WM_MOVE, sent },
9737     { WM_SETFONT, sent },
9738     { WM_INITDIALOG, sent },
9739     { WM_CHANGEUISTATE, sent|optional },
9740     { 0 }
9741 };
9742 /* Creation of a dialog */
9743 static const struct message WmCreateDialogParamSeq_2[] = {
9744     { HCBT_CREATEWND, hook },
9745     { WM_NCCREATE, sent },
9746     { WM_NCCALCSIZE, sent|wparam, 0 },
9747     { WM_CREATE, sent },
9748     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9749     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9750     { WM_MOVE, sent },
9751     { WM_CHANGEUISTATE, sent|optional },
9752     { 0 }
9753 };
9754
9755 static void test_dialog_messages(void)
9756 {
9757     WNDCLASS cls;
9758     HWND hdlg, hedit1, hedit2, hfocus;
9759     LRESULT ret;
9760
9761 #define set_selection(hctl, start, end) \
9762     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9763     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9764
9765 #define check_selection(hctl, start, end) \
9766     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9767     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9768
9769     subclass_edit();
9770
9771     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9772                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9773                           0, 0, 100, 100, 0, 0, 0, NULL);
9774     ok(hdlg != 0, "Failed to create custom dialog window\n");
9775
9776     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9777                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9778                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9779     ok(hedit1 != 0, "Failed to create edit control\n");
9780     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9781                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9782                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9783     ok(hedit2 != 0, "Failed to create edit control\n");
9784
9785     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9786     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9787
9788     hfocus = GetFocus();
9789     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9790
9791     SetFocus(hedit2);
9792     hfocus = GetFocus();
9793     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9794
9795     check_selection(hedit1, 0, 0);
9796     check_selection(hedit2, 0, 0);
9797
9798     set_selection(hedit2, 0, -1);
9799     check_selection(hedit2, 0, 3);
9800
9801     SetFocus(0);
9802     hfocus = GetFocus();
9803     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9804
9805     flush_sequence();
9806     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9807     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9808     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9809
9810     hfocus = GetFocus();
9811     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9812
9813     check_selection(hedit1, 0, 5);
9814     check_selection(hedit2, 0, 3);
9815
9816     flush_sequence();
9817     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9818     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9819     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9820
9821     hfocus = GetFocus();
9822     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9823
9824     check_selection(hedit1, 0, 5);
9825     check_selection(hedit2, 0, 3);
9826
9827     EndDialog(hdlg, 0);
9828     DestroyWindow(hedit1);
9829     DestroyWindow(hedit2);
9830     DestroyWindow(hdlg);
9831     flush_sequence();
9832
9833 #undef set_selection
9834 #undef check_selection
9835
9836     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9837     cls.lpszClassName = "MyDialogClass";
9838     cls.hInstance = GetModuleHandle(0);
9839     /* need a cast since a dlgproc is used as a wndproc */
9840     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9841     if (!RegisterClass(&cls)) assert(0);
9842
9843     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9844     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9845     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9846     EndDialog(hdlg, 0);
9847     DestroyWindow(hdlg);
9848     flush_sequence();
9849
9850     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9851     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9852     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9853     EndDialog(hdlg, 0);
9854     DestroyWindow(hdlg);
9855     flush_sequence();
9856
9857     UnregisterClass(cls.lpszClassName, cls.hInstance);
9858 }
9859
9860 static void test_nullCallback(void)
9861 {
9862     HWND hwnd;
9863
9864     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9865                            100, 100, 200, 200, 0, 0, 0, NULL);
9866     ok (hwnd != 0, "Failed to create overlapped window\n");
9867
9868     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9869     flush_events();
9870     DestroyWindow(hwnd);
9871 }
9872
9873 static const struct message SetForegroundWindowSeq[] =
9874 {
9875     { WM_NCACTIVATE, sent|wparam, 0 },
9876     { WM_GETTEXT, sent|defwinproc|optional },
9877     { WM_ACTIVATE, sent|wparam, 0 },
9878     { WM_ACTIVATEAPP, sent|wparam, 0 },
9879     { WM_KILLFOCUS, sent },
9880     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9881     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
9882     { 0 }
9883 };
9884
9885 static void test_SetForegroundWindow(void)
9886 {
9887     HWND hwnd;
9888
9889     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9890                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9891                            100, 100, 200, 200, 0, 0, 0, NULL);
9892     ok (hwnd != 0, "Failed to create overlapped window\n");
9893     flush_sequence();
9894
9895     trace("SetForegroundWindow( 0 )\n");
9896     SetForegroundWindow( 0 );
9897     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9898     trace("SetForegroundWindow( GetDesktopWindow() )\n");
9899     SetForegroundWindow( GetDesktopWindow() );
9900     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9901                                         "foreground top level window", FALSE);
9902     trace("done\n");
9903
9904     DestroyWindow(hwnd);
9905 }
9906
9907 static void test_dbcs_wm_char(void)
9908 {
9909     BYTE dbch[2];
9910     WCHAR wch, bad_wch;
9911     HWND hwnd, hwnd2;
9912     MSG msg;
9913     DWORD time;
9914     POINT pt;
9915     DWORD_PTR res;
9916     CPINFOEXA cpinfo;
9917     UINT i, j, k;
9918     struct message wmCharSeq[2];
9919
9920     if (!pGetCPInfoExA)
9921     {
9922         skip("GetCPInfoExA is not available\n");
9923         return;
9924     }
9925
9926     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9927     if (cpinfo.MaxCharSize != 2)
9928     {
9929         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9930         return;
9931     }
9932
9933     dbch[0] = dbch[1] = 0;
9934     wch = 0;
9935     bad_wch = cpinfo.UnicodeDefaultChar;
9936     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9937         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9938             for (k = 128; k <= 255; k++)
9939             {
9940                 char str[2];
9941                 WCHAR wstr[2];
9942                 str[0] = j;
9943                 str[1] = k;
9944                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9945                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9946                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
9947                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9948                 {
9949                     dbch[0] = j;
9950                     dbch[1] = k;
9951                     wch = wstr[0];
9952                     break;
9953                 }
9954             }
9955
9956     if (!wch)
9957     {
9958         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9959         return;
9960     }
9961     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9962            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9963
9964     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9965                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9966     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9967                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9968     ok (hwnd != 0, "Failed to create overlapped window\n");
9969     ok (hwnd2 != 0, "Failed to create overlapped window\n");
9970     flush_sequence();
9971
9972     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9973     wmCharSeq[0].message = WM_CHAR;
9974     wmCharSeq[0].flags = sent|wparam;
9975     wmCharSeq[0].wParam = wch;
9976
9977     /* posted message */
9978     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9979     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9980     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9981     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9982     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9983     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9984     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9985
9986     /* posted thread message */
9987     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9988     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9989     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9990     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9991     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9992     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9993     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9994
9995     /* sent message */
9996     flush_sequence();
9997     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9998     ok_sequence( WmEmptySeq, "no messages", FALSE );
9999     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10000     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10001     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10002
10003     /* sent message with timeout */
10004     flush_sequence();
10005     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10006     ok_sequence( WmEmptySeq, "no messages", FALSE );
10007     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10008     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10009     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10010
10011     /* sent message with timeout and callback */
10012     flush_sequence();
10013     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10014     ok_sequence( WmEmptySeq, "no messages", FALSE );
10015     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10016     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10017     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10018
10019     /* sent message with callback */
10020     flush_sequence();
10021     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10022     ok_sequence( WmEmptySeq, "no messages", FALSE );
10023     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10024     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10025     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10026
10027     /* direct window proc call */
10028     flush_sequence();
10029     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10030     ok_sequence( WmEmptySeq, "no messages", FALSE );
10031     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10032     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10033
10034     /* dispatch message */
10035     msg.hwnd = hwnd;
10036     msg.message = WM_CHAR;
10037     msg.wParam = dbch[0];
10038     msg.lParam = 0;
10039     DispatchMessageA( &msg );
10040     ok_sequence( WmEmptySeq, "no messages", FALSE );
10041     msg.wParam = dbch[1];
10042     DispatchMessageA( &msg );
10043     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10044
10045     /* window handle is irrelevant */
10046     flush_sequence();
10047     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10048     ok_sequence( WmEmptySeq, "no messages", FALSE );
10049     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10050     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10051     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10052
10053     /* interleaved post and send */
10054     flush_sequence();
10055     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10056     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10057     ok_sequence( WmEmptySeq, "no messages", FALSE );
10058     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10059     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10060     ok_sequence( WmEmptySeq, "no messages", FALSE );
10061     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10062     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10063     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10064     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10065     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10066     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10067     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10068
10069     /* interleaved sent message and winproc */
10070     flush_sequence();
10071     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10072     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10073     ok_sequence( WmEmptySeq, "no messages", FALSE );
10074     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10075     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10076     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10077     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10078
10079     /* interleaved winproc and dispatch */
10080     msg.hwnd = hwnd;
10081     msg.message = WM_CHAR;
10082     msg.wParam = dbch[0];
10083     msg.lParam = 0;
10084     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10085     DispatchMessageA( &msg );
10086     ok_sequence( WmEmptySeq, "no messages", FALSE );
10087     msg.wParam = dbch[1];
10088     DispatchMessageA( &msg );
10089     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10090     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10091     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10092
10093     /* interleaved sends */
10094     flush_sequence();
10095     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10096     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10097     ok_sequence( WmEmptySeq, "no messages", FALSE );
10098     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10099     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10100     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10101     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10102
10103     /* dbcs WM_CHAR */
10104     flush_sequence();
10105     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10106     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10107     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10108
10109     /* other char messages are not magic */
10110     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10111     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10112     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10113     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10114     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10115     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10116     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10117     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10118     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10119     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10120
10121     /* test retrieving messages */
10122
10123     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10124     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10125     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10126     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10127     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10128     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10129     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10130     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10131     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10132     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10133
10134     /* message filters */
10135     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10136     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10137     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10138     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10139     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10140     /* message id is filtered, hwnd is not */
10141     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10142     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10143     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10144     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10145     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10146     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10147
10148     /* mixing GetMessage and PostMessage */
10149     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10150     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10151     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10152     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10153     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10154     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10155     time = msg.time;
10156     pt = msg.pt;
10157     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10158     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10159     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10160     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10161     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10162     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10163     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10164     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 );
10165     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10166
10167     /* without PM_REMOVE */
10168     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10169     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10170     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10171     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10172     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10173     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10174     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10175     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10176     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10177     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10178     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10179     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10180     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10181     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10182     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10183     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10184     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10185     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10186
10187     DestroyWindow(hwnd);
10188 }
10189
10190 #define ID_LISTBOX 0x000f
10191
10192 static const struct message wm_lb_setcursel_0[] =
10193 {
10194     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10195     { WM_CTLCOLORLISTBOX, sent|parent },
10196     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10197     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10198     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10199     { 0 }
10200 };
10201 static const struct message wm_lb_setcursel_1[] =
10202 {
10203     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10204     { WM_CTLCOLORLISTBOX, sent|parent },
10205     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10206     { WM_CTLCOLORLISTBOX, sent|parent },
10207     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10208     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10209     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10210     { 0 }
10211 };
10212 static const struct message wm_lb_setcursel_2[] =
10213 {
10214     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10215     { WM_CTLCOLORLISTBOX, sent|parent },
10216     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10217     { WM_CTLCOLORLISTBOX, sent|parent },
10218     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10219     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10220     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10221     { 0 }
10222 };
10223 static const struct message wm_lb_click_0[] =
10224 {
10225     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10226     { HCBT_SETFOCUS, hook },
10227     { WM_KILLFOCUS, sent|parent },
10228     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10229     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10230     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10231     { WM_SETFOCUS, sent|defwinproc },
10232
10233     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10234     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10235     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10236     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10237     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10238
10239     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10240     { WM_CTLCOLORLISTBOX, sent|parent },
10241     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10242     { WM_CTLCOLORLISTBOX, sent|parent },
10243     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10244     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10245
10246     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10247     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10248
10249     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10250     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10251     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10252     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10253     { 0 }
10254 };
10255
10256 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10257
10258 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10259
10260 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10261 {
10262     static long defwndproc_counter = 0;
10263     LRESULT ret;
10264     struct message msg;
10265
10266     /* do not log painting messages */
10267     if (message != WM_PAINT &&
10268         message != WM_NCPAINT &&
10269         message != WM_SYNCPAINT &&
10270         message != WM_ERASEBKGND &&
10271         message != WM_NCHITTEST &&
10272         message != WM_GETTEXT &&
10273         message != WM_GETICON &&
10274         message != WM_DEVICECHANGE)
10275     {
10276         trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
10277
10278         msg.message = message;
10279         msg.flags = sent|wparam|lparam;
10280         if (defwndproc_counter) msg.flags |= defwinproc;
10281         msg.wParam = wp;
10282         msg.lParam = lp;
10283         add_message(&msg);
10284     }
10285
10286     defwndproc_counter++;
10287     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10288     defwndproc_counter--;
10289
10290     return ret;
10291 }
10292
10293 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10294                                int caret_index, int top_index, int line)
10295 {
10296     LRESULT ret;
10297
10298     /* calling an orig proc helps to avoid unnecessary message logging */
10299     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10300     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10301     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10302     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10303     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10304     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10305     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10306     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10307 }
10308
10309 static void test_listbox_messages(void)
10310 {
10311     HWND parent, listbox;
10312     LRESULT ret;
10313
10314     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10315                              100, 100, 200, 200, 0, 0, 0, NULL);
10316     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10317                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10318                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10319     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10320
10321     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10322
10323     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10324     ok(ret == 0, "expected 0, got %ld\n", ret);
10325     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10326     ok(ret == 1, "expected 1, got %ld\n", ret);
10327     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10328     ok(ret == 2, "expected 2, got %ld\n", ret);
10329
10330     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10331
10332     flush_sequence();
10333
10334     log_all_parent_messages++;
10335
10336     trace("selecting item 0\n");
10337     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10338     ok(ret == 0, "expected 0, got %ld\n", ret);
10339     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10340     check_lb_state(listbox, 3, 0, 0, 0);
10341     flush_sequence();
10342
10343     trace("selecting item 1\n");
10344     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10345     ok(ret == 1, "expected 1, got %ld\n", ret);
10346     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10347     check_lb_state(listbox, 3, 1, 1, 0);
10348
10349     trace("selecting item 2\n");
10350     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10351     ok(ret == 2, "expected 2, got %ld\n", ret);
10352     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10353     check_lb_state(listbox, 3, 2, 2, 0);
10354
10355     trace("clicking on item 0\n");
10356     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10357     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10358     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10359     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10360     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10361     check_lb_state(listbox, 3, 0, 0, 0);
10362     flush_sequence();
10363
10364     log_all_parent_messages--;
10365
10366     DestroyWindow(listbox);
10367     DestroyWindow(parent);
10368 }
10369
10370 START_TEST(msg)
10371 {
10372     BOOL ret;
10373     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
10374
10375     init_procs();
10376
10377     if (!RegisterWindowClasses()) assert(0);
10378
10379     if (pSetWinEventHook)
10380     {
10381         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
10382                                                       GetModuleHandleA(0),
10383                                                       win_event_proc,
10384                                                       0,
10385                                                       GetCurrentThreadId(),
10386                                                       WINEVENT_INCONTEXT);
10387         assert(hEvent_hook);
10388
10389         if (pIsWinEventHookInstalled)
10390         {
10391             UINT event;
10392             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
10393                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
10394         }
10395     }
10396
10397     cbt_hook_thread_id = GetCurrentThreadId();
10398     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
10399     assert(hCBT_hook);
10400
10401     test_winevents();
10402
10403     /* Fix message sequences before removing 4 lines below */
10404 #if 1
10405     if (pUnhookWinEvent && hEvent_hook)
10406     {
10407         ret = pUnhookWinEvent(hEvent_hook);
10408         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10409         pUnhookWinEvent = 0;
10410     }
10411     hEvent_hook = 0;
10412 #endif
10413
10414     test_ShowWindow();
10415     test_PeekMessage();
10416     test_PeekMessage2();
10417     test_scrollwindowex();
10418     test_messages();
10419     test_showwindow();
10420     invisible_parent_tests();
10421     test_mdi_messages();
10422     test_button_messages();
10423     test_static_messages();
10424     test_listbox_messages();
10425     test_combobox_messages();
10426     test_wmime_keydown_message();
10427     test_paint_messages();
10428     test_interthread_messages();
10429     test_message_conversion();
10430     test_accelerators();
10431     test_timers();
10432     test_timers_no_wnd();
10433     test_set_hook();
10434     test_DestroyWindow();
10435     test_DispatchMessage();
10436     test_SendMessageTimeout();
10437     test_edit_messages();
10438     test_quit_message();
10439
10440     if (!pTrackMouseEvent)
10441         skip("TrackMouseEvent is not available\n");
10442     else
10443         test_TrackMouseEvent();
10444
10445     test_SetWindowRgn();
10446     test_sys_menu();
10447     test_dialog_messages();
10448     test_nullCallback();
10449     test_SetForegroundWindow();
10450     test_dbcs_wm_char();
10451
10452     UnhookWindowsHookEx(hCBT_hook);
10453     if (pUnhookWinEvent)
10454     {
10455         ret = pUnhookWinEvent(hEvent_hook);
10456         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10457         SetLastError(0xdeadbeef);
10458         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
10459         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
10460            GetLastError() == 0xdeadbeef, /* Win9x */
10461            "unexpected error %d\n", GetLastError());
10462     }
10463     else
10464         skip("UnhookWinEvent is not available\n");
10465 }