makefiles: Rename the SRCDIR, TOPSRCDIR and TOPOBJDIR variables to follow autoconf...
[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 #define _WIN32_WINNT 0x0600 /* For WM_CHANGEUISTATE,QS_RAWINPUT,WM_DWMxxxx */
24 #define WINVER 0x0600 /* for WM_GETTITLEBARINFOEX */
25
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.h"
35
36 #include "wine/test.h"
37
38 #define MDI_FIRST_CHILD_ID 2004
39
40 /* undocumented SWP flags - from SDK 3.1 */
41 #define SWP_NOCLIENTSIZE        0x0800
42 #define SWP_NOCLIENTMOVE        0x1000
43 #define SWP_STATECHANGED        0x8000
44
45 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
46
47 #ifndef WM_KEYF1
48 #define WM_KEYF1 0x004d
49 #endif
50
51 #ifndef WM_SYSTIMER
52 #define WM_SYSTIMER         0x0118
53 #endif
54
55 #define WND_PARENT_ID           1
56 #define WND_POPUP_ID            2
57 #define WND_CHILD_ID            3
58
59 #ifndef WM_LBTRACKPOINT
60 #define WM_LBTRACKPOINT  0x0131
61 #endif
62
63 /* encoded DRAWITEMSTRUCT into an LPARAM */
64 typedef struct
65 {
66     union
67     {
68         struct
69         {
70             UINT type    : 4;  /* ODT_* flags */
71             UINT ctl_id  : 4;  /* Control ID */
72             UINT item_id : 4;  /* Menu item ID */
73             UINT action  : 4;  /* ODA_* flags */
74             UINT state   : 16; /* ODS_* flags */
75         } item;
76         LPARAM lp;
77     } u;
78 } DRAW_ITEM_STRUCT;
79
80 static BOOL test_DestroyWindow_flag;
81 static HWINEVENTHOOK hEvent_hook;
82 static HHOOK hCBT_hook;
83 static DWORD cbt_hook_thread_id;
84
85 static const WCHAR testWindowClassW[] =
86 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
87
88 /*
89 FIXME: add tests for these
90 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
91  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
92  WS_THICKFRAME: thick border
93  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
94  WS_BORDER (default for overlapped windows): single black border
95  none (default for child (and popup?) windows): no border
96 */
97
98 typedef enum {
99     sent=0x1,
100     posted=0x2,
101     parent=0x4,
102     wparam=0x8,
103     lparam=0x10,
104     defwinproc=0x20,
105     beginpaint=0x40,
106     optional=0x80,
107     hook=0x100,
108     winevent_hook=0x200
109 } msg_flags_t;
110
111 struct message {
112     UINT message;          /* the WM_* code */
113     msg_flags_t flags;     /* message props */
114     WPARAM wParam;         /* expected value of wParam */
115     LPARAM lParam;         /* expected value of lParam */
116     WPARAM wp_mask;        /* mask for wParam checks */
117     LPARAM lp_mask;        /* mask for lParam checks */
118 };
119
120 struct recvd_message {
121     UINT message;          /* the WM_* code */
122     msg_flags_t flags;     /* message props */
123     HWND hwnd;             /* window that received the message */
124     WPARAM wParam;         /* expected value of wParam */
125     LPARAM lParam;         /* expected value of lParam */
126     int line;              /* source line where logged */
127     const char *descr;     /* description for trace output */
128     char output[512];      /* trace output */
129 };
130
131 /* Empty message sequence */
132 static const struct message WmEmptySeq[] =
133 {
134     { 0 }
135 };
136 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
137 static const struct message WmCreateOverlappedSeq[] = {
138     { HCBT_CREATEWND, hook },
139     { WM_GETMINMAXINFO, sent },
140     { WM_NCCREATE, sent },
141     { WM_NCCALCSIZE, sent|wparam, 0 },
142     { 0x0093, sent|defwinproc|optional },
143     { 0x0094, sent|defwinproc|optional },
144     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
145     { WM_CREATE, sent },
146     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
147     { 0 }
148 };
149 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
150  * for a not visible overlapped window.
151  */
152 static const struct message WmSWP_ShowOverlappedSeq[] = {
153     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
154     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
155     { WM_NCPAINT, sent|wparam|optional, 1 },
156     { WM_GETTEXT, sent|defwinproc|optional },
157     { WM_ERASEBKGND, sent|optional },
158     { HCBT_ACTIVATE, hook },
159     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
160     { WM_NOTIFYFORMAT, sent|optional },
161     { WM_QUERYUISTATE, sent|optional },
162     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
163     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
164     { WM_ACTIVATEAPP, sent|wparam, 1 },
165     { WM_NCACTIVATE, sent },
166     { WM_GETTEXT, sent|defwinproc|optional },
167     { WM_ACTIVATE, sent|wparam, 1 },
168     { HCBT_SETFOCUS, hook },
169     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
170     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
171     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
172     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
173     { WM_GETTEXT, sent|optional },
174     { WM_NCPAINT, sent|wparam|optional, 1 },
175     { WM_GETTEXT, sent|defwinproc|optional },
176     { WM_ERASEBKGND, sent|optional },
177     /* Win9x adds SWP_NOZORDER below */
178     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
179     { WM_GETTEXT, sent|optional },
180     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
181     { WM_NCPAINT, sent|wparam|optional, 1 },
182     { WM_ERASEBKGND, sent|optional },
183     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
184     { WM_SYNCPAINT, sent|optional },
185     { WM_GETTITLEBARINFOEX, sent|optional },
186     { WM_PAINT, sent|optional },
187     { WM_NCPAINT, sent|beginpaint|optional },
188     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
189     { WM_ERASEBKGND, sent|beginpaint|optional },
190     { 0 }
191 };
192 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
193  * for a visible overlapped window.
194  */
195 static const struct message WmSWP_HideOverlappedSeq[] = {
196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
197     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
198     { HCBT_ACTIVATE, hook|optional },
199     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
200     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
201     { WM_NCACTIVATE, sent|optional },
202     { WM_ACTIVATE, sent|optional },
203     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
204     { 0 }
205 };
206
207 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
208  * for a visible overlapped window.
209  */
210 static const struct message WmSWP_ResizeSeq[] = {
211     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
212     { WM_GETMINMAXINFO, sent|defwinproc },
213     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
214     { WM_NCPAINT, sent|optional },
215     { WM_GETTEXT, sent|defwinproc|optional },
216     { WM_ERASEBKGND, sent|optional },
217     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
218     { WM_SIZE, sent|defwinproc|optional },
219     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
220     { WM_NCPAINT, sent|optional },
221     { WM_GETTEXT, sent|defwinproc|optional },
222     { WM_ERASEBKGND, sent|optional },
223     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
224     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
225     { 0 }
226 };
227
228 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
229  * for a visible popup window.
230  */
231 static const struct message WmSWP_ResizePopupSeq[] = {
232     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
233     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
234     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
235     { WM_NCPAINT, sent|optional },
236     { WM_GETTEXT, sent|defwinproc|optional },
237     { WM_ERASEBKGND, sent|optional },
238     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
239     { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
240     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
241     { WM_NCPAINT, sent|optional },
242     { WM_GETTEXT, sent|defwinproc|optional },
243     { WM_ERASEBKGND, sent|optional },
244     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
245     { 0 }
246 };
247
248 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
249  * for a visible overlapped window.
250  */
251 static const struct message WmSWP_MoveSeq[] = {
252     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
253     { WM_NCPAINT, sent|optional },
254     { WM_GETTEXT, sent|defwinproc|optional },
255     { WM_ERASEBKGND, sent|optional },
256     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
257     { WM_MOVE, sent|defwinproc|wparam, 0 },
258     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
259     { 0 }
260 };
261 /* Resize with SetWindowPos(SWP_NOZORDER)
262  * for a visible overlapped window
263  * SWP_NOZORDER is stripped by the logging code
264  */
265 static const struct message WmSWP_ResizeNoZOrder[] = {
266     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
267     { WM_GETMINMAXINFO, sent|defwinproc },
268     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
269     { WM_NCPAINT, sent|optional },
270     { WM_GETTEXT, sent|defwinproc|optional },
271     { WM_ERASEBKGND, sent|optional },
272     { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
273       SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
274     { WM_MOVE, sent|defwinproc|optional },
275     { WM_SIZE, sent|defwinproc|optional },
276     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
277     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
278     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
279     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
280     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
282     { 0 }
283 };
284
285 /* Switch visible mdi children */
286 static const struct message WmSwitchChild[] = {
287     /* Switch MDI child */
288     { WM_MDIACTIVATE, sent },/* in the MDI client */
289     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
290     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
291     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
292     /* Deactivate 2nd MDI child */
293     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
294     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
295     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
296     /* Preparing for maximize and maximaze the 1st MDI child */
297     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
298     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
299     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
300     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
301     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
302     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
303     /* Lock redraw 2nd MDI child */
304     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
305     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
306     /* Restore 2nd MDI child */
307     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
308     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
309     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
310     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
311     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
312     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
313     /* Redraw 2nd MDI child */
314     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
315     /* Redraw MDI frame */
316     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
317     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
318     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
319     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
320     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
321     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
322     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
323     { HCBT_SETFOCUS, hook },
324     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
325     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
326     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
327     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
328     { WM_SETFOCUS, sent },/* in the MDI client */
329     { HCBT_SETFOCUS, hook },
330     { WM_KILLFOCUS, sent },/* in the MDI client */
331     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
332     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
333     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
334     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
335     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
336     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
337     { 0 }
338 };
339
340 /* Switch visible not maximized mdi children */
341 static const struct message WmSwitchNotMaximizedChild[] = {
342     /* Switch not maximized MDI child */
343     { WM_MDIACTIVATE, sent },/* in the MDI client */
344     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
345     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
346     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
347     /* Deactivate 1st MDI child */
348     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
349     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
350     /* Activate 2nd MDI child */
351     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
352     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
353     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
354     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
355     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
356     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
357     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
358     { HCBT_SETFOCUS, hook },
359     { WM_KILLFOCUS, sent }, /* in the  MDI client */
360     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
361     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
362     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
363     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
364     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
365     { 0 }
366 };
367
368
369 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
370                 SWP_NOZORDER|SWP_FRAMECHANGED)
371  * for a visible overlapped window with WS_CLIPCHILDREN style set.
372  */
373 static const struct message WmSWP_FrameChanged_clip[] = {
374     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
375     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
376     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
377     { WM_GETTEXT, sent|parent|defwinproc|optional },
378     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
379     { WM_NCPAINT, sent }, /* wparam != 1 */
380     { WM_ERASEBKGND, sent },
381     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
382     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
383     { WM_PAINT, sent },
384     { 0 }
385 };
386 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
387                 SWP_NOZORDER|SWP_FRAMECHANGED)
388  * for a visible overlapped window.
389  */
390 static const struct message WmSWP_FrameChangedDeferErase[] = {
391     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
392     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
393     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
394     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
395     { WM_PAINT, sent|parent|optional },
396     { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
397     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
398     { WM_PAINT, sent },
399     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
400     { WM_ERASEBKGND, sent|beginpaint|optional },
401     { 0 }
402 };
403
404 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
405                 SWP_NOZORDER|SWP_FRAMECHANGED)
406  * for a visible overlapped window without WS_CLIPCHILDREN style set.
407  */
408 static const struct message WmSWP_FrameChanged_noclip[] = {
409     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
410     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
411     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
412     { WM_GETTEXT, sent|parent|defwinproc|optional },
413     { WM_ERASEBKGND, sent|parent|optional },
414     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
415     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
416     { WM_PAINT, sent },
417     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
418     { WM_ERASEBKGND, sent|beginpaint|optional },
419     { 0 }
420 };
421
422 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
423 static const struct message WmShowOverlappedSeq[] = {
424     { WM_SHOWWINDOW, sent|wparam, 1 },
425     { WM_NCPAINT, sent|wparam|optional, 1 },
426     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
427     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
428     { WM_NCPAINT, sent|wparam|optional, 1 },
429     { WM_GETTEXT, sent|defwinproc|optional },
430     { WM_ERASEBKGND, sent|optional },
431     { HCBT_ACTIVATE, hook },
432     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
433     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
434     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
435     { WM_NCPAINT, sent|wparam|optional, 1 },
436     { WM_ACTIVATEAPP, sent|wparam, 1 },
437     { WM_NCACTIVATE, sent|wparam, 1 },
438     { WM_GETTEXT, sent|defwinproc|optional },
439     { WM_ACTIVATE, sent|wparam, 1 },
440     { HCBT_SETFOCUS, hook },
441     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
442     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
443     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
444     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
445     { WM_GETTEXT, sent|optional },
446     { WM_NCPAINT, sent|wparam|optional, 1 },
447     { WM_GETTEXT, sent|defwinproc|optional },
448     { WM_ERASEBKGND, sent|optional },
449     /* Win9x adds SWP_NOZORDER below */
450     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
451     { WM_NCCALCSIZE, sent|optional },
452     { WM_GETTEXT, sent|optional },
453     { WM_NCPAINT, sent|optional },
454     { WM_ERASEBKGND, sent|optional },
455     { WM_SYNCPAINT, sent|optional },
456 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
457        * messages. Does that mean that CreateWindow doesn't set initial
458        * window dimensions for overlapped windows?
459        */
460     { WM_SIZE, sent },
461     { WM_MOVE, sent },
462 #endif
463     { WM_PAINT, sent|optional },
464     { WM_NCPAINT, sent|beginpaint|optional },
465     { 0 }
466 };
467 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
468 static const struct message WmShowMaxOverlappedSeq[] = {
469     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
470     { WM_GETMINMAXINFO, sent },
471     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
472     { WM_GETMINMAXINFO, sent|defwinproc },
473     { WM_NCCALCSIZE, sent|wparam, TRUE },
474     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
475     { HCBT_ACTIVATE, hook },
476     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
477     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
478     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
479     { WM_ACTIVATEAPP, sent|wparam, 1 },
480     { WM_NCACTIVATE, sent|wparam, 1 },
481     { WM_GETTEXT, sent|defwinproc|optional },
482     { WM_ACTIVATE, sent|wparam, 1 },
483     { HCBT_SETFOCUS, hook },
484     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
485     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
486     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
487     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
488     { WM_GETTEXT, sent|optional },
489     { WM_NCPAINT, sent|wparam|optional, 1 },
490     { WM_GETTEXT, sent|defwinproc|optional },
491     { WM_ERASEBKGND, sent|optional },
492     /* Win9x adds SWP_NOZORDER below */
493     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
494     { WM_MOVE, sent|defwinproc },
495     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
496     { WM_GETTEXT, sent|optional },
497     { WM_NCCALCSIZE, sent|optional },
498     { WM_NCPAINT, sent|optional },
499     { WM_ERASEBKGND, sent|optional },
500     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
502     { WM_SYNCPAINT, sent|optional },
503     { WM_GETTITLEBARINFOEX, sent|optional },
504     { WM_PAINT, sent|optional },
505     { WM_NCPAINT, sent|beginpaint|optional },
506     { WM_ERASEBKGND, sent|beginpaint|optional },
507     { 0 }
508 };
509 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
510 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
511     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
512     { WM_GETTEXT, sent|optional },
513     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
514     { WM_GETMINMAXINFO, sent|defwinproc },
515     { WM_NCCALCSIZE, sent|wparam, TRUE },
516     { WM_NCPAINT, sent|optional },
517     { WM_GETTEXT, sent|defwinproc|optional },
518     { WM_ERASEBKGND, sent|optional },
519     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
520     { WM_MOVE, sent|defwinproc|optional },
521     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
522     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
523     { WM_NCPAINT, sent|optional },
524     { WM_ERASEBKGND, sent|optional },
525     { WM_PAINT, sent|optional },
526     { WM_GETTITLEBARINFOEX, sent|optional },
527     { WM_NCPAINT, sent|beginpaint|optional },
528     { WM_ERASEBKGND, sent|beginpaint|optional },
529     { 0 }
530 };
531 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
532 static const struct message WmShowRestoreMinOverlappedSeq[] = {
533     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
534     { WM_QUERYOPEN, sent|optional },
535     { WM_GETTEXT, sent|optional },
536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
537     { WM_GETMINMAXINFO, sent|defwinproc },
538     { WM_NCCALCSIZE, sent|wparam, TRUE },
539     { HCBT_ACTIVATE, hook },
540     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
541     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
542     { WM_ACTIVATEAPP, sent|wparam, 1 },
543     { WM_NCACTIVATE, sent|wparam, 1 },
544     { WM_GETTEXT, sent|defwinproc|optional },
545     { WM_ACTIVATE, sent|wparam, 1 },
546     { HCBT_SETFOCUS, hook },
547     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
548     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
549     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
550     { WM_GETTEXT, sent|optional },
551     { WM_NCPAINT, sent|wparam|optional, 1 },
552     { WM_GETTEXT, sent|defwinproc|optional },
553     { WM_ERASEBKGND, sent },
554     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
555     { WM_MOVE, sent|defwinproc },
556     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
557     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
558     { WM_NCPAINT, sent|wparam|optional, 1 },
559     { WM_ERASEBKGND, sent|optional },
560     { WM_ACTIVATE, sent|wparam, 1 },
561     { WM_GETTEXT, sent|optional },
562     { WM_PAINT, sent|optional },
563     { WM_GETTITLEBARINFOEX, sent|optional },
564     { WM_NCPAINT, sent|beginpaint|optional },
565     { WM_ERASEBKGND, sent|beginpaint|optional },
566     { 0 }
567 };
568 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
569 static const struct message WmShowMinOverlappedSeq[] = {
570     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
571     { HCBT_SETFOCUS, hook },
572     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
573     { WM_KILLFOCUS, sent },
574     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
575     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
576     { WM_GETTEXT, sent|optional },
577     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
578     { WM_GETMINMAXINFO, sent|defwinproc },
579     { WM_NCCALCSIZE, sent|wparam, TRUE },
580     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
581     { WM_NCPAINT, sent|optional },
582     { WM_GETTEXT, sent|defwinproc|optional },
583     { WM_WINDOWPOSCHANGED, sent },
584     { WM_MOVE, sent|defwinproc },
585     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
586     { WM_NCCALCSIZE, sent|optional },
587     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
589     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
590     { WM_NCACTIVATE, sent|wparam, 0 },
591     { WM_GETTEXT, sent|defwinproc|optional },
592     { WM_ACTIVATE, sent },
593     { WM_ACTIVATEAPP, sent|wparam, 0 },
594
595     /* Vista sometimes restores the window right away... */
596     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
597     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
598     { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
599     { WM_QUERYOPEN, sent|optional },
600     { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
601     { WM_GETMINMAXINFO, sent|optional|defwinproc },
602     { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
603     { HCBT_ACTIVATE, hook|optional },
604     { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
605     { WM_NCACTIVATE, sent|optional },
606     { WM_GETTEXT, sent|optional },
607     { WM_ACTIVATE, sent|optional|wparam, 1 },
608     { HCBT_SETFOCUS, hook|optional },
609     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
610     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
611     { WM_SETFOCUS, sent|optional },
612     { WM_NCPAINT, sent|optional },
613     { WM_GETTEXT, sent|defwinproc|optional },
614     { WM_ERASEBKGND, sent|optional },
615     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
616     { WM_MOVE, sent|defwinproc|optional },
617     { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
618     { WM_ACTIVATE, sent|optional|wparam, 1 },
619     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
620     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
621
622     { WM_PAINT, sent|optional },
623     { WM_NCPAINT, sent|beginpaint|optional },
624     { WM_ERASEBKGND, sent|beginpaint|optional },
625     { 0 }
626 };
627 /* ShowWindow(SW_HIDE) for a visible overlapped window */
628 static const struct message WmHideOverlappedSeq[] = {
629     { WM_SHOWWINDOW, sent|wparam, 0 },
630     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
631     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
632     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
633     { WM_SIZE, sent|optional }, /* XP doesn't send it */
634     { WM_MOVE, sent|optional }, /* XP doesn't send it */
635     { WM_NCACTIVATE, sent|wparam|optional, 0 },
636     { WM_ACTIVATE, sent|wparam|optional, 0 },
637     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
638     { HCBT_SETFOCUS, hook|optional },
639     { WM_KILLFOCUS, sent|wparam, 0 },
640     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
641     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
642     { 0 }
643 };
644 /* DestroyWindow for a visible overlapped window */
645 static const struct message WmDestroyOverlappedSeq[] = {
646     { HCBT_DESTROYWND, hook },
647     { 0x0090, sent|optional },
648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
649     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
650     { 0x0090, sent|optional },
651     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
652     { WM_NCACTIVATE, sent|optional|wparam, 0 },
653     { WM_ACTIVATE, sent|optional },
654     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
655     { WM_KILLFOCUS, sent|optional|wparam, 0 },
656     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
657     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
658     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
659     { WM_DESTROY, sent },
660     { WM_NCDESTROY, sent },
661     { 0 }
662 };
663 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
664 static const struct message WmCreateMaxPopupSeq[] = {
665     { HCBT_CREATEWND, hook },
666     { WM_NCCREATE, sent },
667     { WM_NCCALCSIZE, sent|wparam, 0 },
668     { WM_CREATE, sent },
669     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
670     { WM_SIZE, sent|wparam, SIZE_RESTORED },
671     { WM_MOVE, sent },
672     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
673     { WM_GETMINMAXINFO, sent },
674     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
675     { WM_NCCALCSIZE, sent|wparam, TRUE },
676     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
677     { WM_MOVE, sent|defwinproc },
678     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
679     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
680     { WM_SHOWWINDOW, sent|wparam, 1 },
681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
682     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
683     { HCBT_ACTIVATE, hook },
684     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
685     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
686     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
687     { WM_NCPAINT, sent|wparam|optional, 1 },
688     { WM_ERASEBKGND, sent|optional },
689     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
690     { WM_ACTIVATEAPP, sent|wparam, 1 },
691     { WM_NCACTIVATE, sent },
692     { WM_ACTIVATE, sent|wparam, 1 },
693     { HCBT_SETFOCUS, hook },
694     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
695     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
696     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
697     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
698     { WM_GETTEXT, sent|optional },
699     { WM_SYNCPAINT, sent|wparam|optional, 4 },
700     { WM_NCPAINT, sent|wparam|optional, 1 },
701     { WM_ERASEBKGND, sent|optional },
702     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
703     { WM_ERASEBKGND, sent|defwinproc|optional },
704     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
705     { 0 }
706 };
707 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
708 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
709     { HCBT_CREATEWND, hook },
710     { WM_NCCREATE, sent },
711     { WM_NCCALCSIZE, sent|wparam, 0 },
712     { WM_CREATE, sent },
713     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
714     { WM_SIZE, sent|wparam, SIZE_RESTORED },
715     { WM_MOVE, sent },
716     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
717     { WM_GETMINMAXINFO, sent },
718     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
719     { WM_NCCALCSIZE, sent|wparam, TRUE },
720     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
721     { WM_MOVE, sent|defwinproc },
722     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
723     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
724     { 0 }
725 };
726 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
727 static const struct message WmShowMaxPopupResizedSeq[] = {
728     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
729     { WM_GETMINMAXINFO, sent },
730     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
731     { WM_NCCALCSIZE, sent|wparam, TRUE },
732     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
733     { HCBT_ACTIVATE, hook },
734     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
735     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
736     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
737     { WM_NCPAINT, sent|wparam|optional, 1 },
738     { WM_ERASEBKGND, sent|optional },
739     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
740     { WM_ACTIVATEAPP, sent|wparam, 1 },
741     { WM_NCACTIVATE, sent },
742     { WM_ACTIVATE, sent|wparam, 1 },
743     { HCBT_SETFOCUS, hook },
744     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
745     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
746     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
747     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
748     { WM_GETTEXT, sent|optional },
749     { WM_NCPAINT, sent|wparam|optional, 1 },
750     { WM_ERASEBKGND, sent|optional },
751     { WM_WINDOWPOSCHANGED, sent },
752     /* WinNT4.0 sends WM_MOVE */
753     { WM_MOVE, sent|defwinproc|optional },
754     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
755     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
756     { 0 }
757 };
758 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
759 static const struct message WmShowMaxPopupSeq[] = {
760     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
761     { WM_GETMINMAXINFO, sent },
762     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
763     { WM_NCCALCSIZE, sent|wparam, TRUE },
764     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
765     { HCBT_ACTIVATE, hook },
766     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
767     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
768     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
769     { WM_ACTIVATEAPP, sent|wparam, 1 },
770     { WM_NCACTIVATE, sent },
771     { WM_ACTIVATE, sent|wparam, 1 },
772     { HCBT_SETFOCUS, hook },
773     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
774     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
775     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
776     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
777     { WM_GETTEXT, sent|optional },
778     { WM_SYNCPAINT, sent|wparam|optional, 4 },
779     { WM_NCPAINT, sent|wparam|optional, 1 },
780     { WM_ERASEBKGND, sent|optional },
781     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
782     { WM_ERASEBKGND, sent|defwinproc|optional },
783     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
784     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
785     { 0 }
786 };
787 /* CreateWindow(WS_VISIBLE) for popup window */
788 static const struct message WmCreatePopupSeq[] = {
789     { HCBT_CREATEWND, hook },
790     { WM_NCCREATE, sent },
791     { WM_NCCALCSIZE, sent|wparam, 0 },
792     { WM_CREATE, sent },
793     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
794     { WM_SIZE, sent|wparam, SIZE_RESTORED },
795     { WM_MOVE, sent },
796     { WM_SHOWWINDOW, sent|wparam, 1 },
797     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
798     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
799     { HCBT_ACTIVATE, hook },
800     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
801     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
802     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
803     { WM_NCPAINT, sent|wparam|optional, 1 },
804     { WM_ERASEBKGND, sent|optional },
805     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
806     { WM_ACTIVATEAPP, sent|wparam, 1 },
807     { WM_NCACTIVATE, sent },
808     { WM_ACTIVATE, sent|wparam, 1 },
809     { HCBT_SETFOCUS, hook },
810     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
811     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
812     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
813     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
814     { WM_GETTEXT, sent|optional },
815     { WM_SYNCPAINT, sent|wparam|optional, 4 },
816     { WM_NCPAINT, sent|wparam|optional, 1 },
817     { WM_ERASEBKGND, sent|optional },
818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
819     { 0 }
820 };
821 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
822 static const struct message WmShowVisMaxPopupSeq[] = {
823     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
824     { WM_GETMINMAXINFO, sent },
825     { WM_GETTEXT, sent|optional },
826     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
827     { WM_GETTEXT, sent|optional },
828     { WM_NCCALCSIZE, sent|wparam, TRUE },
829     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
830     { WM_NCPAINT, sent|wparam|optional, 1 },
831     { WM_ERASEBKGND, sent|optional },
832     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
833     { WM_MOVE, sent|defwinproc },
834     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
835     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
836     { 0 }
837 };
838 /* CreateWindow (for a child popup window, not initially visible) */
839 static const struct message WmCreateChildPopupSeq[] = {
840     { HCBT_CREATEWND, hook },
841     { WM_NCCREATE, sent }, 
842     { WM_NCCALCSIZE, sent|wparam, 0 },
843     { WM_CREATE, sent },
844     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
845     { WM_SIZE, sent|wparam, SIZE_RESTORED },
846     { WM_MOVE, sent },
847     { 0 }
848 };
849 /* CreateWindow (for a popup window, not initially visible,
850  * which sets WS_VISIBLE in WM_CREATE handler)
851  */
852 static const struct message WmCreateInvisiblePopupSeq[] = {
853     { HCBT_CREATEWND, hook },
854     { WM_NCCREATE, sent }, 
855     { WM_NCCALCSIZE, sent|wparam, 0 },
856     { WM_CREATE, sent },
857     { WM_STYLECHANGING, sent },
858     { WM_STYLECHANGED, sent },
859     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
860     { WM_SIZE, sent|wparam, SIZE_RESTORED },
861     { WM_MOVE, sent },
862     { 0 }
863 };
864 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
865  * for a popup window with WS_VISIBLE style set
866  */
867 static const struct message WmShowVisiblePopupSeq_2[] = {
868     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
869     { 0 }
870 };
871 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
872  * for a popup window with WS_VISIBLE style set
873  */
874 static const struct message WmShowVisiblePopupSeq_3[] = {
875     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
876     { HCBT_ACTIVATE, hook },
877     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
878     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
879     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
880     { WM_NCACTIVATE, sent },
881     { WM_ACTIVATE, sent|wparam, 1 },
882     { HCBT_SETFOCUS, hook },
883     { WM_KILLFOCUS, sent|parent },
884     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
885     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
886     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
887     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
888     { WM_SETFOCUS, sent|defwinproc },
889     { WM_GETTEXT, sent|optional },
890     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
891     { 0 }
892 };
893 /* CreateWindow (for child window, not initially visible) */
894 static const struct message WmCreateChildSeq[] = {
895     { HCBT_CREATEWND, hook },
896     { WM_NCCREATE, sent }, 
897     /* child is inserted into parent's child list after WM_NCCREATE returns */
898     { WM_NCCALCSIZE, sent|wparam, 0 },
899     { WM_CREATE, sent },
900     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
901     { WM_SIZE, sent|wparam, SIZE_RESTORED },
902     { WM_MOVE, sent },
903     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
904     { 0 }
905 };
906 /* CreateWindow (for maximized child window, not initially visible) */
907 static const struct message WmCreateMaximizedChildSeq[] = {
908     { HCBT_CREATEWND, hook },
909     { WM_NCCREATE, sent }, 
910     { WM_NCCALCSIZE, sent|wparam, 0 },
911     { WM_CREATE, sent },
912     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
913     { WM_SIZE, sent|wparam, SIZE_RESTORED },
914     { WM_MOVE, sent },
915     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
916     { WM_GETMINMAXINFO, sent },
917     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
918     { WM_NCCALCSIZE, sent|wparam, 1 },
919     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
920     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
921     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
922     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
923     { 0 }
924 };
925 /* CreateWindow (for a child window, initially visible) */
926 static const struct message WmCreateVisibleChildSeq[] = {
927     { HCBT_CREATEWND, hook },
928     { WM_NCCREATE, sent }, 
929     /* child is inserted into parent's child list after WM_NCCREATE returns */
930     { WM_NCCALCSIZE, sent|wparam, 0 },
931     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
932     { WM_CREATE, sent },
933     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
934     { WM_SIZE, sent|wparam, SIZE_RESTORED },
935     { WM_MOVE, sent },
936     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
937     { WM_SHOWWINDOW, sent|wparam, 1 },
938     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
939     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
940     { WM_ERASEBKGND, sent|parent|optional },
941     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
942     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
943     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
944     { 0 }
945 };
946 /* ShowWindow(SW_SHOW) for a not visible child window */
947 static const struct message WmShowChildSeq[] = {
948     { WM_SHOWWINDOW, sent|wparam, 1 },
949     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
950     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
951     { WM_ERASEBKGND, sent|parent|optional },
952     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
953     { 0 }
954 };
955 /* ShowWindow(SW_HIDE) for a visible child window */
956 static const struct message WmHideChildSeq[] = {
957     { WM_SHOWWINDOW, sent|wparam, 0 },
958     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
959     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
960     { WM_ERASEBKGND, sent|parent|optional },
961     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
962     { 0 }
963 };
964 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
965 static const struct message WmHideChildSeq2[] = {
966     { WM_SHOWWINDOW, sent|wparam, 0 },
967     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
968     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
969     { WM_ERASEBKGND, sent|parent|optional },
970     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
971     { 0 }
972 };
973 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
974  * for a not visible child window
975  */
976 static const struct message WmShowChildSeq_2[] = {
977     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
978     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
979     { WM_CHILDACTIVATE, sent },
980     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
981     { 0 }
982 };
983 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
984  * for a not visible child window
985  */
986 static const struct message WmShowChildSeq_3[] = {
987     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
988     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
989     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
990     { 0 }
991 };
992 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
993  * for a visible child window with a caption
994  */
995 static const struct message WmShowChildSeq_4[] = {
996     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
997     { WM_CHILDACTIVATE, sent },
998     { 0 }
999 };
1000 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1001 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1002     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1003     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1004     { WM_NCCALCSIZE, sent|wparam, 1 },
1005     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1006     { WM_CHILDACTIVATE, sent|optional },
1007     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1008     { WM_MOVE, sent|defwinproc },
1009     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1010     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1011     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1012     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1013     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1014     { WM_GETTEXT, sent|optional },
1015     { 0 }
1016 };
1017 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1018 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1019     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1020     { 0 }
1021 };
1022 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1023 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1024     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1025     { WM_GETMINMAXINFO, sent },
1026     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1027     { WM_NCCALCSIZE, sent|wparam, 1 },
1028     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1029     { WM_CHILDACTIVATE, sent },
1030     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1031     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1032     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1033     { 0 }
1034 };
1035 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1036 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1037     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1038     { 0 }
1039 };
1040 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1041 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1042     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1043     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1044     { WM_NCCALCSIZE, sent|wparam, 1 },
1045     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1046     { WM_CHILDACTIVATE, sent },
1047     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1048     { WM_MOVE, sent|defwinproc },
1049     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1050     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1051     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1052     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1053     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1054     { WM_GETTEXT, sent|optional },
1055     { 0 }
1056 };
1057 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1058 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1059     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1060     { 0 }
1061 };
1062 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1063 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1064     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1065     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1066     { WM_NCCALCSIZE, sent|wparam, 1 },
1067     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1068     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1069     { WM_MOVE, sent|defwinproc },
1070     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1071     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1072     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1073     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1074     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1075     { WM_GETTEXT, sent|optional },
1076     { 0 }
1077 };
1078 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1079 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1080     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1081     { 0 }
1082 };
1083 /* ShowWindow(SW_SHOW) for child with invisible parent */
1084 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1085     { WM_SHOWWINDOW, sent|wparam, 1 },
1086     { 0 }
1087 };
1088 /* ShowWindow(SW_HIDE) for child with invisible parent */
1089 static const struct message WmHideChildInvisibleParentSeq[] = {
1090     { WM_SHOWWINDOW, sent|wparam, 0 },
1091     { 0 }
1092 };
1093 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1094 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1096     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1097     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1098     { 0 }
1099 };
1100 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1101 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1102     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1103     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1104     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1105     { 0 }
1106 };
1107 /* DestroyWindow for a visible child window */
1108 static const struct message WmDestroyChildSeq[] = {
1109     { HCBT_DESTROYWND, hook },
1110     { 0x0090, sent|optional },
1111     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1112     { WM_SHOWWINDOW, sent|wparam, 0 },
1113     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1114     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1115     { WM_ERASEBKGND, sent|parent|optional },
1116     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1117     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1118     { WM_KILLFOCUS, sent },
1119     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1120     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1121     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1122     { WM_SETFOCUS, sent|parent },
1123     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1124     { WM_DESTROY, sent },
1125     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1126     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1127     { WM_NCDESTROY, sent },
1128     { 0 }
1129 };
1130 /* visible child window destroyed by thread exit */
1131 static const struct message WmExitThreadSeq[] = {
1132     { WM_NCDESTROY, sent },  /* actually in grandchild */
1133     { WM_PAINT, sent|parent },
1134     { WM_ERASEBKGND, sent|parent|beginpaint },
1135     { 0 }
1136 };
1137 /* DestroyWindow for a visible child window with invisible parent */
1138 static const struct message WmDestroyInvisibleChildSeq[] = {
1139     { HCBT_DESTROYWND, hook },
1140     { 0x0090, sent|optional },
1141     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1142     { WM_SHOWWINDOW, sent|wparam, 0 },
1143     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1144     { WM_DESTROY, sent },
1145     { WM_NCDESTROY, sent },
1146     { 0 }
1147 };
1148 /* Moving the mouse in nonclient area */
1149 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1150     { WM_NCHITTEST, sent },
1151     { WM_SETCURSOR, sent },
1152     { WM_NCMOUSEMOVE, posted },
1153     { 0 }
1154 };
1155 /* Moving the mouse in client area */
1156 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1157     { WM_NCHITTEST, sent },
1158     { WM_SETCURSOR, sent },
1159     { WM_MOUSEMOVE, posted },
1160     { 0 }
1161 };
1162 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1163 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1164     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1165     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1166     { WM_GETMINMAXINFO, sent|defwinproc },
1167     { WM_ENTERSIZEMOVE, sent|defwinproc },
1168     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1169     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1170     { WM_MOVE, sent|defwinproc },
1171     { WM_EXITSIZEMOVE, sent|defwinproc },
1172     { 0 }
1173 };
1174 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1175 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1176     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1177     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1178     { WM_GETMINMAXINFO, sent|defwinproc },
1179     { WM_ENTERSIZEMOVE, sent|defwinproc },
1180     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1181     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1182     { WM_GETMINMAXINFO, sent|defwinproc },
1183     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1184     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1185     { WM_GETTEXT, sent|defwinproc },
1186     { WM_ERASEBKGND, sent|defwinproc },
1187     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1188     { WM_MOVE, sent|defwinproc },
1189     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1190     { WM_EXITSIZEMOVE, sent|defwinproc },
1191     { 0 }
1192 };
1193 /* Resizing child window with MoveWindow (32) */
1194 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1195     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1196     { WM_NCCALCSIZE, sent|wparam, 1 },
1197     { WM_ERASEBKGND, sent|parent|optional },
1198     { WM_ERASEBKGND, sent|optional },
1199     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1200     { WM_MOVE, sent|defwinproc },
1201     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1202     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1203     { 0 }
1204 };
1205 /* Clicking on inactive button */
1206 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1207     { WM_NCHITTEST, sent },
1208     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1209     { WM_MOUSEACTIVATE, sent },
1210     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1211     { WM_SETCURSOR, sent },
1212     { WM_SETCURSOR, sent|parent|defwinproc },
1213     { WM_LBUTTONDOWN, posted },
1214     { WM_KILLFOCUS, posted|parent },
1215     { WM_SETFOCUS, posted },
1216     { WM_CTLCOLORBTN, posted|parent },
1217     { BM_SETSTATE, posted },
1218     { WM_CTLCOLORBTN, posted|parent },
1219     { WM_LBUTTONUP, posted },
1220     { BM_SETSTATE, posted },
1221     { WM_CTLCOLORBTN, posted|parent },
1222     { WM_COMMAND, posted|parent },
1223     { 0 }
1224 };
1225 /* Reparenting a button (16/32) */
1226 /* The last child (button) reparented gets topmost for its new parent. */
1227 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1228     { WM_SHOWWINDOW, sent|wparam, 0 },
1229     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1230     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1231     { WM_ERASEBKGND, sent|parent },
1232     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1233     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1234     { WM_CHILDACTIVATE, sent },
1235     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1236     { WM_MOVE, sent|defwinproc },
1237     { WM_SHOWWINDOW, sent|wparam, 1 },
1238     { 0 }
1239 };
1240 /* Creation of a custom dialog (32) */
1241 static const struct message WmCreateCustomDialogSeq[] = {
1242     { HCBT_CREATEWND, hook },
1243     { WM_GETMINMAXINFO, sent },
1244     { WM_NCCREATE, sent },
1245     { WM_NCCALCSIZE, sent|wparam, 0 },
1246     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1247     { WM_CREATE, sent },
1248     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1249     { WM_NOTIFYFORMAT, sent|optional },
1250     { WM_QUERYUISTATE, sent|optional },
1251     { WM_WINDOWPOSCHANGING, sent|optional },
1252     { WM_GETMINMAXINFO, sent|optional },
1253     { WM_NCCALCSIZE, sent|optional },
1254     { WM_WINDOWPOSCHANGED, sent|optional },
1255     { WM_SHOWWINDOW, sent|wparam, 1 },
1256     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1257     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1258     { HCBT_ACTIVATE, hook },
1259     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1260
1261
1262     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1263
1264     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1265
1266     { WM_NCACTIVATE, sent },
1267     { WM_GETTEXT, sent|optional|defwinproc },
1268     { WM_GETTEXT, sent|optional|defwinproc },
1269     { WM_GETTEXT, sent|optional|defwinproc },
1270     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1271     { WM_ACTIVATE, sent|wparam, 1 },
1272     { WM_GETTEXT, sent|optional },
1273     { WM_KILLFOCUS, sent|parent },
1274     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1275     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1276     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1277     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1278     { WM_SETFOCUS, sent },
1279     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1280     { WM_NCPAINT, sent|wparam, 1 },
1281     { WM_GETTEXT, sent|optional|defwinproc },
1282     { WM_GETTEXT, sent|optional|defwinproc },
1283     { WM_ERASEBKGND, sent },
1284     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1285     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1286     { WM_GETTEXT, sent|optional },
1287     { WM_GETTEXT, sent|optional },
1288     { WM_NCCALCSIZE, sent|optional },
1289     { WM_NCPAINT, sent|optional },
1290     { WM_GETTEXT, sent|optional|defwinproc },
1291     { WM_GETTEXT, sent|optional|defwinproc },
1292     { WM_ERASEBKGND, sent|optional },
1293     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1294     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1295     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1296     { WM_MOVE, sent },
1297     { 0 }
1298 };
1299 /* Calling EndDialog for a custom dialog (32) */
1300 static const struct message WmEndCustomDialogSeq[] = {
1301     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1302     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1303     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1304     { WM_GETTEXT, sent|optional },
1305     { HCBT_ACTIVATE, hook },
1306     { WM_NCACTIVATE, sent|wparam, 0 },
1307     { WM_GETTEXT, sent|optional|defwinproc },
1308     { WM_GETTEXT, sent|optional|defwinproc },
1309     { WM_ACTIVATE, sent|wparam, 0 },
1310     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1311     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1312     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1313     { WM_GETTEXT, sent|optional|defwinproc },
1314     { WM_GETTEXT, sent|optional|defwinproc },
1315     { HCBT_SETFOCUS, hook },
1316     { WM_KILLFOCUS, sent },
1317     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1318     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1319     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1320     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1321     { WM_SETFOCUS, sent|parent|defwinproc },
1322     { 0 }
1323 };
1324 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1325 static const struct message WmShowCustomDialogSeq[] = {
1326     { WM_SHOWWINDOW, sent|wparam, 1 },
1327     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1328     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1329     { HCBT_ACTIVATE, hook },
1330     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1331
1332     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1333
1334     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1335     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1336     { WM_NCACTIVATE, sent },
1337     { WM_ACTIVATE, sent|wparam, 1 },
1338     { WM_GETTEXT, sent|optional },
1339
1340     { WM_KILLFOCUS, sent|parent },
1341     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1342     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1343     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1344     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1345     { WM_SETFOCUS, sent },
1346     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1347     { WM_NCPAINT, sent|wparam, 1 },
1348     { WM_ERASEBKGND, sent },
1349     { WM_CTLCOLORDLG, sent|defwinproc },
1350     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1351     { 0 }
1352 };
1353 /* Creation and destruction of a modal dialog (32) */
1354 static const struct message WmModalDialogSeq[] = {
1355     { WM_CANCELMODE, sent|parent },
1356     { HCBT_SETFOCUS, hook },
1357     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1358     { WM_KILLFOCUS, sent|parent },
1359     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1360     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1361     { WM_ENABLE, sent|parent|wparam, 0 },
1362     { HCBT_CREATEWND, hook },
1363     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1364     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1365     { WM_SETFONT, sent },
1366     { WM_INITDIALOG, sent },
1367     { WM_CHANGEUISTATE, sent|optional },
1368     { WM_UPDATEUISTATE, sent|optional },
1369     { WM_SHOWWINDOW, sent },
1370     { HCBT_ACTIVATE, hook },
1371     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1372     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1373     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1374     { WM_NCACTIVATE, sent },
1375     { WM_GETTEXT, sent|optional },
1376     { WM_ACTIVATE, sent|wparam, 1 },
1377     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1378     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1379     { WM_NCPAINT, sent|optional },
1380     { WM_GETTEXT, sent|optional },
1381     { WM_ERASEBKGND, sent|optional },
1382     { WM_CTLCOLORDLG, sent|optional },
1383     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1384     { WM_GETTEXT, sent|optional },
1385     { WM_NCCALCSIZE, sent|optional },
1386     { WM_NCPAINT, sent|optional },
1387     { WM_GETTEXT, sent|optional },
1388     { WM_ERASEBKGND, sent|optional },
1389     { WM_CTLCOLORDLG, sent|optional },
1390     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1391     { WM_PAINT, sent|optional },
1392     { WM_CTLCOLORBTN, sent|optional },
1393     { WM_GETTITLEBARINFOEX, sent|optional },
1394     { WM_ENTERIDLE, sent|parent|optional },
1395     { WM_ENTERIDLE, sent|parent|optional },
1396     { WM_ENTERIDLE, sent|parent|optional },
1397     { WM_ENTERIDLE, sent|parent|optional },
1398     { WM_ENTERIDLE, sent|parent|optional },
1399     { WM_ENTERIDLE, sent|parent|optional },
1400     { WM_ENTERIDLE, sent|parent|optional },
1401     { WM_ENTERIDLE, sent|parent|optional },
1402     { WM_ENTERIDLE, sent|parent|optional },
1403     { WM_ENTERIDLE, sent|parent|optional },
1404     { WM_ENTERIDLE, sent|parent|optional },
1405     { WM_ENTERIDLE, sent|parent|optional },
1406     { WM_ENTERIDLE, sent|parent|optional },
1407     { WM_ENTERIDLE, sent|parent|optional },
1408     { WM_ENTERIDLE, sent|parent|optional },
1409     { WM_ENTERIDLE, sent|parent|optional },
1410     { WM_ENTERIDLE, sent|parent|optional },
1411     { WM_ENTERIDLE, sent|parent|optional },
1412     { WM_ENTERIDLE, sent|parent|optional },
1413     { WM_ENTERIDLE, sent|parent|optional },
1414     { WM_TIMER, sent },
1415     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1416     { WM_ENABLE, sent|parent|wparam, 1 },
1417     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1418     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1419     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1420     { WM_GETTEXT, sent|optional },
1421     { HCBT_ACTIVATE, hook },
1422     { WM_NCACTIVATE, sent|wparam, 0 },
1423     { WM_GETTEXT, sent|optional },
1424     { WM_ACTIVATE, sent|wparam, 0 },
1425     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1426     { WM_WINDOWPOSCHANGING, sent|optional },
1427     { WM_WINDOWPOSCHANGED, sent|optional },
1428     { HCBT_SETFOCUS, hook },
1429     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1430     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1431     { WM_SETFOCUS, sent|parent|defwinproc },
1432     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1433     { HCBT_DESTROYWND, hook },
1434     { 0x0090, sent|optional },
1435     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1436     { WM_DESTROY, sent },
1437     { WM_NCDESTROY, sent },
1438     { 0 }
1439 };
1440 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1441 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1442     /* (inside dialog proc, handling WM_INITDIALOG) */
1443     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1444     { WM_NCCALCSIZE, sent },
1445     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1446     { WM_GETTEXT, sent|defwinproc },
1447     { WM_ACTIVATE, sent|parent|wparam, 0 },
1448     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1449     { WM_WINDOWPOSCHANGING, sent|parent },
1450     { WM_NCACTIVATE, sent|wparam, 1 },
1451     { WM_ACTIVATE, sent|wparam, 1 },
1452     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1453     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1454     /* (setting focus) */
1455     { WM_SHOWWINDOW, sent|wparam, 1 },
1456     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1457     { WM_NCPAINT, sent },
1458     { WM_GETTEXT, sent|defwinproc },
1459     { WM_ERASEBKGND, sent },
1460     { WM_CTLCOLORDLG, sent|defwinproc },
1461     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1462     { WM_PAINT, sent },
1463     /* (bunch of WM_CTLCOLOR* for each control) */
1464     { WM_PAINT, sent|parent },
1465     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1466     { WM_SETCURSOR, sent|parent },
1467     { 0 }
1468 };
1469 /* SetMenu for NonVisible windows with size change*/
1470 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1471     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1472     { WM_NCCALCSIZE, sent|wparam, 1 },
1473     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1474     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1475     { WM_MOVE, sent|defwinproc },
1476     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1477     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1478     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1479     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1480     { WM_GETTEXT, sent|optional },
1481     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1482     { 0 }
1483 };
1484 /* SetMenu for NonVisible windows with no size change */
1485 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1486     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1487     { WM_NCCALCSIZE, sent|wparam, 1 },
1488     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1489     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1490     { 0 }
1491 };
1492 /* SetMenu for Visible windows with size change */
1493 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1494     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1495     { WM_NCCALCSIZE, sent|wparam, 1 },
1496     { 0x0093, sent|defwinproc|optional },
1497     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1498     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1499     { 0x0093, sent|defwinproc|optional },
1500     { 0x0093, sent|defwinproc|optional },
1501     { 0x0091, sent|defwinproc|optional },
1502     { 0x0092, sent|defwinproc|optional },
1503     { WM_GETTEXT, sent|defwinproc|optional },
1504     { WM_ERASEBKGND, sent|optional },
1505     { WM_ACTIVATE, sent|optional },
1506     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1507     { WM_MOVE, sent|defwinproc },
1508     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1509     { 0x0093, sent|optional },
1510     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1511     { 0x0093, sent|defwinproc|optional },
1512     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1513     { 0x0093, sent|defwinproc|optional },
1514     { 0x0093, sent|defwinproc|optional },
1515     { 0x0091, sent|defwinproc|optional },
1516     { 0x0092, sent|defwinproc|optional },
1517     { WM_ERASEBKGND, sent|optional },
1518     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1519     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1520     { 0 }
1521 };
1522 /* SetMenu for Visible windows with no size change */
1523 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1524     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1525     { WM_NCCALCSIZE, sent|wparam, 1 },
1526     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1527     { WM_GETTEXT, sent|defwinproc|optional },
1528     { WM_ERASEBKGND, sent|optional },
1529     { WM_ACTIVATE, sent|optional },
1530     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1531     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1532     { 0 }
1533 };
1534 /* DrawMenuBar for a visible window */
1535 static const struct message WmDrawMenuBarSeq[] =
1536 {
1537     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1538     { WM_NCCALCSIZE, sent|wparam, 1 },
1539     { 0x0093, sent|defwinproc|optional },
1540     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1541     { 0x0093, sent|defwinproc|optional },
1542     { 0x0093, sent|defwinproc|optional },
1543     { 0x0091, sent|defwinproc|optional },
1544     { 0x0092, sent|defwinproc|optional },
1545     { WM_GETTEXT, sent|defwinproc|optional },
1546     { WM_ERASEBKGND, sent|optional },
1547     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1548     { 0x0093, sent|optional },
1549     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1550     { 0 }
1551 };
1552
1553 static const struct message WmSetRedrawFalseSeq[] =
1554 {
1555     { WM_SETREDRAW, sent|wparam, 0 },
1556     { 0 }
1557 };
1558
1559 static const struct message WmSetRedrawTrueSeq[] =
1560 {
1561     { WM_SETREDRAW, sent|wparam, 1 },
1562     { 0 }
1563 };
1564
1565 static const struct message WmEnableWindowSeq_1[] =
1566 {
1567     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1568     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1569     { HCBT_SETFOCUS, hook|optional },
1570     { WM_KILLFOCUS, sent|optional },
1571     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1572     { 0 }
1573 };
1574
1575 static const struct message WmEnableWindowSeq_2[] =
1576 {
1577     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1578     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1579     { 0 }
1580 };
1581
1582 static const struct message WmGetScrollRangeSeq[] =
1583 {
1584     { SBM_GETRANGE, sent },
1585     { 0 }
1586 };
1587 static const struct message WmGetScrollInfoSeq[] =
1588 {
1589     { SBM_GETSCROLLINFO, sent },
1590     { 0 }
1591 };
1592 static const struct message WmSetScrollRangeSeq[] =
1593 {
1594     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1595        sends SBM_SETSCROLLINFO.
1596      */
1597     { SBM_SETSCROLLINFO, sent },
1598     { 0 }
1599 };
1600 /* SetScrollRange for a window without a non-client area */
1601 static const struct message WmSetScrollRangeHSeq_empty[] =
1602 {
1603     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1604     { 0 }
1605 };
1606 static const struct message WmSetScrollRangeVSeq_empty[] =
1607 {
1608     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1609     { 0 }
1610 };
1611 static const struct message WmSetScrollRangeHVSeq[] =
1612 {
1613     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1614     { WM_NCCALCSIZE, sent|wparam, 1 },
1615     { WM_GETTEXT, sent|defwinproc|optional },
1616     { WM_ERASEBKGND, sent|optional },
1617     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1618     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1619     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1620     { 0 }
1621 };
1622 /* SetScrollRange for a window with a non-client area */
1623 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1624 {
1625     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1626     { WM_NCCALCSIZE, sent|wparam, 1 },
1627     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1628     { WM_NCPAINT, sent|optional },
1629     { WM_STYLECHANGING, sent|defwinproc|optional },
1630     { WM_STYLECHANGED, sent|defwinproc|optional },
1631     { WM_STYLECHANGING, sent|defwinproc|optional },
1632     { WM_STYLECHANGED, sent|defwinproc|optional },
1633     { WM_STYLECHANGING, sent|defwinproc|optional },
1634     { WM_STYLECHANGED, sent|defwinproc|optional },
1635     { WM_STYLECHANGING, sent|defwinproc|optional },
1636     { WM_STYLECHANGED, sent|defwinproc|optional },
1637     { WM_GETTEXT, sent|defwinproc|optional },
1638     { WM_GETTEXT, sent|defwinproc|optional },
1639     { WM_ERASEBKGND, sent|optional },
1640     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1641     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1642     { WM_SIZE, sent|defwinproc|optional },
1643     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1644     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1645     { WM_GETTEXT, sent|optional },
1646     { WM_GETTEXT, sent|optional },
1647     { WM_GETTEXT, sent|optional },
1648     { WM_GETTEXT, sent|optional },
1649     { 0 }
1650 };
1651 /* test if we receive the right sequence of messages */
1652 /* after calling ShowWindow( SW_SHOWNA) */
1653 static const struct message WmSHOWNAChildInvisParInvis[] = {
1654     { WM_SHOWWINDOW, sent|wparam, 1 },
1655     { 0 }
1656 };
1657 static const struct message WmSHOWNAChildVisParInvis[] = {
1658     { WM_SHOWWINDOW, sent|wparam, 1 },
1659     { 0 }
1660 };
1661 static const struct message WmSHOWNAChildVisParVis[] = {
1662     { WM_SHOWWINDOW, sent|wparam, 1 },
1663     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1664     { 0 }
1665 };
1666 static const struct message WmSHOWNAChildInvisParVis[] = {
1667     { WM_SHOWWINDOW, sent|wparam, 1 },
1668     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1669     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1670     { WM_ERASEBKGND, sent|optional },
1671     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1672     { 0 }
1673 };
1674 static const struct message WmSHOWNATopVisible[] = {
1675     { WM_SHOWWINDOW, sent|wparam, 1 },
1676     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1677     { WM_NCPAINT, sent|wparam|optional, 1 },
1678     { WM_GETTEXT, sent|defwinproc|optional },
1679     { WM_ERASEBKGND, sent|optional },
1680     { WM_WINDOWPOSCHANGED, sent|optional },
1681     { 0 }
1682 };
1683 static const struct message WmSHOWNATopInvisible[] = {
1684     { WM_NOTIFYFORMAT, sent|optional },
1685     { WM_QUERYUISTATE, sent|optional },
1686     { WM_WINDOWPOSCHANGING, sent|optional },
1687     { WM_GETMINMAXINFO, sent|optional },
1688     { WM_NCCALCSIZE, sent|optional },
1689     { WM_WINDOWPOSCHANGED, sent|optional },
1690     { WM_SHOWWINDOW, sent|wparam, 1 },
1691     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1692     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1693     { WM_NCPAINT, sent|wparam|optional, 1 },
1694     { WM_GETTEXT, sent|defwinproc|optional },
1695     { WM_ERASEBKGND, sent|optional },
1696     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1697     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1698     { WM_NCPAINT, sent|wparam|optional, 1 },
1699     { WM_ERASEBKGND, sent|optional },
1700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1701     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1702     { WM_MOVE, sent },
1703     { 0 }
1704 };
1705
1706 static int after_end_dialog, test_def_id;
1707 static int sequence_cnt, sequence_size;
1708 static struct recvd_message* sequence;
1709 static int log_all_parent_messages;
1710 static int paint_loop_done;
1711
1712 /* user32 functions */
1713 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1714 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1715 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1716 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1717 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1718 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1719 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1720 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
1721 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
1722 /* kernel32 functions */
1723 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1724
1725 static void init_procs(void)
1726 {
1727     HMODULE user32 = GetModuleHandleA("user32.dll");
1728     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1729
1730 #define GET_PROC(dll, func) \
1731     p ## func = (void*)GetProcAddress(dll, #func); \
1732     if(!p ## func) { \
1733       trace("GetProcAddress(%s) failed\n", #func); \
1734     }
1735
1736     GET_PROC(user32, GetAncestor)
1737     GET_PROC(user32, GetMenuInfo)
1738     GET_PROC(user32, NotifyWinEvent)
1739     GET_PROC(user32, SetMenuInfo)
1740     GET_PROC(user32, SetWinEventHook)
1741     GET_PROC(user32, TrackMouseEvent)
1742     GET_PROC(user32, UnhookWinEvent)
1743     GET_PROC(user32, GetMonitorInfoA)
1744     GET_PROC(user32, MonitorFromPoint)
1745
1746     GET_PROC(kernel32, GetCPInfoExA)
1747
1748 #undef GET_PROC
1749 }
1750
1751 static const char *get_winpos_flags(UINT flags)
1752 {
1753     static char buffer[300];
1754
1755     buffer[0] = 0;
1756 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1757     DUMP( SWP_SHOWWINDOW );
1758     DUMP( SWP_HIDEWINDOW );
1759     DUMP( SWP_NOACTIVATE );
1760     DUMP( SWP_FRAMECHANGED );
1761     DUMP( SWP_NOCOPYBITS );
1762     DUMP( SWP_NOOWNERZORDER );
1763     DUMP( SWP_NOSENDCHANGING );
1764     DUMP( SWP_DEFERERASE );
1765     DUMP( SWP_ASYNCWINDOWPOS );
1766     DUMP( SWP_NOZORDER );
1767     DUMP( SWP_NOREDRAW );
1768     DUMP( SWP_NOSIZE );
1769     DUMP( SWP_NOMOVE );
1770     DUMP( SWP_NOCLIENTSIZE );
1771     DUMP( SWP_NOCLIENTMOVE );
1772     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1773     return buffer + 1;
1774 #undef DUMP
1775 }
1776
1777 static BOOL ignore_message( UINT message )
1778 {
1779     /* these are always ignored */
1780     return (message >= 0xc000 ||
1781             message == WM_GETICON ||
1782             message == WM_GETOBJECT ||
1783             message == WM_TIMECHANGE ||
1784             message == WM_DISPLAYCHANGE ||
1785             message == WM_DEVICECHANGE ||
1786             message == WM_DWMNCRENDERINGCHANGED);
1787 }
1788
1789
1790 #define add_message(msg) add_message_(__LINE__,msg);
1791 static void add_message_(int line, const struct recvd_message *msg)
1792 {
1793     struct recvd_message *seq;
1794
1795     if (!sequence) 
1796     {
1797         sequence_size = 10;
1798         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1799     }
1800     if (sequence_cnt == sequence_size) 
1801     {
1802         sequence_size *= 2;
1803         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1804     }
1805     assert(sequence);
1806
1807     seq = &sequence[sequence_cnt];
1808     seq->hwnd = msg->hwnd;
1809     seq->message = msg->message;
1810     seq->flags = msg->flags;
1811     seq->wParam = msg->wParam;
1812     seq->lParam = msg->lParam;
1813     seq->line   = line;
1814     seq->descr  = msg->descr;
1815     seq->output[0] = 0;
1816
1817     if (msg->descr)
1818     {
1819         if (msg->flags & hook)
1820         {
1821             static const char * const CBT_code_name[10] =
1822             {
1823                 "HCBT_MOVESIZE",
1824                 "HCBT_MINMAX",
1825                 "HCBT_QS",
1826                 "HCBT_CREATEWND",
1827                 "HCBT_DESTROYWND",
1828                 "HCBT_ACTIVATE",
1829                 "HCBT_CLICKSKIPPED",
1830                 "HCBT_KEYSKIPPED",
1831                 "HCBT_SYSCOMMAND",
1832                 "HCBT_SETFOCUS"
1833             };
1834             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1835
1836             sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1837                      msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1838         }
1839         else if (msg->flags & winevent_hook)
1840         {
1841             sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1842                      msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1843         }
1844         else
1845         {
1846             switch (msg->message)
1847             {
1848             case WM_WINDOWPOSCHANGING:
1849             case WM_WINDOWPOSCHANGED:
1850             {
1851                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1852
1853                 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1854                           msg->descr, msg->hwnd,
1855                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1856                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1857                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1858                           get_winpos_flags(winpos->flags) );
1859
1860                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1861                  * in the high word for internal purposes
1862                  */
1863                 seq->wParam = winpos->flags & 0xffff;
1864                 /* We are not interested in the flags that don't match under XP and Win9x */
1865                 seq->wParam &= ~SWP_NOZORDER;
1866                 break;
1867             }
1868
1869             case WM_DRAWITEM:
1870             {
1871                 DRAW_ITEM_STRUCT di;
1872                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1873
1874                 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1875                          msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1876                          dis->itemID, dis->itemAction, dis->itemState);
1877
1878                 di.u.lp = 0;
1879                 di.u.item.type = dis->CtlType;
1880                 di.u.item.ctl_id = dis->CtlID;
1881                 if (dis->CtlType == ODT_LISTBOX ||
1882                     dis->CtlType == ODT_COMBOBOX ||
1883                     dis->CtlType == ODT_MENU)
1884                     di.u.item.item_id = dis->itemID;
1885                 di.u.item.action = dis->itemAction;
1886                 di.u.item.state = dis->itemState;
1887
1888                 seq->lParam = di.u.lp;
1889                 break;
1890             }
1891             default:
1892                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1893                 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1894                          msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1895             }
1896             if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1897                 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1898         }
1899     }
1900
1901     sequence_cnt++;
1902 }
1903
1904 /* try to make sure pending X events have been processed before continuing */
1905 static void flush_events(void)
1906 {
1907     MSG msg;
1908     int diff = 200;
1909     int min_timeout = 100;
1910     DWORD time = GetTickCount() + diff;
1911
1912     while (diff > 0)
1913     {
1914         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1915         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1916         diff = time - GetTickCount();
1917     }
1918 }
1919
1920 static void flush_sequence(void)
1921 {
1922     HeapFree(GetProcessHeap(), 0, sequence);
1923     sequence = 0;
1924     sequence_cnt = sequence_size = 0;
1925 }
1926
1927 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1928 {
1929     const struct recvd_message *actual = sequence;
1930     unsigned int count = 0;
1931
1932     trace_(file, line)("Failed sequence %s:\n", context );
1933     while (expected->message && actual->message)
1934     {
1935         if (actual->output[0])
1936         {
1937             if (expected->flags & hook)
1938             {
1939                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1940                                     count, expected->message, actual->output );
1941             }
1942             else if (expected->flags & winevent_hook)
1943             {
1944                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1945                                     count, expected->message, actual->output );
1946             }
1947             else
1948             {
1949                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1950                                     count, expected->message, actual->output );
1951             }
1952         }
1953
1954         if (expected->message == actual->message)
1955         {
1956             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1957                 (expected->flags & optional))
1958             {
1959                 /* don't match messages if their defwinproc status differs */
1960                 expected++;
1961             }
1962             else
1963             {
1964                 expected++;
1965                 actual++;
1966             }
1967         }
1968         /* silently drop winevent messages if there is no support for them */
1969         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1970             expected++;
1971         else
1972         {
1973             expected++;
1974             actual++;
1975         }
1976         count++;
1977     }
1978
1979     /* optional trailing messages */
1980     while (expected->message && ((expected->flags & optional) ||
1981             ((expected->flags & winevent_hook) && !hEvent_hook)))
1982     {
1983         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1984         expected++;
1985         count++;
1986     }
1987
1988     if (expected->message)
1989     {
1990         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1991         return;
1992     }
1993
1994     while (actual->message && actual->output[0])
1995     {
1996         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1997         actual++;
1998         count++;
1999     }
2000 }
2001
2002 #define ok_sequence( exp, contx, todo) \
2003         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2004
2005
2006 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2007                          const char *file, int line)
2008 {
2009     static const struct recvd_message end_of_sequence;
2010     const struct message *expected = expected_list;
2011     const struct recvd_message *actual;
2012     int failcount = 0, dump = 0;
2013     unsigned int count = 0;
2014
2015     add_message(&end_of_sequence);
2016
2017     actual = sequence;
2018
2019     while (expected->message && actual->message)
2020     {
2021         if (expected->message == actual->message)
2022         {
2023             if (expected->flags & wparam)
2024             {
2025                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2026                 {
2027                     todo_wine {
2028                         failcount ++;
2029                         if (strcmp(winetest_platform, "wine")) dump++;
2030                         ok_( file, line) (FALSE,
2031                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2032                             context, count, expected->message, expected->wParam, actual->wParam);
2033                     }
2034                 }
2035                 else
2036                 {
2037                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2038                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2039                                      context, count, expected->message, expected->wParam, actual->wParam);
2040                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2041                 }
2042
2043             }
2044             if (expected->flags & lparam)
2045             {
2046                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2047                 {
2048                     todo_wine {
2049                         failcount ++;
2050                         if (strcmp(winetest_platform, "wine")) dump++;
2051                         ok_( file, line) (FALSE,
2052                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2053                             context, count, expected->message, expected->lParam, actual->lParam);
2054                     }
2055                 }
2056                 else
2057                 {
2058                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2059                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2060                                      context, count, expected->message, expected->lParam, actual->lParam);
2061                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2062                 }
2063             }
2064             if ((expected->flags & optional) &&
2065                 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2066             {
2067                 /* don't match optional messages if their defwinproc or parent status differs */
2068                 expected++;
2069                 count++;
2070                 continue;
2071             }
2072             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2073             {
2074                     todo_wine {
2075                         failcount ++;
2076                         if (strcmp(winetest_platform, "wine")) dump++;
2077                         ok_( file, line) (FALSE,
2078                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2079                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2080                     }
2081             }
2082             else
2083             {
2084                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2085                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2086                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2087                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2088             }
2089
2090             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2091                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2092                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2093             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2094
2095             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2096                 "%s: %u: the msg 0x%04x should have been %s\n",
2097                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2098             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2099
2100             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2101                 "%s: %u: the msg 0x%04x was expected in %s\n",
2102                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2103             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2104
2105             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2106                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2107                 context, count, expected->message);
2108             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2109
2110             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2111                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2112                 context, count, expected->message);
2113             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2114
2115             expected++;
2116             actual++;
2117         }
2118         /* silently drop hook messages if there is no support for them */
2119         else if ((expected->flags & optional) ||
2120                  ((expected->flags & hook) && !hCBT_hook) ||
2121                  ((expected->flags & winevent_hook) && !hEvent_hook))
2122             expected++;
2123         else if (todo)
2124         {
2125             failcount++;
2126             todo_wine {
2127                 if (strcmp(winetest_platform, "wine")) dump++;
2128                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2129                                   context, count, expected->message, actual->message);
2130             }
2131             goto done;
2132         }
2133         else
2134         {
2135             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2136                               context, count, expected->message, actual->message);
2137             dump++;
2138             expected++;
2139             actual++;
2140         }
2141         count++;
2142     }
2143
2144     /* skip all optional trailing messages */
2145     while (expected->message && ((expected->flags & optional) ||
2146                                  ((expected->flags & hook) && !hCBT_hook) ||
2147                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2148         expected++;
2149
2150     if (todo)
2151     {
2152         todo_wine {
2153             if (expected->message || actual->message) {
2154                 failcount++;
2155                 if (strcmp(winetest_platform, "wine")) dump++;
2156                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2157                                   context, count, expected->message, actual->message);
2158             }
2159         }
2160     }
2161     else
2162     {
2163         if (expected->message || actual->message)
2164         {
2165             dump++;
2166             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2167                               context, count, expected->message, actual->message);
2168         }
2169     }
2170     if( todo && !failcount) /* succeeded yet marked todo */
2171         todo_wine {
2172             if (!strcmp(winetest_platform, "wine")) dump++;
2173             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2174         }
2175
2176 done:
2177     if (dump) dump_sequence(expected_list, context, file, line);
2178     flush_sequence();
2179 }
2180
2181 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2182
2183 /******************************** MDI test **********************************/
2184
2185 /* CreateWindow for MDI frame window, initially visible */
2186 static const struct message WmCreateMDIframeSeq[] = {
2187     { HCBT_CREATEWND, hook },
2188     { WM_GETMINMAXINFO, sent },
2189     { WM_NCCREATE, sent },
2190     { WM_NCCALCSIZE, sent|wparam, 0 },
2191     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2192     { WM_CREATE, sent },
2193     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2194     { WM_NOTIFYFORMAT, sent|optional },
2195     { WM_QUERYUISTATE, sent|optional },
2196     { WM_WINDOWPOSCHANGING, sent|optional },
2197     { WM_GETMINMAXINFO, sent|optional },
2198     { WM_NCCALCSIZE, sent|optional },
2199     { WM_WINDOWPOSCHANGED, sent|optional },
2200     { WM_SHOWWINDOW, sent|wparam, 1 },
2201     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2202     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2203     { HCBT_ACTIVATE, hook },
2204     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2205     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2206     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2207     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2208     { WM_NCACTIVATE, sent },
2209     { WM_GETTEXT, sent|defwinproc|optional },
2210     { WM_ACTIVATE, sent|wparam, 1 },
2211     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2212     { HCBT_SETFOCUS, hook },
2213     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2214     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2215     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2216     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2217     /* Win9x adds SWP_NOZORDER below */
2218     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2219     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2220     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2221     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2222     { WM_MOVE, sent },
2223     { 0 }
2224 };
2225 /* DestroyWindow for MDI frame window, initially visible */
2226 static const struct message WmDestroyMDIframeSeq[] = {
2227     { HCBT_DESTROYWND, hook },
2228     { 0x0090, sent|optional },
2229     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2230     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2231     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2232     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2233     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2234     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2235     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2236     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2237     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2238     { WM_DESTROY, sent },
2239     { WM_NCDESTROY, sent },
2240     { 0 }
2241 };
2242 /* CreateWindow for MDI client window, initially visible */
2243 static const struct message WmCreateMDIclientSeq[] = {
2244     { HCBT_CREATEWND, hook },
2245     { WM_NCCREATE, sent },
2246     { WM_NCCALCSIZE, sent|wparam, 0 },
2247     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2248     { WM_CREATE, sent },
2249     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2250     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2251     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2252     { WM_MOVE, sent },
2253     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2254     { WM_SHOWWINDOW, sent|wparam, 1 },
2255     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2256     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2257     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2258     { 0 }
2259 };
2260 /* ShowWindow(SW_SHOW) for MDI client window */
2261 static const struct message WmShowMDIclientSeq[] = {
2262     { WM_SHOWWINDOW, sent|wparam, 1 },
2263     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2264     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2265     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2266     { 0 }
2267 };
2268 /* ShowWindow(SW_HIDE) for MDI client window */
2269 static const struct message WmHideMDIclientSeq[] = {
2270     { WM_SHOWWINDOW, sent|wparam, 0 },
2271     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2272     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2273     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2274     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2275     { 0 }
2276 };
2277 /* DestroyWindow for MDI client window, initially visible */
2278 static const struct message WmDestroyMDIclientSeq[] = {
2279     { HCBT_DESTROYWND, hook },
2280     { 0x0090, sent|optional },
2281     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2282     { WM_SHOWWINDOW, sent|wparam, 0 },
2283     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2284     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2285     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2286     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2287     { WM_DESTROY, sent },
2288     { WM_NCDESTROY, sent },
2289     { 0 }
2290 };
2291 /* CreateWindow for MDI child window, initially visible */
2292 static const struct message WmCreateMDIchildVisibleSeq[] = {
2293     { HCBT_CREATEWND, hook },
2294     { WM_NCCREATE, sent }, 
2295     { WM_NCCALCSIZE, sent|wparam, 0 },
2296     { WM_CREATE, sent },
2297     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2298     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2299     { WM_MOVE, sent },
2300     /* Win2k sends wparam set to
2301      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2302      * while Win9x doesn't bother to set child window id according to
2303      * CLIENTCREATESTRUCT.idFirstChild
2304      */
2305     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2306     { WM_SHOWWINDOW, sent|wparam, 1 },
2307     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2308     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2309     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2310     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2311     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2312     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2313     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2314
2315     /* Win9x: message sequence terminates here. */
2316
2317     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2318     { HCBT_SETFOCUS, hook }, /* in MDI client */
2319     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2320     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2321     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2322     { WM_SETFOCUS, sent }, /* in MDI client */
2323     { HCBT_SETFOCUS, hook },
2324     { WM_KILLFOCUS, sent }, /* in MDI client */
2325     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2326     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2327     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2328     { WM_SETFOCUS, sent|defwinproc },
2329     { WM_MDIACTIVATE, sent|defwinproc },
2330     { 0 }
2331 };
2332 /* CreateWindow for MDI child window with invisible parent */
2333 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2334     { HCBT_CREATEWND, hook },
2335     { WM_GETMINMAXINFO, sent },
2336     { WM_NCCREATE, sent }, 
2337     { WM_NCCALCSIZE, sent|wparam, 0 },
2338     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2339     { WM_CREATE, sent },
2340     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2341     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2342     { WM_MOVE, sent },
2343     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2344     { WM_SHOWWINDOW, sent|wparam, 1 },
2345     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2346     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2347     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2348     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2349
2350     /* Win9x: message sequence terminates here. */
2351
2352     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2353     { HCBT_SETFOCUS, hook }, /* in MDI client */
2354     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2355     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2356     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2357     { WM_SETFOCUS, sent }, /* in MDI client */
2358     { HCBT_SETFOCUS, hook },
2359     { WM_KILLFOCUS, sent }, /* in MDI client */
2360     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2361     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2362     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2363     { WM_SETFOCUS, sent|defwinproc },
2364     { WM_MDIACTIVATE, sent|defwinproc },
2365     { 0 }
2366 };
2367 /* DestroyWindow for MDI child window, initially visible */
2368 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2369     { HCBT_DESTROYWND, hook },
2370     /* Win2k sends wparam set to
2371      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2372      * while Win9x doesn't bother to set child window id according to
2373      * CLIENTCREATESTRUCT.idFirstChild
2374      */
2375     { 0x0090, sent|optional },
2376     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2377     { WM_SHOWWINDOW, sent|wparam, 0 },
2378     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2379     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2380     { WM_ERASEBKGND, sent|parent|optional },
2381     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2382
2383     /* { WM_DESTROY, sent }
2384      * Win9x: message sequence terminates here.
2385      */
2386
2387     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2388     { WM_KILLFOCUS, sent },
2389     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2390     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2391     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2392     { WM_SETFOCUS, sent }, /* in MDI client */
2393
2394     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2395     { WM_KILLFOCUS, sent }, /* in MDI client */
2396     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2397     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2398     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2399     { WM_SETFOCUS, sent }, /* in MDI client */
2400
2401     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2402
2403     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2404     { WM_KILLFOCUS, sent },
2405     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2406     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2407     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2408     { WM_SETFOCUS, sent }, /* in MDI client */
2409
2410     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2411     { WM_KILLFOCUS, sent }, /* in MDI client */
2412     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2413     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2414     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2415     { WM_SETFOCUS, sent }, /* in MDI client */
2416
2417     { WM_DESTROY, sent },
2418
2419     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2420     { WM_KILLFOCUS, sent },
2421     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2422     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2423     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2424     { WM_SETFOCUS, sent }, /* in MDI client */
2425
2426     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2427     { WM_KILLFOCUS, sent }, /* in MDI client */
2428     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2429     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2430     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2431     { WM_SETFOCUS, sent }, /* in MDI client */
2432
2433     { WM_NCDESTROY, sent },
2434     { 0 }
2435 };
2436 /* CreateWindow for MDI child window, initially invisible */
2437 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2438     { HCBT_CREATEWND, hook },
2439     { WM_NCCREATE, sent }, 
2440     { WM_NCCALCSIZE, sent|wparam, 0 },
2441     { WM_CREATE, sent },
2442     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2443     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2444     { WM_MOVE, sent },
2445     /* Win2k sends wparam set to
2446      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2447      * while Win9x doesn't bother to set child window id according to
2448      * CLIENTCREATESTRUCT.idFirstChild
2449      */
2450     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2451     { 0 }
2452 };
2453 /* DestroyWindow for MDI child window, initially invisible */
2454 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2455     { HCBT_DESTROYWND, hook },
2456     /* Win2k sends wparam set to
2457      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2458      * while Win9x doesn't bother to set child window id according to
2459      * CLIENTCREATESTRUCT.idFirstChild
2460      */
2461     { 0x0090, sent|optional },
2462     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2463     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2464     { WM_DESTROY, sent },
2465     { WM_NCDESTROY, sent },
2466     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2467     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2468     { 0 }
2469 };
2470 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2471 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2472     { HCBT_CREATEWND, hook },
2473     { WM_NCCREATE, sent }, 
2474     { WM_NCCALCSIZE, sent|wparam, 0 },
2475     { WM_CREATE, sent },
2476     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2477     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2478     { WM_MOVE, sent },
2479     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2480     { WM_GETMINMAXINFO, sent },
2481     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2482     { WM_NCCALCSIZE, sent|wparam, 1 },
2483     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2484     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2485      /* in MDI frame */
2486     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2487     { WM_NCCALCSIZE, sent|wparam, 1 },
2488     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2489     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2490     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2491     /* Win2k sends wparam set to
2492      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2493      * while Win9x doesn't bother to set child window id according to
2494      * CLIENTCREATESTRUCT.idFirstChild
2495      */
2496     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2497     { WM_SHOWWINDOW, sent|wparam, 1 },
2498     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2499     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2500     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2501     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2502     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2503     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2504     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2505
2506     /* Win9x: message sequence terminates here. */
2507
2508     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2509     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2510     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2511     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2512     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2513     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2514     { HCBT_SETFOCUS, hook|optional },
2515     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2516     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2517     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2518     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2519     { WM_SETFOCUS, sent|defwinproc|optional },
2520     { WM_MDIACTIVATE, sent|defwinproc|optional },
2521      /* in MDI frame */
2522     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2523     { WM_NCCALCSIZE, sent|wparam, 1 },
2524     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2525     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2526     { 0 }
2527 };
2528 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2529 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2530     /* restore the 1st MDI child */
2531     { WM_SETREDRAW, sent|wparam, 0 },
2532     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2533     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2534     { WM_NCCALCSIZE, sent|wparam, 1 },
2535     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2536     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2537     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2538      /* in MDI frame */
2539     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2540     { WM_NCCALCSIZE, sent|wparam, 1 },
2541     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2542     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2543     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2544     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2545     /* create the 2nd MDI child */
2546     { HCBT_CREATEWND, hook },
2547     { WM_NCCREATE, sent }, 
2548     { WM_NCCALCSIZE, sent|wparam, 0 },
2549     { WM_CREATE, sent },
2550     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2551     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2552     { WM_MOVE, sent },
2553     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2554     { WM_GETMINMAXINFO, sent },
2555     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2556     { WM_NCCALCSIZE, sent|wparam, 1 },
2557     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2558     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2559     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2560      /* in MDI frame */
2561     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2562     { WM_NCCALCSIZE, sent|wparam, 1 },
2563     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2564     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2565     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2566     /* Win2k sends wparam set to
2567      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2568      * while Win9x doesn't bother to set child window id according to
2569      * CLIENTCREATESTRUCT.idFirstChild
2570      */
2571     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2572     { WM_SHOWWINDOW, sent|wparam, 1 },
2573     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2574     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2575     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2576     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2577     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2578     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2579
2580     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2581     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2582
2583     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2584
2585     /* Win9x: message sequence terminates here. */
2586
2587     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2588     { HCBT_SETFOCUS, hook },
2589     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2590     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2591     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2592     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2593     { WM_SETFOCUS, sent }, /* in MDI client */
2594     { HCBT_SETFOCUS, hook },
2595     { WM_KILLFOCUS, sent }, /* in MDI client */
2596     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2597     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2598     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2599     { WM_SETFOCUS, sent|defwinproc },
2600
2601     { WM_MDIACTIVATE, sent|defwinproc },
2602      /* in MDI frame */
2603     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2604     { WM_NCCALCSIZE, sent|wparam, 1 },
2605     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2606     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2607     { 0 }
2608 };
2609 /* WM_MDICREATE MDI child window, initially visible and maximized */
2610 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2611     { WM_MDICREATE, sent },
2612     { HCBT_CREATEWND, hook },
2613     { WM_NCCREATE, sent }, 
2614     { WM_NCCALCSIZE, sent|wparam, 0 },
2615     { WM_CREATE, sent },
2616     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2617     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2618     { WM_MOVE, sent },
2619     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2620     { WM_GETMINMAXINFO, sent },
2621     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2622     { WM_NCCALCSIZE, sent|wparam, 1 },
2623     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2624     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2625
2626      /* in MDI frame */
2627     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2628     { WM_NCCALCSIZE, sent|wparam, 1 },
2629     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2630     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2631     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2632
2633     /* Win2k sends wparam set to
2634      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2635      * while Win9x doesn't bother to set child window id according to
2636      * CLIENTCREATESTRUCT.idFirstChild
2637      */
2638     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2639     { WM_SHOWWINDOW, sent|wparam, 1 },
2640     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2641
2642     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2643
2644     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2645     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2646     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2647
2648     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2649     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2650
2651     /* Win9x: message sequence terminates here. */
2652
2653     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2654     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2655     { HCBT_SETFOCUS, hook }, /* in MDI client */
2656     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2657     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2658     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2659     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2660     { HCBT_SETFOCUS, hook|optional },
2661     { WM_KILLFOCUS, sent }, /* in MDI client */
2662     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2663     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2664     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2665     { WM_SETFOCUS, sent|defwinproc },
2666
2667     { WM_MDIACTIVATE, sent|defwinproc },
2668
2669      /* in MDI child */
2670     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2671     { WM_NCCALCSIZE, sent|wparam, 1 },
2672     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2673     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2674
2675      /* in MDI frame */
2676     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2677     { WM_NCCALCSIZE, sent|wparam, 1 },
2678     { 0x0093, sent|defwinproc|optional },
2679     { 0x0093, sent|defwinproc|optional },
2680     { 0x0093, sent|defwinproc|optional },
2681     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2682     { WM_MOVE, sent|defwinproc },
2683     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2684
2685      /* in MDI client */
2686     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2687     { WM_NCCALCSIZE, sent|wparam, 1 },
2688     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2689     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2690
2691      /* in MDI child */
2692     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2693     { WM_NCCALCSIZE, sent|wparam, 1 },
2694     { 0x0093, sent|optional },
2695     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2696     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2697
2698     { 0x0093, sent|optional },
2699     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2701     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2702     { 0x0093, sent|defwinproc|optional },
2703     { 0x0093, sent|defwinproc|optional },
2704     { 0x0093, sent|defwinproc|optional },
2705     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2706     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2707
2708     { 0 }
2709 };
2710 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2711 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2712     { HCBT_CREATEWND, hook },
2713     { WM_GETMINMAXINFO, sent },
2714     { WM_NCCREATE, sent }, 
2715     { WM_NCCALCSIZE, sent|wparam, 0 },
2716     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2717     { WM_CREATE, sent },
2718     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2719     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2720     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2721     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2722     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2723     { WM_MOVE, sent },
2724     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2725     { WM_GETMINMAXINFO, sent },
2726     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2727     { WM_GETMINMAXINFO, sent|defwinproc },
2728     { WM_NCCALCSIZE, sent|wparam, 1 },
2729     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2730     { WM_MOVE, sent|defwinproc },
2731     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2732      /* in MDI frame */
2733     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2734     { WM_NCCALCSIZE, sent|wparam, 1 },
2735     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2736     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2737     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2738     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2739     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2740     /* Win2k sends wparam set to
2741      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2742      * while Win9x doesn't bother to set child window id according to
2743      * CLIENTCREATESTRUCT.idFirstChild
2744      */
2745     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2746     { 0 }
2747 };
2748 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2749 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2750     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2751     { HCBT_SYSCOMMAND, hook },
2752     { WM_CLOSE, sent|defwinproc },
2753     { WM_MDIDESTROY, sent }, /* in MDI client */
2754
2755     /* bring the 1st MDI child to top */
2756     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2757     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2758
2759     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2760
2761     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2762     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2763     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2764
2765     /* maximize the 1st MDI child */
2766     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2767     { WM_GETMINMAXINFO, sent|defwinproc },
2768     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2769     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2770     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2771     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2772     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2773
2774     /* restore the 2nd MDI child */
2775     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2776     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2777     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2778     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2779
2780     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2781
2782     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2783     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2784
2785     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2786
2787     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2788      /* in MDI frame */
2789     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2790     { WM_NCCALCSIZE, sent|wparam, 1 },
2791     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2792     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2793     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2794
2795     /* bring the 1st MDI child to top */
2796     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2797     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2798     { HCBT_SETFOCUS, hook },
2799     { WM_KILLFOCUS, sent|defwinproc },
2800     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2801     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2802     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2803     { WM_SETFOCUS, sent }, /* in MDI client */
2804     { HCBT_SETFOCUS, hook },
2805     { WM_KILLFOCUS, sent }, /* in MDI client */
2806     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2807     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2808     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2809     { WM_SETFOCUS, sent|defwinproc },
2810     { WM_MDIACTIVATE, sent|defwinproc },
2811     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2812
2813     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2814     { WM_SHOWWINDOW, sent|wparam, 1 },
2815     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2816     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2817     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2818     { WM_MDIREFRESHMENU, sent },
2819
2820     { HCBT_DESTROYWND, hook },
2821     /* Win2k sends wparam set to
2822      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2823      * while Win9x doesn't bother to set child window id according to
2824      * CLIENTCREATESTRUCT.idFirstChild
2825      */
2826     { 0x0090, sent|defwinproc|optional },
2827     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2828     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2829     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2830     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2831     { WM_ERASEBKGND, sent|parent|optional },
2832     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2833
2834     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2835     { WM_DESTROY, sent|defwinproc },
2836     { WM_NCDESTROY, sent|defwinproc },
2837     { 0 }
2838 };
2839 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2840 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2841     { WM_MDIDESTROY, sent }, /* in MDI client */
2842     { WM_SHOWWINDOW, sent|wparam, 0 },
2843     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2844     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2845     { WM_ERASEBKGND, sent|parent|optional },
2846     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2847
2848     { HCBT_SETFOCUS, hook },
2849     { WM_KILLFOCUS, sent },
2850     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2851     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2852     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2853     { WM_SETFOCUS, sent }, /* in MDI client */
2854     { HCBT_SETFOCUS, hook },
2855     { WM_KILLFOCUS, sent }, /* in MDI client */
2856     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2857     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2858     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2859     { WM_SETFOCUS, sent },
2860
2861      /* in MDI child */
2862     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2863     { WM_NCCALCSIZE, sent|wparam, 1 },
2864     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2865     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2866
2867      /* in MDI frame */
2868     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2869     { WM_NCCALCSIZE, sent|wparam, 1 },
2870     { 0x0093, sent|defwinproc|optional },
2871     { 0x0093, sent|defwinproc|optional },
2872     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2873     { WM_MOVE, sent|defwinproc },
2874     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2875
2876      /* in MDI client */
2877     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2878     { WM_NCCALCSIZE, sent|wparam, 1 },
2879     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2880     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2881
2882      /* in MDI child */
2883     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2884     { WM_NCCALCSIZE, sent|wparam, 1 },
2885     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2886     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2887
2888      /* in MDI child */
2889     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2890     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2891     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2892     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2893
2894      /* in MDI frame */
2895     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2896     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2897     { 0x0093, sent|defwinproc|optional },
2898     { 0x0093, sent|defwinproc|optional },
2899     { 0x0093, sent|defwinproc|optional },
2900     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2901     { WM_MOVE, sent|defwinproc },
2902     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2903
2904      /* in MDI client */
2905     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2906     { WM_NCCALCSIZE, sent|wparam, 1 },
2907     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2908     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2909
2910      /* in MDI child */
2911     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2912     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2913     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2914     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2915     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2916     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2917
2918     { 0x0093, sent|defwinproc|optional },
2919     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2920     { 0x0093, sent|defwinproc|optional },
2921     { 0x0093, sent|defwinproc|optional },
2922     { 0x0093, sent|defwinproc|optional },
2923     { 0x0093, sent|optional },
2924
2925     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2926     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2927     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2928     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2929     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2930
2931      /* in MDI frame */
2932     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2933     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2934     { 0x0093, sent|defwinproc|optional },
2935     { 0x0093, sent|defwinproc|optional },
2936     { 0x0093, sent|defwinproc|optional },
2937     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2938     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2939     { 0x0093, sent|optional },
2940
2941     { WM_NCACTIVATE, sent|wparam, 0 },
2942     { WM_MDIACTIVATE, sent },
2943
2944     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2945     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2946     { WM_NCCALCSIZE, sent|wparam, 1 },
2947
2948     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2949
2950     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2951     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2952     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2953
2954      /* in MDI child */
2955     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2956     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2957     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2958     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2959
2960      /* in MDI frame */
2961     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2962     { WM_NCCALCSIZE, sent|wparam, 1 },
2963     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2964     { WM_MOVE, sent|defwinproc },
2965     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2966
2967      /* in MDI client */
2968     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2969     { WM_NCCALCSIZE, sent|wparam, 1 },
2970     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2971     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2972     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2973     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2974     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2975     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2976     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2977
2978     { HCBT_SETFOCUS, hook },
2979     { WM_KILLFOCUS, sent },
2980     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2981     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2982     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2983     { WM_SETFOCUS, sent }, /* in MDI client */
2984
2985     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2986
2987     { HCBT_DESTROYWND, hook },
2988     /* Win2k sends wparam set to
2989      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2990      * while Win9x doesn't bother to set child window id according to
2991      * CLIENTCREATESTRUCT.idFirstChild
2992      */
2993     { 0x0090, sent|optional },
2994     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2995
2996     { WM_SHOWWINDOW, sent|wparam, 0 },
2997     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2998     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2999     { WM_ERASEBKGND, sent|parent|optional },
3000     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3001
3002     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3003     { WM_DESTROY, sent },
3004     { WM_NCDESTROY, sent },
3005     { 0 }
3006 };
3007 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3008 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3009     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3010     { WM_GETMINMAXINFO, sent },
3011     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3012     { WM_NCCALCSIZE, sent|wparam, 1 },
3013     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3014     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3015
3016     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3017     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3018     { HCBT_SETFOCUS, hook|optional },
3019     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3020     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3021     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3022     { HCBT_SETFOCUS, hook|optional },
3023     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3024     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3025     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3026     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3027     { WM_SETFOCUS, sent|optional|defwinproc },
3028     { WM_MDIACTIVATE, sent|optional|defwinproc },
3029     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3030     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3031      /* in MDI frame */
3032     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3033     { WM_NCCALCSIZE, sent|wparam, 1 },
3034     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3035     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3036     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3037     { 0 }
3038 };
3039 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3040 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3041     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3042     { WM_GETMINMAXINFO, sent },
3043     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3044     { WM_GETMINMAXINFO, sent|defwinproc },
3045     { WM_NCCALCSIZE, sent|wparam, 1 },
3046     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3047     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3048
3049     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3050     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3051     { HCBT_SETFOCUS, hook|optional },
3052     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3053     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3054     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3055     { HCBT_SETFOCUS, hook|optional },
3056     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3057     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3058     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3059     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3060     { WM_SETFOCUS, sent|defwinproc|optional },
3061     { WM_MDIACTIVATE, sent|defwinproc|optional },
3062     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3063     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3064     { 0 }
3065 };
3066 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3067 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3068     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3069     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3070     { WM_GETMINMAXINFO, sent },
3071     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3072     { WM_GETMINMAXINFO, sent|defwinproc },
3073     { WM_NCCALCSIZE, sent|wparam, 1 },
3074     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3075     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3076     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3077     { WM_MOVE, sent|defwinproc },
3078     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3079
3080     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3081     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3082     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3083     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3084     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3085     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3086      /* in MDI frame */
3087     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3088     { WM_NCCALCSIZE, sent|wparam, 1 },
3089     { 0x0093, sent|defwinproc|optional },
3090     { 0x0094, sent|defwinproc|optional },
3091     { 0x0094, sent|defwinproc|optional },
3092     { 0x0094, sent|defwinproc|optional },
3093     { 0x0094, sent|defwinproc|optional },
3094     { 0x0093, sent|defwinproc|optional },
3095     { 0x0093, sent|defwinproc|optional },
3096     { 0x0091, sent|defwinproc|optional },
3097     { 0x0092, sent|defwinproc|optional },
3098     { 0x0092, sent|defwinproc|optional },
3099     { 0x0092, sent|defwinproc|optional },
3100     { 0x0092, sent|defwinproc|optional },
3101     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3102     { WM_MOVE, sent|defwinproc },
3103     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3104     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3105      /* in MDI client */
3106     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3107     { WM_NCCALCSIZE, sent|wparam, 1 },
3108     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3109     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3110      /* in MDI child */
3111     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3112     { WM_GETMINMAXINFO, sent|defwinproc },
3113     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3114     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3115     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3116     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3117     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3118     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3119     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3120     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3121      /* in MDI frame */
3122     { 0x0093, sent|optional },
3123     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3124     { 0x0093, sent|defwinproc|optional },
3125     { 0x0093, sent|defwinproc|optional },
3126     { 0x0093, sent|defwinproc|optional },
3127     { 0x0091, sent|defwinproc|optional },
3128     { 0x0092, sent|defwinproc|optional },
3129     { 0x0092, sent|defwinproc|optional },
3130     { 0x0092, sent|defwinproc|optional },
3131     { 0x0092, sent|defwinproc|optional },
3132     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3133     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3134     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3135     { 0 }
3136 };
3137 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3138 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3139     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3140     { WM_GETMINMAXINFO, sent },
3141     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3142     { WM_NCCALCSIZE, sent|wparam, 1 },
3143     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3144     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3145     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3146      /* in MDI frame */
3147     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3148     { WM_NCCALCSIZE, sent|wparam, 1 },
3149     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3150     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3151     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3152     { 0 }
3153 };
3154 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3155 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3156     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3157     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3158     { WM_NCCALCSIZE, sent|wparam, 1 },
3159     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3160     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3161     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3162      /* in MDI frame */
3163     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3164     { WM_NCCALCSIZE, sent|wparam, 1 },
3165     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3166     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3167     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3168     { 0 }
3169 };
3170 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3171 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3172     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3173     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3174     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3175     { WM_NCCALCSIZE, sent|wparam, 1 },
3176     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3177     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3178     { WM_MOVE, sent|defwinproc },
3179     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3180     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3181     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3182     { HCBT_SETFOCUS, hook },
3183     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3184     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3185     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3186     { WM_SETFOCUS, sent },
3187     { 0 }
3188 };
3189 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3190 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3191     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3192     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3193     { WM_NCCALCSIZE, sent|wparam, 1 },
3194     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3195     { WM_MOVE, sent|defwinproc },
3196     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3197     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3198     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3199     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3200     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3201     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3202     { 0 }
3203 };
3204 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3205 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3206     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3207     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3208     { WM_NCCALCSIZE, sent|wparam, 1 },
3209     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3210     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3211     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3212     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3213      /* in MDI frame */
3214     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3215     { WM_NCCALCSIZE, sent|wparam, 1 },
3216     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3217     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3218     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3219     { 0 }
3220 };
3221
3222 static HWND mdi_client;
3223 static WNDPROC old_mdi_client_proc;
3224
3225 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3226 {
3227     struct recvd_message msg;
3228
3229     /* do not log painting messages */
3230     if (message != WM_PAINT &&
3231         message != WM_NCPAINT &&
3232         message != WM_SYNCPAINT &&
3233         message != WM_ERASEBKGND &&
3234         message != WM_NCHITTEST &&
3235         message != WM_GETTEXT &&
3236         message != WM_MDIGETACTIVE &&
3237         !ignore_message( message ))
3238     {
3239         msg.hwnd = hwnd;
3240         msg.message = message;
3241         msg.flags = sent|wparam|lparam;
3242         msg.wParam = wParam;
3243         msg.lParam = lParam;
3244         msg.descr = "mdi client";
3245         add_message(&msg);
3246     }
3247
3248     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3249 }
3250
3251 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3252 {
3253     static LONG defwndproc_counter = 0;
3254     LRESULT ret;
3255     struct recvd_message msg;
3256
3257     /* do not log painting messages */
3258     if (message != WM_PAINT &&
3259         message != WM_NCPAINT &&
3260         message != WM_SYNCPAINT &&
3261         message != WM_ERASEBKGND &&
3262         message != WM_NCHITTEST &&
3263         message != WM_GETTEXT &&
3264         !ignore_message( message ))
3265     {
3266         switch (message)
3267         {
3268             case WM_MDIACTIVATE:
3269             {
3270                 HWND active, client = GetParent(hwnd);
3271
3272                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3273
3274                 if (hwnd == (HWND)lParam) /* if we are being activated */
3275                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3276                 else
3277                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3278                 break;
3279             }
3280         }
3281
3282         msg.hwnd = hwnd;
3283         msg.message = message;
3284         msg.flags = sent|wparam|lparam;
3285         if (defwndproc_counter) msg.flags |= defwinproc;
3286         msg.wParam = wParam;
3287         msg.lParam = lParam;
3288         msg.descr = "mdi child";
3289         add_message(&msg);
3290     }
3291
3292     defwndproc_counter++;
3293     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3294     defwndproc_counter--;
3295
3296     return ret;
3297 }
3298
3299 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3300 {
3301     static LONG defwndproc_counter = 0;
3302     LRESULT ret;
3303     struct recvd_message msg;
3304
3305     /* do not log painting messages */
3306     if (message != WM_PAINT &&
3307         message != WM_NCPAINT &&
3308         message != WM_SYNCPAINT &&
3309         message != WM_ERASEBKGND &&
3310         message != WM_NCHITTEST &&
3311         message != WM_GETTEXT &&
3312         !ignore_message( message ))
3313     {
3314         msg.hwnd = hwnd;
3315         msg.message = message;
3316         msg.flags = sent|wparam|lparam;
3317         if (defwndproc_counter) msg.flags |= defwinproc;
3318         msg.wParam = wParam;
3319         msg.lParam = lParam;
3320         msg.descr = "mdi frame";
3321         add_message(&msg);
3322     }
3323
3324     defwndproc_counter++;
3325     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3326     defwndproc_counter--;
3327
3328     return ret;
3329 }
3330
3331 static BOOL mdi_RegisterWindowClasses(void)
3332 {
3333     WNDCLASSA cls;
3334
3335     cls.style = 0;
3336     cls.lpfnWndProc = mdi_frame_wnd_proc;
3337     cls.cbClsExtra = 0;
3338     cls.cbWndExtra = 0;
3339     cls.hInstance = GetModuleHandleA(0);
3340     cls.hIcon = 0;
3341     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3342     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3343     cls.lpszMenuName = NULL;
3344     cls.lpszClassName = "MDI_frame_class";
3345     if (!RegisterClassA(&cls)) return FALSE;
3346
3347     cls.lpfnWndProc = mdi_child_wnd_proc;
3348     cls.lpszClassName = "MDI_child_class";
3349     if (!RegisterClassA(&cls)) return FALSE;
3350
3351     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3352     old_mdi_client_proc = cls.lpfnWndProc;
3353     cls.hInstance = GetModuleHandleA(0);
3354     cls.lpfnWndProc = mdi_client_hook_proc;
3355     cls.lpszClassName = "MDI_client_class";
3356     if (!RegisterClassA(&cls)) assert(0);
3357
3358     return TRUE;
3359 }
3360
3361 static void test_mdi_messages(void)
3362 {
3363     MDICREATESTRUCTA mdi_cs;
3364     CLIENTCREATESTRUCT client_cs;
3365     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3366     BOOL zoomed;
3367     RECT rc;
3368     HMENU hMenu = CreateMenu();
3369
3370     assert(mdi_RegisterWindowClasses());
3371
3372     flush_sequence();
3373
3374     trace("creating MDI frame window\n");
3375     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3376                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3377                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3378                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3379                                 GetDesktopWindow(), hMenu,
3380                                 GetModuleHandleA(0), NULL);
3381     assert(mdi_frame);
3382     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3383
3384     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3385     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3386
3387     trace("creating MDI client window\n");
3388     GetClientRect(mdi_frame, &rc);
3389     client_cs.hWindowMenu = 0;
3390     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3391     mdi_client = CreateWindowExA(0, "MDI_client_class",
3392                                  NULL,
3393                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3394                                  rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3395                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3396     assert(mdi_client);
3397     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3398
3399     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3400     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3401
3402     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3403     ok(!active_child, "wrong active MDI child %p\n", active_child);
3404     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3405
3406     SetFocus(0);
3407     flush_sequence();
3408
3409     trace("creating invisible MDI child window\n");
3410     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3411                                 WS_CHILD,
3412                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3413                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3414     assert(mdi_child);
3415
3416     flush_sequence();
3417     ShowWindow(mdi_child, SW_SHOWNORMAL);
3418     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3419
3420     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3421     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3422
3423     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3424     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3425
3426     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3427     ok(!active_child, "wrong active MDI child %p\n", active_child);
3428     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3429
3430     ShowWindow(mdi_child, SW_HIDE);
3431     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3432     flush_sequence();
3433
3434     ShowWindow(mdi_child, SW_SHOW);
3435     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3436
3437     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3438     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3439
3440     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3441     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3442
3443     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3444     ok(!active_child, "wrong active MDI child %p\n", active_child);
3445     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3446
3447     DestroyWindow(mdi_child);
3448     flush_sequence();
3449
3450     trace("creating visible MDI child window\n");
3451     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3452                                 WS_CHILD | WS_VISIBLE,
3453                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3454                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3455     assert(mdi_child);
3456     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3457
3458     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3459     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3460
3461     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3462     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3463
3464     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3465     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3466     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3467     flush_sequence();
3468
3469     DestroyWindow(mdi_child);
3470     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3471
3472     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3473     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3474
3475     /* Win2k: MDI client still returns a just destroyed child as active
3476      * Win9x: MDI client returns 0
3477      */
3478     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3479     ok(active_child == mdi_child || /* win2k */
3480        !active_child, /* win9x */
3481        "wrong active MDI child %p\n", active_child);
3482     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3483
3484     flush_sequence();
3485
3486     trace("creating invisible MDI child window\n");
3487     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3488                                 WS_CHILD,
3489                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3490                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3491     assert(mdi_child2);
3492     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3493
3494     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3495     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3496
3497     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3498     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3499
3500     /* Win2k: MDI client still returns a just destroyed child as active
3501      * Win9x: MDI client returns mdi_child2
3502      */
3503     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3504     ok(active_child == mdi_child || /* win2k */
3505        active_child == mdi_child2, /* win9x */
3506        "wrong active MDI child %p\n", active_child);
3507     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3508     flush_sequence();
3509
3510     ShowWindow(mdi_child2, SW_MAXIMIZE);
3511     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3512
3513     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3514     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3515
3516     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3517     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3518     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3519     flush_sequence();
3520
3521     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3522     ok(GetFocus() == mdi_child2 || /* win2k */
3523        GetFocus() == 0, /* win9x */
3524        "wrong focus window %p\n", GetFocus());
3525
3526     SetFocus(0);
3527     flush_sequence();
3528
3529     ShowWindow(mdi_child2, SW_HIDE);
3530     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3531
3532     ShowWindow(mdi_child2, SW_RESTORE);
3533     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3534     flush_sequence();
3535
3536     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3537     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3538
3539     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3540     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3541     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3542     flush_sequence();
3543
3544     SetFocus(0);
3545     flush_sequence();
3546
3547     ShowWindow(mdi_child2, SW_HIDE);
3548     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3549
3550     ShowWindow(mdi_child2, SW_SHOW);
3551     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3552
3553     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3554     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3555
3556     ShowWindow(mdi_child2, SW_MAXIMIZE);
3557     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3558
3559     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3560     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3561
3562     ShowWindow(mdi_child2, SW_RESTORE);
3563     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3564
3565     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3566     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3567
3568     ShowWindow(mdi_child2, SW_MINIMIZE);
3569     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3570
3571     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3572     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3573
3574     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3575     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3576     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3577     flush_sequence();
3578
3579     ShowWindow(mdi_child2, SW_RESTORE);
3580     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3581
3582     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3583     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3584
3585     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3586     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3587     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3588     flush_sequence();
3589
3590     SetFocus(0);
3591     flush_sequence();
3592
3593     ShowWindow(mdi_child2, SW_HIDE);
3594     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3595
3596     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3597     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3598
3599     DestroyWindow(mdi_child2);
3600     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3601
3602     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3603     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3604
3605     /* test for maximized MDI children */
3606     trace("creating maximized visible MDI child window 1\n");
3607     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3608                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3609                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3610                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3611     assert(mdi_child);
3612     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3613     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3614
3615     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3616     ok(GetFocus() == mdi_child || /* win2k */
3617        GetFocus() == 0, /* win9x */
3618        "wrong focus window %p\n", GetFocus());
3619
3620     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3621     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3622     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3623     flush_sequence();
3624
3625     trace("creating maximized visible MDI child window 2\n");
3626     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3627                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3628                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3629                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3630     assert(mdi_child2);
3631     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3632     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3633     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3634
3635     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3636     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3637
3638     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3639     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3640     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3641     flush_sequence();
3642
3643     trace("destroying maximized visible MDI child window 2\n");
3644     DestroyWindow(mdi_child2);
3645     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3646
3647     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3648
3649     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3650     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3651
3652     /* Win2k: MDI client still returns a just destroyed child as active
3653      * Win9x: MDI client returns 0
3654      */
3655     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3656     ok(active_child == mdi_child2 || /* win2k */
3657        !active_child, /* win9x */
3658        "wrong active MDI child %p\n", active_child);
3659     flush_sequence();
3660
3661     ShowWindow(mdi_child, SW_MAXIMIZE);
3662     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3663     flush_sequence();
3664
3665     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3666     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3667
3668     trace("re-creating maximized visible MDI child window 2\n");
3669     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3670                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3671                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3672                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3673     assert(mdi_child2);
3674     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3675     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3676     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3677
3678     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3679     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3680
3681     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3682     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3683     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3684     flush_sequence();
3685
3686     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3687     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3688     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3689
3690     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3691     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3692     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3693
3694     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3695     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3696     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3697     flush_sequence();
3698
3699     DestroyWindow(mdi_child);
3700     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3701
3702     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3703     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3704
3705     /* Win2k: MDI client still returns a just destroyed child as active
3706      * Win9x: MDI client returns 0
3707      */
3708     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3709     ok(active_child == mdi_child || /* win2k */
3710        !active_child, /* win9x */
3711        "wrong active MDI child %p\n", active_child);
3712     flush_sequence();
3713
3714     trace("creating maximized invisible MDI child window\n");
3715     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3716                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3717                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3718                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3719     assert(mdi_child2);
3720     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3721     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3722     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3723     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3724
3725     /* Win2k: MDI client still returns a just destroyed child as active
3726      * Win9x: MDI client returns 0
3727      */
3728     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3729     ok(active_child == mdi_child || /* win2k */
3730        !active_child || active_child == mdi_child2, /* win9x */
3731        "wrong active MDI child %p\n", active_child);
3732     flush_sequence();
3733
3734     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3735     ShowWindow(mdi_child2, SW_MAXIMIZE);
3736     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3737     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3738     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3739     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3740
3741     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3742     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3743     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3744     flush_sequence();
3745
3746     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3747     flush_sequence();
3748
3749     /* end of test for maximized MDI children */
3750     SetFocus(0);
3751     flush_sequence();
3752     trace("creating maximized visible MDI child window 1(Switch test)\n");
3753     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3754                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3755                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3756                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3757     assert(mdi_child);
3758     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3759     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3760
3761     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3762     ok(GetFocus() == mdi_child || /* win2k */
3763        GetFocus() == 0, /* win9x */
3764        "wrong focus window %p(Switch test)\n", GetFocus());
3765
3766     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3767     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3768     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3769     flush_sequence();
3770
3771     trace("creating maximized visible MDI child window 2(Switch test)\n");
3772     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3773                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3774                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3775                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3776     assert(mdi_child2);
3777     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3778
3779     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3780     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3781
3782     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3783     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3784
3785     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3786     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3787     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3788     flush_sequence();
3789
3790     trace("Switch child window.\n");
3791     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3792     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3793     trace("end of test for switch maximized MDI children\n");
3794     flush_sequence();
3795
3796     /* Prepare for switching test of not maximized MDI children  */
3797     ShowWindow( mdi_child, SW_NORMAL );
3798     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3799     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3800     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3801     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3802     flush_sequence();
3803
3804     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3805     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3806     trace("end of test for switch not maximized MDI children\n");
3807     flush_sequence();
3808
3809     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3810     flush_sequence();
3811
3812     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3813     flush_sequence();
3814
3815     SetFocus(0);
3816     flush_sequence();
3817     /* end of tests for switch maximized/not maximized MDI children */
3818
3819     mdi_cs.szClass = "MDI_child_Class";
3820     mdi_cs.szTitle = "MDI child";
3821     mdi_cs.hOwner = GetModuleHandleA(0);
3822     mdi_cs.x = 0;
3823     mdi_cs.y = 0;
3824     mdi_cs.cx = CW_USEDEFAULT;
3825     mdi_cs.cy = CW_USEDEFAULT;
3826     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3827     mdi_cs.lParam = 0;
3828     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3829     ok(mdi_child != 0, "MDI child creation failed\n");
3830     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3831
3832     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3833
3834     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3835     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3836
3837     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3838     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3839     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3840
3841     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3842     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3843     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3844     flush_sequence();
3845
3846     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3847     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3848
3849     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3850     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3851     ok(!active_child, "wrong active MDI child %p\n", active_child);
3852
3853     SetFocus(0);
3854     flush_sequence();
3855
3856     DestroyWindow(mdi_client);
3857     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3858
3859     /* test maximization of MDI child with invisible parent */
3860     client_cs.hWindowMenu = 0;
3861     mdi_client = CreateWindow("MDI_client_class",
3862                                  NULL,
3863                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3864                                  0, 0, 660, 430,
3865                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3866     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3867
3868     ShowWindow(mdi_client, SW_HIDE);
3869     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3870
3871     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3872                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3873                                 0, 0, 650, 440,
3874                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3875     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3876
3877     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3878     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3879     zoomed = IsZoomed(mdi_child);
3880     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3881     
3882     ShowWindow(mdi_client, SW_SHOW);
3883     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3884
3885     DestroyWindow(mdi_child);
3886     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3887
3888     /* end of test for maximization of MDI child with invisible parent */
3889
3890     DestroyWindow(mdi_client);
3891     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3892
3893     DestroyWindow(mdi_frame);
3894     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3895 }
3896 /************************* End of MDI test **********************************/
3897
3898 static void test_WM_SETREDRAW(HWND hwnd)
3899 {
3900     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3901
3902     flush_events();
3903     flush_sequence();
3904
3905     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3906     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3907
3908     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3909     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3910
3911     flush_sequence();
3912     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3913     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3914
3915     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3916     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3917
3918     /* restore original WS_VISIBLE state */
3919     SetWindowLongA(hwnd, GWL_STYLE, style);
3920
3921     flush_events();
3922     flush_sequence();
3923 }
3924
3925 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3926 {
3927     struct recvd_message msg;
3928
3929     if (ignore_message( message )) return 0;
3930
3931     switch (message)
3932     {
3933         /* ignore */
3934         case WM_MOUSEMOVE:
3935         case WM_NCMOUSEMOVE:
3936         case WM_NCMOUSELEAVE:
3937         case WM_SETCURSOR:
3938             return 0;
3939         case WM_NCHITTEST:
3940             return HTCLIENT;
3941     }
3942
3943     msg.hwnd = hwnd;
3944     msg.message = message;
3945     msg.flags = sent|wparam|lparam;
3946     msg.wParam = wParam;
3947     msg.lParam = lParam;
3948     msg.descr = "dialog";
3949     add_message(&msg);
3950
3951     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3952     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3953     return 0;
3954 }
3955
3956 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3957 {
3958     DWORD style, exstyle;
3959     INT xmin, xmax;
3960     BOOL ret;
3961
3962     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3963     style = GetWindowLongA(hwnd, GWL_STYLE);
3964     /* do not be confused by WS_DLGFRAME set */
3965     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3966
3967     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3968     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3969
3970     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3971     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3972     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3973         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3974     else
3975         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3976
3977     style = GetWindowLongA(hwnd, GWL_STYLE);
3978     if (set) ok(style & set, "style %08x should be set\n", set);
3979     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3980
3981     /* a subsequent call should do nothing */
3982     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3983     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3984     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3985
3986     xmin = 0xdeadbeef;
3987     xmax = 0xdeadbeef;
3988     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3989     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3990     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3991     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3992     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3993 }
3994
3995 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3996 {
3997     DWORD style, exstyle;
3998     SCROLLINFO si;
3999     BOOL ret;
4000
4001     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4002     style = GetWindowLongA(hwnd, GWL_STYLE);
4003     /* do not be confused by WS_DLGFRAME set */
4004     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4005
4006     if (clear) ok(style & clear, "style %08x should be set\n", clear);
4007     if (set) ok(!(style & set), "style %08x should not be set\n", set);
4008
4009     si.cbSize = sizeof(si);
4010     si.fMask = SIF_RANGE;
4011     si.nMin = min;
4012     si.nMax = max;
4013     SetScrollInfo(hwnd, ctl, &si, TRUE);
4014     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4015         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4016     else
4017         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4018
4019     style = GetWindowLongA(hwnd, GWL_STYLE);
4020     if (set) ok(style & set, "style %08x should be set\n", set);
4021     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4022
4023     /* a subsequent call should do nothing */
4024     SetScrollInfo(hwnd, ctl, &si, TRUE);
4025     if (style & WS_HSCROLL)
4026         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4027     else if (style & WS_VSCROLL)
4028         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4029     else
4030         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4031
4032     si.fMask = SIF_PAGE;
4033     si.nPage = 5;
4034     SetScrollInfo(hwnd, ctl, &si, FALSE);
4035     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4036
4037     si.fMask = SIF_POS;
4038     si.nPos = max - 1;
4039     SetScrollInfo(hwnd, ctl, &si, FALSE);
4040     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4041
4042     si.fMask = SIF_RANGE;
4043     si.nMin = 0xdeadbeef;
4044     si.nMax = 0xdeadbeef;
4045     ret = GetScrollInfo(hwnd, ctl, &si);
4046     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4047     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4048     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4049     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4050 }
4051
4052 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4053 static void test_scroll_messages(HWND hwnd)
4054 {
4055     SCROLLINFO si;
4056     INT min, max;
4057     BOOL ret;
4058
4059     flush_events();
4060     flush_sequence();
4061
4062     min = 0xdeadbeef;
4063     max = 0xdeadbeef;
4064     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4065     ok( ret, "GetScrollRange error %d\n", GetLastError());
4066     if (sequence->message != WmGetScrollRangeSeq[0].message)
4067         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4068     /* values of min and max are undefined */
4069     flush_sequence();
4070
4071     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4072     ok( ret, "SetScrollRange error %d\n", GetLastError());
4073     if (sequence->message != WmSetScrollRangeSeq[0].message)
4074         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4075     flush_sequence();
4076
4077     min = 0xdeadbeef;
4078     max = 0xdeadbeef;
4079     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4080     ok( ret, "GetScrollRange error %d\n", GetLastError());
4081     if (sequence->message != WmGetScrollRangeSeq[0].message)
4082         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4083     /* values of min and max are undefined */
4084     flush_sequence();
4085
4086     si.cbSize = sizeof(si);
4087     si.fMask = SIF_RANGE;
4088     si.nMin = 20;
4089     si.nMax = 160;
4090     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4091     if (sequence->message != WmSetScrollRangeSeq[0].message)
4092         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4093     flush_sequence();
4094
4095     si.fMask = SIF_PAGE;
4096     si.nPage = 10;
4097     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4098     if (sequence->message != WmSetScrollRangeSeq[0].message)
4099         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4100     flush_sequence();
4101
4102     si.fMask = SIF_POS;
4103     si.nPos = 20;
4104     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4105     if (sequence->message != WmSetScrollRangeSeq[0].message)
4106         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4107     flush_sequence();
4108
4109     si.fMask = SIF_RANGE;
4110     si.nMin = 0xdeadbeef;
4111     si.nMax = 0xdeadbeef;
4112     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4113     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4114     if (sequence->message != WmGetScrollInfoSeq[0].message)
4115         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4116     /* values of min and max are undefined */
4117     flush_sequence();
4118
4119     /* set WS_HSCROLL */
4120     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4121     /* clear WS_HSCROLL */
4122     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4123
4124     /* set WS_HSCROLL */
4125     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4126     /* clear WS_HSCROLL */
4127     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4128
4129     /* set WS_VSCROLL */
4130     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4131     /* clear WS_VSCROLL */
4132     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4133
4134     /* set WS_VSCROLL */
4135     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4136     /* clear WS_VSCROLL */
4137     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4138 }
4139
4140 static void test_showwindow(void)
4141 {
4142     HWND hwnd, hchild;
4143     RECT rc;
4144
4145     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4146                            100, 100, 200, 200, 0, 0, 0, NULL);
4147     ok (hwnd != 0, "Failed to create overlapped window\n");
4148     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4149                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4150     ok (hchild != 0, "Failed to create child\n");
4151     flush_sequence();
4152
4153     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4154     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4155     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4156     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4157
4158     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4159     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4160     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4161     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4162     /* back to invisible */
4163     ShowWindow(hchild, SW_HIDE);
4164     ShowWindow(hwnd, SW_HIDE);
4165     flush_sequence();
4166     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4167     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4168     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4169     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4170     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4171     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4172     flush_sequence();
4173     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4174     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4175     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4176     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4177     ShowWindow( hwnd, SW_SHOW);
4178     flush_sequence();
4179     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4180     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4181     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4182
4183     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4184     ShowWindow( hchild, SW_HIDE);
4185     flush_sequence();
4186     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4187     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4188     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4189
4190     SetCapture(hchild);
4191     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4192     DestroyWindow(hchild);
4193     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4194
4195     DestroyWindow(hwnd);
4196     flush_sequence();
4197
4198     /* Popup windows */
4199     /* Test 1:
4200      * 1. Create invisible maximized popup window.
4201      * 2. Move and resize it.
4202      * 3. Show it maximized.
4203      */
4204     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4205     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4206                            100, 100, 200, 200, 0, 0, 0, NULL);
4207     ok (hwnd != 0, "Failed to create popup window\n");
4208     ok(IsZoomed(hwnd), "window should be maximized\n");
4209     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4210
4211     GetWindowRect(hwnd, &rc);
4212     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4213         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4214         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4215         rc.left, rc.top, rc.right, rc.bottom);
4216     /* Reset window's size & position */
4217     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4218     ok(IsZoomed(hwnd), "window should be maximized\n");
4219     flush_sequence();
4220
4221     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4222     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4223     ok(IsZoomed(hwnd), "window should be maximized\n");
4224     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4225
4226     GetWindowRect(hwnd, &rc);
4227     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4228         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4229         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4230         rc.left, rc.top, rc.right, rc.bottom);
4231     DestroyWindow(hwnd);
4232     flush_sequence();
4233
4234     /* Test 2:
4235      * 1. Create invisible maximized popup window.
4236      * 2. Show it maximized.
4237      */
4238     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4239     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4240                            100, 100, 200, 200, 0, 0, 0, NULL);
4241     ok (hwnd != 0, "Failed to create popup window\n");
4242     ok(IsZoomed(hwnd), "window should be maximized\n");
4243     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4244
4245     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4246     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4247     ok(IsZoomed(hwnd), "window should be maximized\n");
4248     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4249     DestroyWindow(hwnd);
4250     flush_sequence();
4251
4252     /* Test 3:
4253      * 1. Create visible maximized popup window.
4254      */
4255     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4256     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4257                            100, 100, 200, 200, 0, 0, 0, NULL);
4258     ok (hwnd != 0, "Failed to create popup window\n");
4259     ok(IsZoomed(hwnd), "window should be maximized\n");
4260     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4261     DestroyWindow(hwnd);
4262     flush_sequence();
4263
4264     /* Test 4:
4265      * 1. Create visible popup window.
4266      * 2. Maximize it.
4267      */
4268     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4269     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4270                            100, 100, 200, 200, 0, 0, 0, NULL);
4271     ok (hwnd != 0, "Failed to create popup window\n");
4272     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4273     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4274
4275     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4276     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4277     ok(IsZoomed(hwnd), "window should be maximized\n");
4278     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4279     DestroyWindow(hwnd);
4280     flush_sequence();
4281 }
4282
4283 static void test_sys_menu(void)
4284 {
4285     HWND hwnd;
4286     HMENU hmenu;
4287     UINT state;
4288
4289     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4290                            100, 100, 200, 200, 0, 0, 0, NULL);
4291     ok (hwnd != 0, "Failed to create overlapped window\n");
4292
4293     flush_sequence();
4294
4295     /* test existing window without CS_NOCLOSE style */
4296     hmenu = GetSystemMenu(hwnd, FALSE);
4297     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4298
4299     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4300     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4301     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4302
4303     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4304     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4305
4306     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4307     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4308     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4309
4310     EnableMenuItem(hmenu, SC_CLOSE, 0);
4311     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4312
4313     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4314     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4315     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4316
4317     /* test whether removing WS_SYSMENU destroys a system menu */
4318     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4319     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4320     flush_sequence();
4321     hmenu = GetSystemMenu(hwnd, FALSE);
4322     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4323
4324     DestroyWindow(hwnd);
4325
4326     /* test new window with CS_NOCLOSE style */
4327     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4328                            100, 100, 200, 200, 0, 0, 0, NULL);
4329     ok (hwnd != 0, "Failed to create overlapped window\n");
4330
4331     hmenu = GetSystemMenu(hwnd, FALSE);
4332     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4333
4334     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4335     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4336
4337     DestroyWindow(hwnd);
4338
4339     /* test new window without WS_SYSMENU style */
4340     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4341                            100, 100, 200, 200, 0, 0, 0, NULL);
4342     ok(hwnd != 0, "Failed to create overlapped window\n");
4343
4344     hmenu = GetSystemMenu(hwnd, FALSE);
4345     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4346
4347     DestroyWindow(hwnd);
4348 }
4349
4350 /* For shown WS_OVERLAPPEDWINDOW */
4351 static const struct message WmSetIcon_1[] = {
4352     { WM_SETICON, sent },
4353     { 0x00AE, sent|defwinproc|optional }, /* XP */
4354     { WM_GETTEXT, sent|defwinproc|optional },
4355     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4356     { 0 }
4357 };
4358
4359 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4360 static const struct message WmSetIcon_2[] = {
4361     { WM_SETICON, sent },
4362     { 0 }
4363 };
4364
4365 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4366 static const struct message WmInitEndSession[] = {
4367     { 0x003B, sent },
4368     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4369     { 0 }
4370 };
4371
4372 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4373 static const struct message WmInitEndSession_2[] = {
4374     { 0x003B, sent },
4375     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4376     { 0 }
4377 };
4378
4379 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4380 static const struct message WmInitEndSession_3[] = {
4381     { 0x003B, sent },
4382     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4383     { 0 }
4384 };
4385
4386 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4387 static const struct message WmInitEndSession_4[] = {
4388     { 0x003B, sent },
4389     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4390     { 0 }
4391 };
4392
4393 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4394 static const struct message WmInitEndSession_5[] = {
4395     { 0x003B, sent },
4396     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4397     { 0 }
4398 };
4399
4400 static const struct message WmOptionalPaint[] = {
4401     { WM_PAINT, sent|optional },
4402     { WM_NCPAINT, sent|beginpaint|optional },
4403     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4404     { WM_ERASEBKGND, sent|beginpaint|optional },
4405     { 0 }
4406 };
4407
4408 static const struct message WmZOrder[] = {
4409     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4410     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4411     { HCBT_ACTIVATE, hook },
4412     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4413     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4414     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4415     { WM_GETTEXT, sent|optional },
4416     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4417     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4418     { WM_NCACTIVATE, sent|lparam, 1, 0 },
4419     { WM_GETTEXT, sent|defwinproc|optional },
4420     { WM_GETTEXT, sent|defwinproc|optional },
4421     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4422     { HCBT_SETFOCUS, hook },
4423     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4424     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4425     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4426     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4427     { WM_GETTEXT, sent|optional },
4428     { WM_NCCALCSIZE, sent|optional },
4429     { 0 }
4430 };
4431
4432 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4433 {
4434     DWORD ret;
4435     MSG msg;
4436
4437     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4438     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4439
4440     PostMessageA(hwnd, WM_USER, 0, 0);
4441
4442     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4443     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4444
4445     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4446     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4447
4448     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4449     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4450
4451     PostMessageA(hwnd, WM_USER, 0, 0);
4452
4453     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4454     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4455
4456     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4457     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4458
4459     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4460     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4461     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4462
4463     PostMessageA(hwnd, WM_USER, 0, 0);
4464
4465     /* new incoming message causes it to become signaled again */
4466     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4467     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4468
4469     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4470     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4471     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4472     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4473 }
4474
4475 /* test if we receive the right sequence of messages */
4476 static void test_messages(void)
4477 {
4478     HWND hwnd, hparent, hchild;
4479     HWND hchild2, hbutton;
4480     HMENU hmenu;
4481     MSG msg;
4482     LRESULT res;
4483
4484     flush_sequence();
4485
4486     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4487                            100, 100, 200, 200, 0, 0, 0, NULL);
4488     ok (hwnd != 0, "Failed to create overlapped window\n");
4489     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4490
4491     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4492     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4493     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4494
4495     /* test WM_SETREDRAW on a not visible top level window */
4496     test_WM_SETREDRAW(hwnd);
4497
4498     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4499     flush_events();
4500     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4501     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4502
4503     ok(GetActiveWindow() == hwnd, "window should be active\n");
4504     ok(GetFocus() == hwnd, "window should have input focus\n");
4505     ShowWindow(hwnd, SW_HIDE);
4506     flush_events();
4507     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4508
4509     ShowWindow(hwnd, SW_SHOW);
4510     flush_events();
4511     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4512
4513     ShowWindow(hwnd, SW_HIDE);
4514     flush_events();
4515     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4516
4517     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4518     flush_events();
4519     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4520     flush_sequence();
4521
4522     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4523     {
4524         ShowWindow(hwnd, SW_RESTORE);
4525         flush_events();
4526         ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4527         flush_sequence();
4528     }
4529
4530     ShowWindow(hwnd, SW_MINIMIZE);
4531     flush_events();
4532     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4533     flush_sequence();
4534
4535     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4536     {
4537         ShowWindow(hwnd, SW_RESTORE);
4538         flush_events();
4539         ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4540         flush_sequence();
4541     }
4542
4543     ShowWindow(hwnd, SW_SHOW);
4544     flush_events();
4545     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4546
4547     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4548     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4549     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4550     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4551
4552     /* test WM_SETREDRAW on a visible top level window */
4553     ShowWindow(hwnd, SW_SHOW);
4554     flush_events();
4555     test_WM_SETREDRAW(hwnd);
4556
4557     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4558     test_scroll_messages(hwnd);
4559
4560     /* test resizing and moving */
4561     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4562     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4563     flush_events();
4564     flush_sequence();
4565     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4566     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4567     flush_events();
4568     flush_sequence();
4569     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4570     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4571     flush_events();
4572     flush_sequence();
4573
4574     /* popups don't get WM_GETMINMAXINFO */
4575     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4576     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4577     flush_sequence();
4578     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4579     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4580
4581     DestroyWindow(hwnd);
4582     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4583
4584     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4585                               100, 100, 200, 200, 0, 0, 0, NULL);
4586     ok (hparent != 0, "Failed to create parent window\n");
4587     flush_sequence();
4588
4589     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4590                              0, 0, 10, 10, hparent, 0, 0, NULL);
4591     ok (hchild != 0, "Failed to create child window\n");
4592     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4593     DestroyWindow(hchild);
4594     flush_sequence();
4595
4596     /* visible child window with a caption */
4597     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4598                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4599                              0, 0, 10, 10, hparent, 0, 0, NULL);
4600     ok (hchild != 0, "Failed to create child window\n");
4601     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4602
4603     trace("testing scroll APIs on a visible child window %p\n", hchild);
4604     test_scroll_messages(hchild);
4605
4606     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4607     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4608
4609     DestroyWindow(hchild);
4610     flush_sequence();
4611
4612     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4613                              0, 0, 10, 10, hparent, 0, 0, NULL);
4614     ok (hchild != 0, "Failed to create child window\n");
4615     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4616     
4617     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4618                                100, 100, 50, 50, hparent, 0, 0, NULL);
4619     ok (hchild2 != 0, "Failed to create child2 window\n");
4620     flush_sequence();
4621
4622     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4623                               0, 100, 50, 50, hchild, 0, 0, NULL);
4624     ok (hbutton != 0, "Failed to create button window\n");
4625
4626     /* test WM_SETREDRAW on a not visible child window */
4627     test_WM_SETREDRAW(hchild);
4628
4629     ShowWindow(hchild, SW_SHOW);
4630     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4631
4632     /* check parent messages too */
4633     log_all_parent_messages++;
4634     ShowWindow(hchild, SW_HIDE);
4635     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4636     log_all_parent_messages--;
4637
4638     ShowWindow(hchild, SW_SHOW);
4639     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4640
4641     ShowWindow(hchild, SW_HIDE);
4642     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4643
4644     ShowWindow(hchild, SW_SHOW);
4645     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4646
4647     /* test WM_SETREDRAW on a visible child window */
4648     test_WM_SETREDRAW(hchild);
4649
4650     log_all_parent_messages++;
4651     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4652     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4653     log_all_parent_messages--;
4654
4655     ShowWindow(hchild, SW_HIDE);
4656     flush_sequence();
4657     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4658     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4659
4660     ShowWindow(hchild, SW_HIDE);
4661     flush_sequence();
4662     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4663     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4664
4665     /* DestroyWindow sequence below expects that a child has focus */
4666     SetFocus(hchild);
4667     flush_sequence();
4668
4669     DestroyWindow(hchild);
4670     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4671     DestroyWindow(hchild2);
4672     DestroyWindow(hbutton);
4673
4674     flush_sequence();
4675     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4676                              0, 0, 100, 100, hparent, 0, 0, NULL);
4677     ok (hchild != 0, "Failed to create child popup window\n");
4678     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4679     DestroyWindow(hchild);
4680
4681     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4682     flush_sequence();
4683     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4684                              0, 0, 100, 100, hparent, 0, 0, NULL);
4685     ok (hchild != 0, "Failed to create popup window\n");
4686     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4687     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4688     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4689     flush_sequence();
4690     ShowWindow(hchild, SW_SHOW);
4691     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4692     flush_sequence();
4693     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4694     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4695     flush_sequence();
4696     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4697     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4698     DestroyWindow(hchild);
4699
4700     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4701      * changes nothing in message sequences.
4702      */
4703     flush_sequence();
4704     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4705                              0, 0, 100, 100, hparent, 0, 0, NULL);
4706     ok (hchild != 0, "Failed to create popup window\n");
4707     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4708     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4709     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4710     flush_sequence();
4711     ShowWindow(hchild, SW_SHOW);
4712     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4713     flush_sequence();
4714     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4715     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4716     DestroyWindow(hchild);
4717
4718     flush_sequence();
4719     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4720                            0, 0, 100, 100, hparent, 0, 0, NULL);
4721     ok(hwnd != 0, "Failed to create custom dialog window\n");
4722     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4723
4724     if(0) {
4725     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4726     test_scroll_messages(hwnd);
4727     }
4728
4729     flush_sequence();
4730
4731     test_def_id = 1;
4732     SendMessage(hwnd, WM_NULL, 0, 0);
4733
4734     flush_sequence();
4735     after_end_dialog = 1;
4736     EndDialog( hwnd, 0 );
4737     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4738
4739     DestroyWindow(hwnd);
4740     after_end_dialog = 0;
4741     test_def_id = 0;
4742
4743     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4744                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4745     ok(hwnd != 0, "Failed to create custom dialog window\n");
4746     flush_sequence();
4747     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4748     ShowWindow(hwnd, SW_SHOW);
4749     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4750     DestroyWindow(hwnd);
4751
4752     flush_sequence();
4753     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4754     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4755
4756     DestroyWindow(hparent);
4757     flush_sequence();
4758
4759     /* Message sequence for SetMenu */
4760     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4761     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4762
4763     hmenu = CreateMenu();
4764     ok (hmenu != 0, "Failed to create menu\n");
4765     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4766     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4767                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4768     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4769     ok (SetMenu(hwnd, 0), "SetMenu\n");
4770     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4771     ok (SetMenu(hwnd, 0), "SetMenu\n");
4772     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4773     ShowWindow(hwnd, SW_SHOW);
4774     UpdateWindow( hwnd );
4775     flush_events();
4776     flush_sequence();
4777     ok (SetMenu(hwnd, 0), "SetMenu\n");
4778     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4779     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4780     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4781
4782     UpdateWindow( hwnd );
4783     flush_events();
4784     flush_sequence();
4785     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4786     flush_events();
4787     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4788
4789     DestroyWindow(hwnd);
4790     flush_sequence();
4791
4792     /* Message sequence for EnableWindow */
4793     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4794                               100, 100, 200, 200, 0, 0, 0, NULL);
4795     ok (hparent != 0, "Failed to create parent window\n");
4796     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4797                              0, 0, 10, 10, hparent, 0, 0, NULL);
4798     ok (hchild != 0, "Failed to create child window\n");
4799
4800     SetFocus(hchild);
4801     flush_events();
4802     flush_sequence();
4803
4804     EnableWindow(hparent, FALSE);
4805     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4806
4807     EnableWindow(hparent, TRUE);
4808     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4809
4810     flush_events();
4811     flush_sequence();
4812
4813     test_MsgWaitForMultipleObjects(hparent);
4814
4815     /* the following test causes an exception in user.exe under win9x */
4816     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4817     {
4818         DestroyWindow(hparent);
4819         flush_sequence();
4820         return;
4821     }
4822     PostMessageW( hparent, WM_USER+1, 0, 0 );
4823     /* PeekMessage(NULL) fails, but still removes the message */
4824     SetLastError(0xdeadbeef);
4825     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4826     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4827         GetLastError() == 0xdeadbeef, /* NT4 */
4828         "last error is %d\n", GetLastError() );
4829     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4830     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4831
4832     DestroyWindow(hchild);
4833     DestroyWindow(hparent);
4834     flush_sequence();
4835
4836     /* Message sequences for WM_SETICON */
4837     trace("testing WM_SETICON\n");
4838     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4839                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4840                            NULL, NULL, 0);
4841     ShowWindow(hwnd, SW_SHOW);
4842     UpdateWindow(hwnd);
4843     flush_events();
4844     flush_sequence();
4845     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4846     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4847
4848     ShowWindow(hwnd, SW_HIDE);
4849     flush_events();
4850     flush_sequence();
4851     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4852     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4853     DestroyWindow(hwnd);
4854     flush_sequence();
4855
4856     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4857                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4858                            NULL, NULL, 0);
4859     ShowWindow(hwnd, SW_SHOW);
4860     UpdateWindow(hwnd);
4861     flush_events();
4862     flush_sequence();
4863     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4864     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4865
4866     ShowWindow(hwnd, SW_HIDE);
4867     flush_events();
4868     flush_sequence();
4869     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4870     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4871
4872     flush_sequence();
4873     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4874     if (!res)
4875     {
4876         todo_wine win_skip( "Message 0x3b not supported\n" );
4877         goto done;
4878     }
4879     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4880     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4881     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4882     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4883     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4884     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4885     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4886     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4887
4888     flush_sequence();
4889     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4890     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4891     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4892     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4893     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4894     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4895
4896     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4897     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4898     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4899
4900     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4901     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4902     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4903
4904 done:
4905     DestroyWindow(hwnd);
4906     flush_sequence();
4907 }
4908
4909 static void test_setwindowpos(void)
4910 {
4911     HWND hwnd;
4912     RECT rc;
4913     LRESULT res;
4914     const INT winX = 100;
4915     const INT winY = 100;
4916     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4917
4918     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4919                            0, 0, winX, winY, 0,
4920                            NULL, NULL, 0);
4921
4922     GetWindowRect(hwnd, &rc);
4923     expect(sysX, rc.right);
4924     expect(winY, rc.bottom);
4925
4926     flush_events();
4927     flush_sequence();
4928     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4929     ok_sequence(WmZOrder, "Z-Order", TRUE);
4930     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4931
4932     GetWindowRect(hwnd, &rc);
4933     expect(sysX, rc.right);
4934     expect(winY, rc.bottom);
4935     DestroyWindow(hwnd);
4936 }
4937
4938 static void invisible_parent_tests(void)
4939 {
4940     HWND hparent, hchild;
4941
4942     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4943                               100, 100, 200, 200, 0, 0, 0, NULL);
4944     ok (hparent != 0, "Failed to create parent window\n");
4945     flush_sequence();
4946
4947     /* test showing child with hidden parent */
4948
4949     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4950                              0, 0, 10, 10, hparent, 0, 0, NULL);
4951     ok (hchild != 0, "Failed to create child window\n");
4952     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4953
4954     ShowWindow( hchild, SW_MINIMIZE );
4955     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4956     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4957     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4958
4959     /* repeat */
4960     flush_events();
4961     flush_sequence();
4962     ShowWindow( hchild, SW_MINIMIZE );
4963     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4964
4965     DestroyWindow(hchild);
4966     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4967                              0, 0, 10, 10, hparent, 0, 0, NULL);
4968     flush_sequence();
4969
4970     ShowWindow( hchild, SW_MAXIMIZE );
4971     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4972     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4973     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4974
4975     /* repeat */
4976     flush_events();
4977     flush_sequence();
4978     ShowWindow( hchild, SW_MAXIMIZE );
4979     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4980
4981     DestroyWindow(hchild);
4982     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4983                              0, 0, 10, 10, hparent, 0, 0, NULL);
4984     flush_sequence();
4985
4986     ShowWindow( hchild, SW_RESTORE );
4987     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4988     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4989     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4990
4991     DestroyWindow(hchild);
4992     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4993                              0, 0, 10, 10, hparent, 0, 0, NULL);
4994     flush_sequence();
4995
4996     ShowWindow( hchild, SW_SHOWMINIMIZED );
4997     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4998     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4999     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5000
5001     /* repeat */
5002     flush_events();
5003     flush_sequence();
5004     ShowWindow( hchild, SW_SHOWMINIMIZED );
5005     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5006
5007     DestroyWindow(hchild);
5008     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5009                              0, 0, 10, 10, hparent, 0, 0, NULL);
5010     flush_sequence();
5011
5012     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5013     ShowWindow( hchild, SW_SHOWMAXIMIZED );
5014     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5015     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5016     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5017
5018     DestroyWindow(hchild);
5019     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5020                              0, 0, 10, 10, hparent, 0, 0, NULL);
5021     flush_sequence();
5022
5023     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5024     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5025     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5026     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5027
5028     /* repeat */
5029     flush_events();
5030     flush_sequence();
5031     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5032     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5033
5034     DestroyWindow(hchild);
5035     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5036                              0, 0, 10, 10, hparent, 0, 0, NULL);
5037     flush_sequence();
5038
5039     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5040     ShowWindow( hchild, SW_FORCEMINIMIZE );
5041     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5042 todo_wine {
5043     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5044 }
5045     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5046
5047     DestroyWindow(hchild);
5048     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5049                              0, 0, 10, 10, hparent, 0, 0, NULL);
5050     flush_sequence();
5051
5052     ShowWindow( hchild, SW_SHOWNA );
5053     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5054     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5055     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5056
5057     /* repeat */
5058     flush_events();
5059     flush_sequence();
5060     ShowWindow( hchild, SW_SHOWNA );
5061     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5062
5063     DestroyWindow(hchild);
5064     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5065                              0, 0, 10, 10, hparent, 0, 0, NULL);
5066     flush_sequence();
5067
5068     ShowWindow( hchild, SW_SHOW );
5069     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5070     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5071     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5072
5073     /* repeat */
5074     flush_events();
5075     flush_sequence();
5076     ShowWindow( hchild, SW_SHOW );
5077     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5078
5079     ShowWindow( hchild, SW_HIDE );
5080     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5081     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5082     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5083
5084     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5085     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5086     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5087     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5088
5089     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5090     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5091     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5092     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5093
5094     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5095     flush_sequence();
5096     DestroyWindow(hchild);
5097     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5098
5099     DestroyWindow(hparent);
5100     flush_sequence();
5101 }
5102
5103 /****************** button message test *************************/
5104 #define ID_BUTTON 0x000e
5105
5106 static const struct message WmSetFocusButtonSeq[] =
5107 {
5108     { HCBT_SETFOCUS, hook },
5109     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5110     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5111     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5112     { WM_SETFOCUS, sent|wparam, 0 },
5113     { WM_CTLCOLORBTN, sent|parent },
5114     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5115     { WM_APP, sent|wparam|lparam, 0, 0 },
5116     { 0 }
5117 };
5118 static const struct message WmKillFocusButtonSeq[] =
5119 {
5120     { HCBT_SETFOCUS, hook },
5121     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5122     { WM_KILLFOCUS, sent|wparam, 0 },
5123     { WM_CTLCOLORBTN, sent|parent },
5124     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5125     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5126     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5127     { WM_APP, sent|wparam|lparam, 0, 0 },
5128     { WM_PAINT, sent },
5129     { WM_CTLCOLORBTN, sent|parent },
5130     { 0 }
5131 };
5132 static const struct message WmSetFocusStaticSeq[] =
5133 {
5134     { HCBT_SETFOCUS, hook },
5135     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5136     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5137     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5138     { WM_SETFOCUS, sent|wparam, 0 },
5139     { WM_CTLCOLORSTATIC, sent|parent },
5140     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5141     { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5142     { WM_APP, sent|wparam|lparam, 0, 0 },
5143     { 0 }
5144 };
5145 static const struct message WmKillFocusStaticSeq[] =
5146 {
5147     { HCBT_SETFOCUS, hook },
5148     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5149     { WM_KILLFOCUS, sent|wparam, 0 },
5150     { WM_CTLCOLORSTATIC, sent|parent },
5151     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5152     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5153     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5154     { WM_APP, sent|wparam|lparam, 0, 0 },
5155     { WM_PAINT, sent },
5156     { WM_CTLCOLORSTATIC, sent|parent },
5157     { 0 }
5158 };
5159 static const struct message WmSetFocusOwnerdrawSeq[] =
5160 {
5161     { HCBT_SETFOCUS, hook },
5162     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5163     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5164     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5165     { WM_SETFOCUS, sent|wparam, 0 },
5166     { WM_CTLCOLORBTN, sent|parent },
5167     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5168     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5169     { WM_APP, sent|wparam|lparam, 0, 0 },
5170     { 0 }
5171 };
5172 static const struct message WmKillFocusOwnerdrawSeq[] =
5173 {
5174     { HCBT_SETFOCUS, hook },
5175     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5176     { WM_KILLFOCUS, sent|wparam, 0 },
5177     { WM_CTLCOLORBTN, sent|parent },
5178     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5179     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5180     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5181     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5182     { WM_APP, sent|wparam|lparam, 0, 0 },
5183     { WM_PAINT, sent },
5184     { WM_CTLCOLORBTN, sent|parent },
5185     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5186     { 0 }
5187 };
5188 static const struct message WmLButtonDownSeq[] =
5189 {
5190     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5191     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5192     { HCBT_SETFOCUS, hook },
5193     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5194     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5195     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5196     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5197     { WM_CTLCOLORBTN, sent|defwinproc },
5198     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5199     { WM_CTLCOLORBTN, sent|defwinproc },
5200     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5201     { 0 }
5202 };
5203 static const struct message WmLButtonUpSeq[] =
5204 {
5205     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5206     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5207     { WM_CTLCOLORBTN, sent|defwinproc },
5208     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5209     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5210     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5211     { 0 }
5212 };
5213 static const struct message WmSetFontButtonSeq[] =
5214 {
5215     { WM_SETFONT, sent },
5216     { WM_PAINT, sent },
5217     { WM_ERASEBKGND, sent|defwinproc|optional },
5218     { WM_CTLCOLORBTN, sent|defwinproc },
5219     { 0 }
5220 };
5221 static const struct message WmSetStyleButtonSeq[] =
5222 {
5223     { BM_SETSTYLE, sent },
5224     { WM_APP, sent|wparam|lparam, 0, 0 },
5225     { WM_PAINT, sent },
5226     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5227     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5228     { WM_CTLCOLORBTN, sent|parent },
5229     { 0 }
5230 };
5231 static const struct message WmSetStyleStaticSeq[] =
5232 {
5233     { BM_SETSTYLE, sent },
5234     { WM_APP, sent|wparam|lparam, 0, 0 },
5235     { WM_PAINT, sent },
5236     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5237     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5238     { WM_CTLCOLORSTATIC, sent|parent },
5239     { 0 }
5240 };
5241 static const struct message WmSetStyleUserSeq[] =
5242 {
5243     { BM_SETSTYLE, sent },
5244     { WM_APP, sent|wparam|lparam, 0, 0 },
5245     { WM_PAINT, sent },
5246     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5247     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5248     { WM_CTLCOLORBTN, sent|parent },
5249     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5250     { 0 }
5251 };
5252 static const struct message WmSetStyleOwnerdrawSeq[] =
5253 {
5254     { BM_SETSTYLE, sent },
5255     { WM_APP, sent|wparam|lparam, 0, 0 },
5256     { WM_PAINT, sent },
5257     { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5258     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5259     { WM_CTLCOLORBTN, sent|parent },
5260     { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5261     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5262     { 0 }
5263 };
5264 static const struct message WmSetStateButtonSeq[] =
5265 {
5266     { BM_SETSTATE, sent },
5267     { WM_CTLCOLORBTN, sent|parent },
5268     { WM_APP, sent|wparam|lparam, 0, 0 },
5269     { 0 }
5270 };
5271 static const struct message WmSetStateStaticSeq[] =
5272 {
5273     { BM_SETSTATE, sent },
5274     { WM_CTLCOLORSTATIC, sent|parent },
5275     { WM_APP, sent|wparam|lparam, 0, 0 },
5276     { 0 }
5277 };
5278 static const struct message WmSetStateUserSeq[] =
5279 {
5280     { BM_SETSTATE, sent },
5281     { WM_CTLCOLORBTN, sent|parent },
5282     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5283     { WM_APP, sent|wparam|lparam, 0, 0 },
5284     { 0 }
5285 };
5286 static const struct message WmSetStateOwnerdrawSeq[] =
5287 {
5288     { BM_SETSTATE, sent },
5289     { WM_CTLCOLORBTN, sent|parent },
5290     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5291     { WM_APP, sent|wparam|lparam, 0, 0 },
5292     { 0 }
5293 };
5294 static const struct message WmClearStateButtonSeq[] =
5295 {
5296     { BM_SETSTATE, sent },
5297     { WM_CTLCOLORBTN, sent|parent },
5298     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5299     { WM_APP, sent|wparam|lparam, 0, 0 },
5300     { 0 }
5301 };
5302 static const struct message WmClearStateOwnerdrawSeq[] =
5303 {
5304     { BM_SETSTATE, sent },
5305     { WM_CTLCOLORBTN, sent|parent },
5306     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5307     { WM_APP, sent|wparam|lparam, 0, 0 },
5308     { 0 }
5309 };
5310 static const struct message WmSetCheckIgnoredSeq[] =
5311 {
5312     { BM_SETCHECK, sent },
5313     { WM_APP, sent|wparam|lparam, 0, 0 },
5314     { 0 }
5315 };
5316 static const struct message WmSetCheckStaticSeq[] =
5317 {
5318     { BM_SETCHECK, sent },
5319     { WM_CTLCOLORSTATIC, sent|parent },
5320     { WM_APP, sent|wparam|lparam, 0, 0 },
5321     { 0 }
5322 };
5323
5324 static WNDPROC old_button_proc;
5325
5326 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5327 {
5328     static LONG defwndproc_counter = 0;
5329     LRESULT ret;
5330     struct recvd_message msg;
5331
5332     if (ignore_message( message )) return 0;
5333
5334     switch (message)
5335     {
5336     case WM_SYNCPAINT:
5337         break;
5338     case BM_SETSTATE:
5339         if (GetCapture())
5340             ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5341         /* fall through */
5342     default:
5343         msg.hwnd = hwnd;
5344         msg.message = message;
5345         msg.flags = sent|wparam|lparam;
5346         if (defwndproc_counter) msg.flags |= defwinproc;
5347         msg.wParam = wParam;
5348         msg.lParam = lParam;
5349         msg.descr = "button";
5350         add_message(&msg);
5351     }
5352
5353     defwndproc_counter++;
5354     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5355     defwndproc_counter--;
5356
5357     return ret;
5358 }
5359
5360 static void subclass_button(void)
5361 {
5362     WNDCLASSA cls;
5363
5364     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5365
5366     old_button_proc = cls.lpfnWndProc;
5367
5368     cls.hInstance = GetModuleHandle(0);
5369     cls.lpfnWndProc = button_hook_proc;
5370     cls.lpszClassName = "my_button_class";
5371     UnregisterClass(cls.lpszClassName, cls.hInstance);
5372     if (!RegisterClassA(&cls)) assert(0);
5373 }
5374
5375 static void test_button_messages(void)
5376 {
5377     static const struct
5378     {
5379         DWORD style;
5380         DWORD dlg_code;
5381         const struct message *setfocus;
5382         const struct message *killfocus;
5383         const struct message *setstyle;
5384         const struct message *setstate;
5385         const struct message *clearstate;
5386         const struct message *setcheck;
5387     } button[] = {
5388         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5389           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5390           WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5391         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5392           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5393           WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5394         { BS_CHECKBOX, DLGC_BUTTON,
5395           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5396           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5397         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5398           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5399           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5400         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5401           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5402           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5403         { BS_3STATE, DLGC_BUTTON,
5404           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5405           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5406         { BS_AUTO3STATE, DLGC_BUTTON,
5407           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5408           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5409         { BS_GROUPBOX, DLGC_STATIC,
5410           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5411           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5412         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5413           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5414           WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5415         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5416           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5417           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5418         { BS_OWNERDRAW, DLGC_BUTTON,
5419           WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5420           WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5421     };
5422     unsigned int i;
5423     HWND hwnd, parent;
5424     DWORD dlg_code;
5425     HFONT zfont;
5426
5427     /* selection with VK_SPACE should capture button window */
5428     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5429                            0, 0, 50, 14, 0, 0, 0, NULL);
5430     ok(hwnd != 0, "Failed to create button window\n");
5431     ReleaseCapture();
5432     SetFocus(hwnd);
5433     SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5434     ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5435     SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5436     DestroyWindow(hwnd);
5437
5438     subclass_button();
5439
5440     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5441                              100, 100, 200, 200, 0, 0, 0, NULL);
5442     ok(parent != 0, "Failed to create parent window\n");
5443
5444     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5445     {
5446         MSG msg;
5447         DWORD style, state;
5448
5449         trace("button style %08x\n", button[i].style);
5450
5451         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5452                                0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5453         ok(hwnd != 0, "Failed to create button window\n");
5454
5455         style = GetWindowLongA(hwnd, GWL_STYLE);
5456         style &= ~(WS_CHILD | BS_NOTIFY);
5457         /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5458         if (button[i].style == BS_USERBUTTON)
5459             ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5460         else
5461             ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5462
5463         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5464         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5465
5466         ShowWindow(hwnd, SW_SHOW);
5467         UpdateWindow(hwnd);
5468         SetFocus(0);
5469         flush_events();
5470         SetFocus(0);
5471         flush_sequence();
5472
5473         log_all_parent_messages++;
5474
5475         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5476         SetFocus(hwnd);
5477         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5478         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5479         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5480
5481         SetFocus(0);
5482         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5483         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5484         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5485
5486         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5487
5488         SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5489         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5490         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5491         ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5492
5493         style = GetWindowLongA(hwnd, GWL_STYLE);
5494         style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5495         /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5496         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5497
5498         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5499         ok(state == 0, "expected state 0, got %04x\n", state);
5500
5501         flush_sequence();
5502
5503         SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5504         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5505         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5506         ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5507
5508         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5509         ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5510
5511         style = GetWindowLongA(hwnd, GWL_STYLE);
5512         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5513         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5514
5515         flush_sequence();
5516
5517         SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5518         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5519         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5520         ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5521
5522         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5523         ok(state == 0, "expected state 0, got %04x\n", state);
5524
5525         style = GetWindowLongA(hwnd, GWL_STYLE);
5526         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5527         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5528
5529         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5530         ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5531
5532         flush_sequence();
5533
5534         SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5535         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5536         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5537         ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5538
5539         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5540         ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5541
5542         style = GetWindowLongA(hwnd, GWL_STYLE);
5543         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5544         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5545
5546         flush_sequence();
5547
5548         SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5549         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5550         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5551         ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5552
5553         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5554         if (button[i].style == BS_PUSHBUTTON ||
5555             button[i].style == BS_DEFPUSHBUTTON ||
5556             button[i].style == BS_GROUPBOX ||
5557             button[i].style == BS_USERBUTTON ||
5558             button[i].style == BS_OWNERDRAW)
5559             ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5560         else
5561             ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5562
5563         style = GetWindowLongA(hwnd, GWL_STYLE);
5564         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5565         if (button[i].style == BS_RADIOBUTTON ||
5566             button[i].style == BS_AUTORADIOBUTTON)
5567             ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5568         else
5569             ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5570
5571         log_all_parent_messages--;
5572
5573         DestroyWindow(hwnd);
5574     }
5575
5576     DestroyWindow(parent);
5577
5578     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5579                            0, 0, 50, 14, 0, 0, 0, NULL);
5580     ok(hwnd != 0, "Failed to create button window\n");
5581
5582     SetForegroundWindow(hwnd);
5583     flush_events();
5584
5585     SetActiveWindow(hwnd);
5586     SetFocus(0);
5587     flush_sequence();
5588
5589     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5590     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5591
5592     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5593     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5594
5595     flush_sequence();
5596     zfont = GetStockObject(SYSTEM_FONT);
5597     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5598     UpdateWindow(hwnd);
5599     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5600
5601     DestroyWindow(hwnd);
5602 }
5603
5604 /****************** static message test *************************/
5605 static const struct message WmSetFontStaticSeq[] =
5606 {
5607     { WM_SETFONT, sent },
5608     { WM_PAINT, sent|defwinproc|optional },
5609     { WM_ERASEBKGND, sent|defwinproc|optional },
5610     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5611     { 0 }
5612 };
5613
5614 static WNDPROC old_static_proc;
5615
5616 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5617 {
5618     static LONG defwndproc_counter = 0;
5619     LRESULT ret;
5620     struct recvd_message msg;
5621
5622     if (ignore_message( message )) return 0;
5623
5624     msg.hwnd = hwnd;
5625     msg.message = message;
5626     msg.flags = sent|wparam|lparam;
5627     if (defwndproc_counter) msg.flags |= defwinproc;
5628     msg.wParam = wParam;
5629     msg.lParam = lParam;
5630     msg.descr = "static";
5631     add_message(&msg);
5632
5633     defwndproc_counter++;
5634     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5635     defwndproc_counter--;
5636
5637     return ret;
5638 }
5639
5640 static void subclass_static(void)
5641 {
5642     WNDCLASSA cls;
5643
5644     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5645
5646     old_static_proc = cls.lpfnWndProc;
5647
5648     cls.hInstance = GetModuleHandle(0);
5649     cls.lpfnWndProc = static_hook_proc;
5650     cls.lpszClassName = "my_static_class";
5651     UnregisterClass(cls.lpszClassName, cls.hInstance);
5652     if (!RegisterClassA(&cls)) assert(0);
5653 }
5654
5655 static void test_static_messages(void)
5656 {
5657     /* FIXME: make as comprehensive as the button message test */
5658     static const struct
5659     {
5660         DWORD style;
5661         DWORD dlg_code;
5662         const struct message *setfont;
5663     } static_ctrl[] = {
5664         { SS_LEFT, DLGC_STATIC,
5665           WmSetFontStaticSeq }
5666     };
5667     unsigned int i;
5668     HWND hwnd;
5669     DWORD dlg_code;
5670
5671     subclass_static();
5672
5673     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5674     {
5675         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5676                                0, 0, 50, 14, 0, 0, 0, NULL);
5677         ok(hwnd != 0, "Failed to create static window\n");
5678
5679         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5680         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5681
5682         ShowWindow(hwnd, SW_SHOW);
5683         UpdateWindow(hwnd);
5684         SetFocus(0);
5685         flush_sequence();
5686
5687         trace("static style %08x\n", static_ctrl[i].style);
5688         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5689         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5690
5691         DestroyWindow(hwnd);
5692     }
5693 }
5694
5695 /****************** ComboBox message test *************************/
5696 #define ID_COMBOBOX 0x000f
5697
5698 static const struct message WmKeyDownComboSeq[] =
5699 {
5700     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5701     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5702     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5703     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5704     { WM_CTLCOLOREDIT, sent|parent },
5705     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5706     { 0 }
5707 };
5708
5709 static WNDPROC old_combobox_proc;
5710
5711 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5712 {
5713     static LONG defwndproc_counter = 0;
5714     LRESULT ret;
5715     struct recvd_message msg;
5716
5717     /* do not log painting messages */
5718     if (message != WM_PAINT &&
5719         message != WM_NCPAINT &&
5720         message != WM_SYNCPAINT &&
5721         message != WM_ERASEBKGND &&
5722         message != WM_NCHITTEST &&
5723         message != WM_GETTEXT &&
5724         !ignore_message( message ))
5725     {
5726         msg.hwnd = hwnd;
5727         msg.message = message;
5728         msg.flags = sent|wparam|lparam;
5729         if (defwndproc_counter) msg.flags |= defwinproc;
5730         msg.wParam = wParam;
5731         msg.lParam = lParam;
5732         msg.descr = "combo";
5733         add_message(&msg);
5734     }
5735
5736     defwndproc_counter++;
5737     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5738     defwndproc_counter--;
5739
5740     return ret;
5741 }
5742
5743 static void subclass_combobox(void)
5744 {
5745     WNDCLASSA cls;
5746
5747     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5748
5749     old_combobox_proc = cls.lpfnWndProc;
5750
5751     cls.hInstance = GetModuleHandle(0);
5752     cls.lpfnWndProc = combobox_hook_proc;
5753     cls.lpszClassName = "my_combobox_class";
5754     UnregisterClass(cls.lpszClassName, cls.hInstance);
5755     if (!RegisterClassA(&cls)) assert(0);
5756 }
5757
5758 static void test_combobox_messages(void)
5759 {
5760     HWND parent, combo;
5761     LRESULT ret;
5762
5763     subclass_combobox();
5764
5765     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5766                              100, 100, 200, 200, 0, 0, 0, NULL);
5767     ok(parent != 0, "Failed to create parent window\n");
5768     flush_sequence();
5769
5770     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5771                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5772     ok(combo != 0, "Failed to create combobox window\n");
5773
5774     UpdateWindow(combo);
5775
5776     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5777     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5778
5779     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5780     ok(ret == 0, "expected 0, got %ld\n", ret);
5781     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5782     ok(ret == 1, "expected 1, got %ld\n", ret);
5783     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5784     ok(ret == 2, "expected 2, got %ld\n", ret);
5785
5786     SendMessage(combo, CB_SETCURSEL, 0, 0);
5787     SetFocus(combo);
5788     flush_sequence();
5789
5790     log_all_parent_messages++;
5791     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5792     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5793     log_all_parent_messages--;
5794     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5795
5796     DestroyWindow(combo);
5797     DestroyWindow(parent);
5798 }
5799
5800 /****************** WM_IME_KEYDOWN message test *******************/
5801
5802 static const struct message WmImeKeydownMsgSeq_0[] =
5803 {
5804     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5805     { WM_CHAR, wparam, 'A' },
5806     { 0 }
5807 };
5808
5809 static const struct message WmImeKeydownMsgSeq_1[] =
5810 {
5811     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5812     { WM_CHAR,    optional|wparam, VK_RETURN },
5813     { 0 }
5814 };
5815
5816 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5817 {
5818     struct recvd_message msg;
5819
5820     msg.hwnd = hwnd;
5821     msg.message = message;
5822     msg.flags = wparam|lparam;
5823     msg.wParam = wParam;
5824     msg.lParam = lParam;
5825     msg.descr = "wmime_keydown";
5826     add_message(&msg);
5827
5828     return DefWindowProcA(hwnd, message, wParam, lParam);
5829 }
5830
5831 static void register_wmime_keydown_class(void)
5832 {
5833     WNDCLASSA cls;
5834
5835     ZeroMemory(&cls, sizeof(WNDCLASSA));
5836     cls.lpfnWndProc = wmime_keydown_procA;
5837     cls.hInstance = GetModuleHandleA(0);
5838     cls.lpszClassName = "wmime_keydown_class";
5839     if (!RegisterClassA(&cls)) assert(0);
5840 }
5841
5842 static void test_wmime_keydown_message(void)
5843 {
5844     HWND hwnd;
5845     MSG msg;
5846
5847     trace("Message sequences by WM_IME_KEYDOWN\n");
5848
5849     register_wmime_keydown_class();
5850     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5851                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5852                            NULL, NULL, 0);
5853     flush_events();
5854     flush_sequence();
5855
5856     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5857     SendMessage(hwnd, WM_CHAR, 'A', 1);
5858     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5859
5860     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5861     {
5862         TranslateMessage(&msg);
5863         DispatchMessage(&msg);
5864     }
5865     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5866
5867     DestroyWindow(hwnd);
5868 }
5869
5870 /************* painting message test ********************/
5871
5872 void dump_region(HRGN hrgn)
5873 {
5874     DWORD i, size;
5875     RGNDATA *data = NULL;
5876     RECT *rect;
5877
5878     if (!hrgn)
5879     {
5880         printf( "null region\n" );
5881         return;
5882     }
5883     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5884     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5885     GetRegionData( hrgn, size, data );
5886     printf("%d rects:", data->rdh.nCount );
5887     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5888         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5889     printf("\n");
5890     HeapFree( GetProcessHeap(), 0, data );
5891 }
5892
5893 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5894 {
5895     INT ret;
5896     RECT r1, r2;
5897     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5898     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5899
5900     ret = GetUpdateRgn( hwnd, update, FALSE );
5901     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5902     if (ret == NULLREGION)
5903     {
5904         ok( !hrgn, "Update region shouldn't be empty\n" );
5905     }
5906     else
5907     {
5908         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5909         {
5910             ok( 0, "Regions are different\n" );
5911             if (winetest_debug > 0)
5912             {
5913                 printf( "Update region: " );
5914                 dump_region( update );
5915                 printf( "Wanted region: " );
5916                 dump_region( hrgn );
5917             }
5918         }
5919     }
5920     GetRgnBox( update, &r1 );
5921     GetUpdateRect( hwnd, &r2, FALSE );
5922     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5923         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5924         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5925
5926     DeleteObject( tmp );
5927     DeleteObject( update );
5928 }
5929
5930 static const struct message WmInvalidateRgn[] = {
5931     { WM_NCPAINT, sent },
5932     { WM_GETTEXT, sent|defwinproc|optional },
5933     { 0 }
5934 };
5935
5936 static const struct message WmGetUpdateRect[] = {
5937     { WM_NCPAINT, sent },
5938     { WM_GETTEXT, sent|defwinproc|optional },
5939     { WM_PAINT, sent },
5940     { 0 }
5941 };
5942
5943 static const struct message WmInvalidateFull[] = {
5944     { WM_NCPAINT, sent|wparam, 1 },
5945     { WM_GETTEXT, sent|defwinproc|optional },
5946     { 0 }
5947 };
5948
5949 static const struct message WmInvalidateErase[] = {
5950     { WM_NCPAINT, sent|wparam, 1 },
5951     { WM_GETTEXT, sent|defwinproc|optional },
5952     { WM_ERASEBKGND, sent },
5953     { 0 }
5954 };
5955
5956 static const struct message WmInvalidatePaint[] = {
5957     { WM_PAINT, sent },
5958     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5959     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5960     { 0 }
5961 };
5962
5963 static const struct message WmInvalidateErasePaint[] = {
5964     { WM_PAINT, sent },
5965     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5966     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5967     { WM_ERASEBKGND, sent|beginpaint|optional },
5968     { 0 }
5969 };
5970
5971 static const struct message WmInvalidateErasePaint2[] = {
5972     { WM_PAINT, sent },
5973     { WM_NCPAINT, sent|beginpaint },
5974     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5975     { WM_ERASEBKGND, sent|beginpaint|optional },
5976     { 0 }
5977 };
5978
5979 static const struct message WmErase[] = {
5980     { WM_ERASEBKGND, sent },
5981     { 0 }
5982 };
5983
5984 static const struct message WmPaint[] = {
5985     { WM_PAINT, sent },
5986     { 0 }
5987 };
5988
5989 static const struct message WmParentOnlyPaint[] = {
5990     { WM_PAINT, sent|parent },
5991     { 0 }
5992 };
5993
5994 static const struct message WmInvalidateParent[] = {
5995     { WM_NCPAINT, sent|parent },
5996     { WM_GETTEXT, sent|defwinproc|parent|optional },
5997     { WM_ERASEBKGND, sent|parent },
5998     { 0 }
5999 };
6000
6001 static const struct message WmInvalidateParentChild[] = {
6002     { WM_NCPAINT, sent|parent },
6003     { WM_GETTEXT, sent|defwinproc|parent|optional },
6004     { WM_ERASEBKGND, sent|parent },
6005     { WM_NCPAINT, sent },
6006     { WM_GETTEXT, sent|defwinproc|optional },
6007     { WM_ERASEBKGND, sent },
6008     { 0 }
6009 };
6010
6011 static const struct message WmInvalidateParentChild2[] = {
6012     { WM_ERASEBKGND, sent|parent },
6013     { WM_NCPAINT, sent },
6014     { WM_GETTEXT, sent|defwinproc|optional },
6015     { WM_ERASEBKGND, sent },
6016     { 0 }
6017 };
6018
6019 static const struct message WmParentPaint[] = {
6020     { WM_PAINT, sent|parent },
6021     { WM_PAINT, sent },
6022     { 0 }
6023 };
6024
6025 static const struct message WmParentPaintNc[] = {
6026     { WM_PAINT, sent|parent },
6027     { WM_PAINT, sent },
6028     { WM_NCPAINT, sent|beginpaint },
6029     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6030     { WM_ERASEBKGND, sent|beginpaint|optional },
6031     { 0 }
6032 };
6033
6034 static const struct message WmChildPaintNc[] = {
6035     { WM_PAINT, sent },
6036     { WM_NCPAINT, sent|beginpaint },
6037     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6038     { WM_ERASEBKGND, sent|beginpaint|optional },
6039     { 0 }
6040 };
6041
6042 static const struct message WmParentErasePaint[] = {
6043     { WM_PAINT, sent|parent },
6044     { WM_NCPAINT, sent|parent|beginpaint },
6045     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6046     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6047     { WM_PAINT, sent },
6048     { WM_NCPAINT, sent|beginpaint },
6049     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6050     { WM_ERASEBKGND, sent|beginpaint|optional },
6051     { 0 }
6052 };
6053
6054 static const struct message WmParentOnlyNcPaint[] = {
6055     { WM_PAINT, sent|parent },
6056     { WM_NCPAINT, sent|parent|beginpaint },
6057     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6058     { 0 }
6059 };
6060
6061 static const struct message WmSetParentStyle[] = {
6062     { WM_STYLECHANGING, sent|parent },
6063     { WM_STYLECHANGED, sent|parent },
6064     { 0 }
6065 };
6066
6067 static void test_paint_messages(void)
6068 {
6069     BOOL ret;
6070     RECT rect;
6071     POINT pt;
6072     MSG msg;
6073     HWND hparent, hchild;
6074     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6075     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6076     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6077                                 100, 100, 200, 200, 0, 0, 0, NULL);
6078     ok (hwnd != 0, "Failed to create overlapped window\n");
6079
6080     ShowWindow( hwnd, SW_SHOW );
6081     UpdateWindow( hwnd );
6082     flush_events();
6083     flush_sequence();
6084
6085     check_update_rgn( hwnd, 0 );
6086     SetRectRgn( hrgn, 10, 10, 20, 20 );
6087     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6088     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6089     check_update_rgn( hwnd, hrgn );
6090     SetRectRgn( hrgn2, 20, 20, 30, 30 );
6091     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6092     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6093     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6094     check_update_rgn( hwnd, hrgn );
6095     /* validate everything */
6096     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6097     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6098     check_update_rgn( hwnd, 0 );
6099
6100     /* test empty region */
6101     SetRectRgn( hrgn, 10, 10, 10, 15 );
6102     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6103     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6104     check_update_rgn( hwnd, 0 );
6105     /* test empty rect */
6106     SetRect( &rect, 10, 10, 10, 15 );
6107     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6108     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6109     check_update_rgn( hwnd, 0 );
6110
6111     /* flush pending messages */
6112     flush_events();
6113     flush_sequence();
6114
6115     GetClientRect( hwnd, &rect );
6116     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6117     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6118      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6119      */
6120     trace("testing InvalidateRect(0, NULL, FALSE)\n");
6121     SetRectEmpty( &rect );
6122     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6123     check_update_rgn( hwnd, hrgn );
6124     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6125     flush_events();
6126     ok_sequence( WmPaint, "Paint", FALSE );
6127     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6128     check_update_rgn( hwnd, 0 );
6129
6130     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6131      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6132      */
6133     trace("testing ValidateRect(0, NULL)\n");
6134     SetRectEmpty( &rect );
6135     if (ValidateRect(0, &rect))  /* not supported on Win9x */
6136     {
6137         check_update_rgn( hwnd, hrgn );
6138         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6139         flush_events();
6140         ok_sequence( WmPaint, "Paint", FALSE );
6141         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6142         check_update_rgn( hwnd, 0 );
6143     }
6144
6145     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6146     SetLastError(0xdeadbeef);
6147     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6148     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6149        "wrong error code %d\n", GetLastError());
6150     check_update_rgn( hwnd, 0 );
6151     flush_events();
6152     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6153
6154     trace("testing ValidateRgn(0, NULL)\n");
6155     SetLastError(0xdeadbeef);
6156     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6157     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6158        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6159        "wrong error code %d\n", GetLastError());
6160     check_update_rgn( hwnd, 0 );
6161     flush_events();
6162     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6163
6164     /* now with frame */
6165     SetRectRgn( hrgn, -5, -5, 20, 20 );
6166
6167     /* flush pending messages */
6168     flush_events();
6169     flush_sequence();
6170     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6171     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6172
6173     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
6174     check_update_rgn( hwnd, hrgn );
6175
6176     flush_sequence();
6177     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6178     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6179
6180     flush_sequence();
6181     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6182     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6183
6184     GetClientRect( hwnd, &rect );
6185     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6186     check_update_rgn( hwnd, hrgn );
6187
6188     flush_sequence();
6189     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6190     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6191
6192     flush_sequence();
6193     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6194     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6195     check_update_rgn( hwnd, 0 );
6196
6197     flush_sequence();
6198     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6199     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6200     check_update_rgn( hwnd, 0 );
6201
6202     flush_sequence();
6203     SetRectRgn( hrgn, 0, 0, 100, 100 );
6204     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6205     SetRectRgn( hrgn, 0, 0, 50, 100 );
6206     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6207     SetRectRgn( hrgn, 50, 0, 100, 100 );
6208     check_update_rgn( hwnd, hrgn );
6209     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6210     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
6211     check_update_rgn( hwnd, 0 );
6212
6213     flush_sequence();
6214     SetRectRgn( hrgn, 0, 0, 100, 100 );
6215     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6216     SetRectRgn( hrgn, 0, 0, 100, 50 );
6217     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6218     ok_sequence( WmErase, "Erase", FALSE );
6219     SetRectRgn( hrgn, 0, 50, 100, 100 );
6220     check_update_rgn( hwnd, hrgn );
6221
6222     flush_sequence();
6223     SetRectRgn( hrgn, 0, 0, 100, 100 );
6224     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6225     SetRectRgn( hrgn, 0, 0, 50, 50 );
6226     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6227     ok_sequence( WmPaint, "Paint", FALSE );
6228
6229     flush_sequence();
6230     SetRectRgn( hrgn, -4, -4, -2, -2 );
6231     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6232     SetRectRgn( hrgn, -200, -200, -198, -198 );
6233     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6234     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6235
6236     flush_sequence();
6237     SetRectRgn( hrgn, -4, -4, -2, -2 );
6238     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6239     SetRectRgn( hrgn, -4, -4, -3, -3 );
6240     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6241     SetRectRgn( hrgn, 0, 0, 1, 1 );
6242     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6243     ok_sequence( WmPaint, "Paint", FALSE );
6244
6245     flush_sequence();
6246     SetRectRgn( hrgn, -4, -4, -1, -1 );
6247     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6248     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6249     /* make sure no WM_PAINT was generated */
6250     flush_events();
6251     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6252
6253     flush_sequence();
6254     SetRectRgn( hrgn, -4, -4, -1, -1 );
6255     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6256     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6257     {
6258         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6259         {
6260             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6261             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6262             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6263             ret = GetUpdateRect( hwnd, &rect, FALSE );
6264             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6265             /* this will send WM_NCPAINT and validate the non client area */
6266             ret = GetUpdateRect( hwnd, &rect, TRUE );
6267             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6268         }
6269         DispatchMessage( &msg );
6270     }
6271     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6272
6273     DestroyWindow( hwnd );
6274
6275     /* now test with a child window */
6276
6277     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6278                               100, 100, 200, 200, 0, 0, 0, NULL);
6279     ok (hparent != 0, "Failed to create parent window\n");
6280
6281     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6282                            10, 10, 100, 100, hparent, 0, 0, NULL);
6283     ok (hchild != 0, "Failed to create child window\n");
6284
6285     ShowWindow( hparent, SW_SHOW );
6286     UpdateWindow( hparent );
6287     UpdateWindow( hchild );
6288     flush_events();
6289     flush_sequence();
6290     log_all_parent_messages++;
6291
6292     SetRect( &rect, 0, 0, 50, 50 );
6293     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6294     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6295     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6296
6297     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6298     pt.x = pt.y = 0;
6299     MapWindowPoints( hchild, hparent, &pt, 1 );
6300     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6301     check_update_rgn( hchild, hrgn );
6302     SetRectRgn( hrgn, 0, 0, 50, 50 );
6303     check_update_rgn( hparent, hrgn );
6304     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6305     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6306     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6307     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6308
6309     flush_events();
6310     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6311
6312     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6313     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6314     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6315     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6316     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6317
6318     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6319     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6320     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6321
6322     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6323     flush_sequence();
6324     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6325     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6326     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6327
6328     /* flush all paint messages */
6329     flush_events();
6330     flush_sequence();
6331
6332     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6333     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6334     SetRectRgn( hrgn, 0, 0, 50, 50 );
6335     check_update_rgn( hparent, hrgn );
6336     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6337     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6338     SetRectRgn( hrgn, 0, 0, 50, 50 );
6339     check_update_rgn( hparent, hrgn );
6340
6341     /* flush all paint messages */
6342     flush_events();
6343     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6344     flush_sequence();
6345
6346     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6347     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6348     SetRectRgn( hrgn, 0, 0, 50, 50 );
6349     check_update_rgn( hparent, hrgn );
6350     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6351     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6352     SetRectRgn( hrgn2, 10, 10, 50, 50 );
6353     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6354     check_update_rgn( hparent, hrgn );
6355     /* flush all paint messages */
6356     flush_events();
6357     flush_sequence();
6358
6359     /* same as above but parent gets completely validated */
6360     SetRect( &rect, 20, 20, 30, 30 );
6361     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6362     SetRectRgn( hrgn, 20, 20, 30, 30 );
6363     check_update_rgn( hparent, hrgn );
6364     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6365     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6366     check_update_rgn( hparent, 0 );  /* no update region */
6367     flush_events();
6368     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
6369
6370     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6371     flush_sequence();
6372     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6373     SetRectRgn( hrgn, 20, 20, 30, 30 );
6374     check_update_rgn( hparent, hrgn );
6375     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6376     SetRectRgn( hrgn, 20, 20, 30, 30 );
6377     check_update_rgn( hparent, hrgn );
6378
6379     /* same as above but normal WM_PAINT doesn't validate parent */
6380     flush_sequence();
6381     SetRect( &rect, 20, 20, 30, 30 );
6382     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6383     SetRectRgn( hrgn, 20, 20, 30, 30 );
6384     check_update_rgn( hparent, hrgn );
6385     /* no WM_PAINT in child while parent still pending */
6386     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6387     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6388     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6389     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6390
6391     flush_sequence();
6392     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6393     /* no WM_PAINT in child while parent still pending */
6394     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6395     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6396     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6397     /* now that parent is valid child should get WM_PAINT */
6398     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6399     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6400     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6401     ok_sequence( WmEmptySeq, "No other message", FALSE );
6402
6403     /* same thing with WS_CLIPCHILDREN in parent */
6404     flush_sequence();
6405     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6406     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6407     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6408     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6409     ok_sequence( WmEmptySeq, "No message", FALSE );
6410     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6411     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6412
6413     flush_sequence();
6414     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6415     SetRectRgn( hrgn, 20, 20, 30, 30 );
6416     check_update_rgn( hparent, hrgn );
6417     /* no WM_PAINT in child while parent still pending */
6418     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6419     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6420     /* WM_PAINT in parent first */
6421     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6422     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6423
6424     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6425     flush_sequence();
6426     SetRect( &rect, 0, 0, 30, 30 );
6427     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6428     SetRectRgn( hrgn, 0, 0, 30, 30 );
6429     check_update_rgn( hparent, hrgn );
6430     flush_events();
6431     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6432
6433     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6434     flush_sequence();
6435     SetRect( &rect, -10, 0, 30, 30 );
6436     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6437     SetRect( &rect, 0, 0, 20, 20 );
6438     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6439     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6440     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6441
6442     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6443     flush_sequence();
6444     SetRect( &rect, -10, 0, 30, 30 );
6445     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6446     SetRect( &rect, 0, 0, 100, 100 );
6447     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6448     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6449     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6450     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6451     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6452
6453     /* test RDW_INTERNALPAINT behavior */
6454
6455     flush_sequence();
6456     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6457     flush_events();
6458     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6459
6460     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6461     flush_events();
6462     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6463
6464     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6465     flush_events();
6466     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6467
6468     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6469     UpdateWindow( hparent );
6470     flush_events();
6471     flush_sequence();
6472     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6473     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6474     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6475                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6476     flush_events();
6477     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6478
6479     UpdateWindow( hparent );
6480     flush_events();
6481     flush_sequence();
6482     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6483     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6484     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6485                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6486     flush_events();
6487     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6488
6489     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6490     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6491     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6492     flush_events();
6493     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6494
6495     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6496     UpdateWindow( hparent );
6497     flush_events();
6498     flush_sequence();
6499     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6500     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6501     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6502                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6503     flush_events();
6504     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6505
6506     UpdateWindow( hparent );
6507     flush_events();
6508     flush_sequence();
6509     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6510     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6511     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6512                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6513     flush_events();
6514     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6515
6516     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6517     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6518
6519     UpdateWindow( hparent );
6520     flush_events();
6521     flush_sequence();
6522     trace("testing SetWindowPos(-10000, -10000) on child\n");
6523     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6524     check_update_rgn( hchild, 0 );
6525     flush_events();
6526
6527 #if 0 /* this one doesn't pass under Wine yet */
6528     UpdateWindow( hparent );
6529     flush_events();
6530     flush_sequence();
6531     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6532     ShowWindow( hchild, SW_MINIMIZE );
6533     check_update_rgn( hchild, 0 );
6534     flush_events();
6535 #endif
6536
6537     UpdateWindow( hparent );
6538     flush_events();
6539     flush_sequence();
6540     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6541     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6542     check_update_rgn( hparent, 0 );
6543     flush_events();
6544
6545     log_all_parent_messages--;
6546     DestroyWindow( hparent );
6547     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6548
6549     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6550
6551     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6552                               100, 100, 200, 200, 0, 0, 0, NULL);
6553     ok (hparent != 0, "Failed to create parent window\n");
6554
6555     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6556                            10, 10, 100, 100, hparent, 0, 0, NULL);
6557     ok (hchild != 0, "Failed to create child window\n");
6558
6559     ShowWindow( hparent, SW_SHOW );
6560     UpdateWindow( hparent );
6561     UpdateWindow( hchild );
6562     flush_events();
6563     flush_sequence();
6564
6565     /* moving child outside of parent boundaries changes update region */
6566     SetRect( &rect, 0, 0, 40, 40 );
6567     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6568     SetRectRgn( hrgn, 0, 0, 40, 40 );
6569     check_update_rgn( hchild, hrgn );
6570     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6571     SetRectRgn( hrgn, 10, 0, 40, 40 );
6572     check_update_rgn( hchild, hrgn );
6573     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6574     SetRectRgn( hrgn, 10, 10, 40, 40 );
6575     check_update_rgn( hchild, hrgn );
6576
6577     /* moving parent off-screen does too */
6578     SetRect( &rect, 0, 0, 100, 100 );
6579     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6580     SetRectRgn( hrgn, 0, 0, 100, 100 );
6581     check_update_rgn( hparent, hrgn );
6582     SetRectRgn( hrgn, 10, 10, 40, 40 );
6583     check_update_rgn( hchild, hrgn );
6584     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6585     SetRectRgn( hrgn, 20, 20, 100, 100 );
6586     check_update_rgn( hparent, hrgn );
6587     SetRectRgn( hrgn, 30, 30, 40, 40 );
6588     check_update_rgn( hchild, hrgn );
6589
6590     /* invalidated region is cropped by the parent rects */
6591     SetRect( &rect, 0, 0, 50, 50 );
6592     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6593     SetRectRgn( hrgn, 30, 30, 50, 50 );
6594     check_update_rgn( hchild, hrgn );
6595
6596     DestroyWindow( hparent );
6597     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6598     flush_sequence();
6599
6600     DeleteObject( hrgn );
6601     DeleteObject( hrgn2 );
6602 }
6603
6604 struct wnd_event
6605 {
6606     HWND hwnd;
6607     HANDLE grand_child;
6608     HANDLE start_event;
6609     HANDLE stop_event;
6610 };
6611
6612 static DWORD WINAPI thread_proc(void *param)
6613 {
6614     MSG msg;
6615     struct wnd_event *wnd_event = param;
6616
6617     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6618                                       100, 100, 200, 200, 0, 0, 0, NULL);
6619     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6620
6621     SetEvent(wnd_event->start_event);
6622
6623     while (GetMessage(&msg, 0, 0, 0))
6624     {
6625         TranslateMessage(&msg);
6626         DispatchMessage(&msg);
6627     }
6628
6629     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6630
6631     return 0;
6632 }
6633
6634 static DWORD CALLBACK create_grand_child_thread( void *param )
6635 {
6636     struct wnd_event *wnd_event = param;
6637     HWND hchild;
6638     MSG msg;
6639
6640     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6641                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6642     ok (hchild != 0, "Failed to create child window\n");
6643     flush_events();
6644     flush_sequence();
6645     SetEvent( wnd_event->start_event );
6646
6647     for (;;)
6648     {
6649         MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6650         if (!IsWindow( hchild )) break;  /* will be destroyed when parent thread exits */
6651         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6652     }
6653     return 0;
6654 }
6655
6656 static DWORD CALLBACK create_child_thread( void *param )
6657 {
6658     struct wnd_event *wnd_event = param;
6659     struct wnd_event child_event;
6660     DWORD ret, tid;
6661     MSG msg;
6662
6663     child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6664                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6665     ok (child_event.hwnd != 0, "Failed to create child window\n");
6666     SetFocus( child_event.hwnd );
6667     flush_events();
6668     flush_sequence();
6669     child_event.start_event = wnd_event->start_event;
6670     wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6671     for (;;)
6672     {
6673         DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6674         if (ret != 1) break;
6675         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6676     }
6677     ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6678     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6679     return 0;
6680 }
6681
6682 static void test_interthread_messages(void)
6683 {
6684     HANDLE hThread;
6685     DWORD tid;
6686     WNDPROC proc;
6687     MSG msg;
6688     char buf[256];
6689     int len, expected_len;
6690     struct wnd_event wnd_event;
6691     BOOL ret;
6692
6693     wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6694     if (!wnd_event.start_event)
6695     {
6696         win_skip("skipping interthread message test under win9x\n");
6697         return;
6698     }
6699
6700     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6701     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6702
6703     ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6704
6705     CloseHandle(wnd_event.start_event);
6706
6707     SetLastError(0xdeadbeef);
6708     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6709     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6710        "wrong error code %d\n", GetLastError());
6711
6712     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6713     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6714
6715     expected_len = lstrlenA("window caption text");
6716     memset(buf, 0, sizeof(buf));
6717     SetLastError(0xdeadbeef);
6718     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6719     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6720     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6721
6722     msg.hwnd = wnd_event.hwnd;
6723     msg.message = WM_GETTEXT;
6724     msg.wParam = sizeof(buf);
6725     msg.lParam = (LPARAM)buf;
6726     memset(buf, 0, sizeof(buf));
6727     SetLastError(0xdeadbeef);
6728     len = DispatchMessageA(&msg);
6729     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6730        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6731
6732     /* the following test causes an exception in user.exe under win9x */
6733     msg.hwnd = wnd_event.hwnd;
6734     msg.message = WM_TIMER;
6735     msg.wParam = 0;
6736     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6737     SetLastError(0xdeadbeef);
6738     len = DispatchMessageA(&msg);
6739     ok(!len && GetLastError() == 0xdeadbeef,
6740        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6741
6742     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6743     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6744
6745     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6746     CloseHandle(hThread);
6747
6748     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6749
6750     wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6751                               100, 100, 200, 200, 0, 0, 0, NULL);
6752     ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6753     flush_sequence();
6754     log_all_parent_messages++;
6755     wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6756     wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6757     hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6758     for (;;)
6759     {
6760         ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6761         if (ret != 1) break;
6762         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6763     }
6764     ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6765     /* now wait for the thread without processing messages; this shouldn't deadlock */
6766     SetEvent( wnd_event.stop_event );
6767     ret = WaitForSingleObject( hThread, 5000 );
6768     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6769     CloseHandle( hThread );
6770
6771     ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6772     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6773     CloseHandle( wnd_event.grand_child );
6774
6775     CloseHandle( wnd_event.start_event );
6776     CloseHandle( wnd_event.stop_event );
6777     flush_events();
6778     ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6779     log_all_parent_messages--;
6780     DestroyWindow( wnd_event.hwnd );
6781 }
6782
6783
6784 static const struct message WmVkN[] = {
6785     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6786     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6787     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6788     { WM_CHAR, wparam|lparam, 'n', 1 },
6789     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6790     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6791     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6792     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6793     { 0 }
6794 };
6795 static const struct message WmShiftVkN[] = {
6796     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6797     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6798     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6799     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6800     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6801     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6802     { WM_CHAR, wparam|lparam, 'N', 1 },
6803     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6804     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6805     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6806     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6807     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6808     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6809     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6810     { 0 }
6811 };
6812 static const struct message WmCtrlVkN[] = {
6813     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6814     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6815     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6816     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6817     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6818     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6819     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6820     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6821     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6822     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6823     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6824     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6825     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6826     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6827     { 0 }
6828 };
6829 static const struct message WmCtrlVkN_2[] = {
6830     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6831     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6832     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6833     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6834     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6835     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6836     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6837     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6838     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6839     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6840     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6841     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6842     { 0 }
6843 };
6844 static const struct message WmAltVkN[] = {
6845     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6846     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6847     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6848     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6849     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6850     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6851     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6852     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6853     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6854     { HCBT_SYSCOMMAND, hook },
6855     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6856     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6857     { 0x00AE, sent|defwinproc|optional }, /* XP */
6858     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6859     { WM_INITMENU, sent|defwinproc },
6860     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6861     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6862     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6863     { WM_CAPTURECHANGED, sent|defwinproc },
6864     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6865     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6866     { WM_EXITMENULOOP, sent|defwinproc },
6867     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6868     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6869     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6870     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6871     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6872     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6873     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6874     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6875     { 0 }
6876 };
6877 static const struct message WmAltVkN_2[] = {
6878     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6879     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6880     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6881     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6882     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6883     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6884     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6885     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6886     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6887     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6888     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6889     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6890     { 0 }
6891 };
6892 static const struct message WmCtrlAltVkN[] = {
6893     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6894     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6895     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6896     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6897     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6898     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6899     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6900     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6901     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6902     { WM_CHAR, optional },
6903     { WM_CHAR, sent|optional },
6904     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6905     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6906     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6907     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6908     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6909     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6910     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6911     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6912     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6913     { 0 }
6914 };
6915 static const struct message WmCtrlShiftVkN[] = {
6916     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6917     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6918     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6919     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6920     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6921     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6922     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6923     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6924     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6925     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6926     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6927     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6928     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6929     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6930     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6931     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6932     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6933     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6934     { 0 }
6935 };
6936 static const struct message WmCtrlAltShiftVkN[] = {
6937     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6938     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6939     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6940     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6941     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6942     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6943     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6944     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6945     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6946     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6947     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6948     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6949     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6950     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6951     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6952     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6953     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6954     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6955     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6956     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6957     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6958     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6959     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6960     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6961     { 0 }
6962 };
6963 static const struct message WmAltPressRelease[] = {
6964     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6965     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6966     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6967     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6968     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6969     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6970     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6971     { HCBT_SYSCOMMAND, hook },
6972     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6973     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6974     { WM_INITMENU, sent|defwinproc },
6975     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6976     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6977     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6978
6979     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6980
6981     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6982     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6983     { WM_CAPTURECHANGED, sent|defwinproc },
6984     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6985     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6986     { WM_EXITMENULOOP, sent|defwinproc },
6987     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6988     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6989     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6990     { 0 }
6991 };
6992 static const struct message WmShiftMouseButton[] = {
6993     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6994     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6995     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6996     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6997     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6998     { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6999     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7000     { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7001     { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7002     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7003     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7004     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7005     { 0 }
7006 };
7007 static const struct message WmF1Seq[] = {
7008     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7009     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7010     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7011     { WM_KEYF1, wparam|lparam, 0, 0 },
7012     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7013     { WM_HELP, sent|defwinproc },
7014     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7015     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7016     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7017     { 0 }
7018 };
7019 static const struct message WmVkAppsSeq[] = {
7020     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7021     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7022     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7023     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7024     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7025     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7026     { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7027     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7028     { 0 }
7029 };
7030 static const struct message WmVkF10Seq[] = {
7031     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7032     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7033     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7034     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7035     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7036     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7037     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7038     { HCBT_SYSCOMMAND, hook },
7039     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7040     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7041     { WM_INITMENU, sent|defwinproc },
7042     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7043     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7044     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7045
7046     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7047
7048     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7049     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7050     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7051     { WM_CAPTURECHANGED, sent|defwinproc },
7052     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7053     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7054     { WM_EXITMENULOOP, sent|defwinproc },
7055     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7056     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7057     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7058     { 0 }
7059 };
7060 static const struct message WmShiftF10Seq[] = {
7061     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7062     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7063     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7064     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7065     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7066     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7067     { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7068     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7069     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7070     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7071     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7072     { HCBT_SYSCOMMAND, hook },
7073     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7074     { WM_INITMENU, sent|defwinproc },
7075     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7076     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7077     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7078     { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7079     { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7080     { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7081     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7082     { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7083     { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7084     { 0 }
7085 };
7086
7087 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7088 {
7089     MSG msg;
7090
7091     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7092     {
7093         struct recvd_message log_msg;
7094
7095         /* ignore some unwanted messages */
7096         if (msg.message == WM_MOUSEMOVE ||
7097             msg.message == WM_TIMER ||
7098             ignore_message( msg.message ))
7099             continue;
7100
7101         log_msg.hwnd = msg.hwnd;
7102         log_msg.message = msg.message;
7103         log_msg.flags = wparam|lparam;
7104         log_msg.wParam = msg.wParam;
7105         log_msg.lParam = msg.lParam;
7106         log_msg.descr = "accel";
7107         add_message(&log_msg);
7108
7109         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7110         {
7111             TranslateMessage(&msg);
7112             DispatchMessage(&msg);
7113         }
7114     }
7115 }
7116
7117 static void test_accelerators(void)
7118 {
7119     RECT rc;
7120     POINT pt;
7121     SHORT state;
7122     HACCEL hAccel;
7123     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7124                                 100, 100, 200, 200, 0, 0, 0, NULL);
7125     BOOL ret;
7126
7127     assert(hwnd != 0);
7128     UpdateWindow(hwnd);
7129     flush_events();
7130     flush_sequence();
7131
7132     SetFocus(hwnd);
7133     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7134
7135     state = GetKeyState(VK_SHIFT);
7136     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7137     state = GetKeyState(VK_CAPITAL);
7138     ok(state == 0, "wrong CapsLock state %04x\n", state);
7139
7140     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7141     assert(hAccel != 0);
7142
7143     flush_events();
7144     pump_msg_loop(hwnd, 0);
7145     flush_sequence();
7146
7147     trace("testing VK_N press/release\n");
7148     flush_sequence();
7149     keybd_event('N', 0, 0, 0);
7150     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7151     pump_msg_loop(hwnd, hAccel);
7152     if (!sequence_cnt)  /* we didn't get any message */
7153     {
7154         skip( "queuing key events not supported\n" );
7155         goto done;
7156     }
7157     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7158
7159     trace("testing Shift+VK_N press/release\n");
7160     flush_sequence();
7161     keybd_event(VK_SHIFT, 0, 0, 0);
7162     keybd_event('N', 0, 0, 0);
7163     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7164     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7165     pump_msg_loop(hwnd, hAccel);
7166     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7167
7168     trace("testing Ctrl+VK_N press/release\n");
7169     flush_sequence();
7170     keybd_event(VK_CONTROL, 0, 0, 0);
7171     keybd_event('N', 0, 0, 0);
7172     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7173     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7174     pump_msg_loop(hwnd, hAccel);
7175     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7176
7177     trace("testing Alt+VK_N press/release\n");
7178     flush_sequence();
7179     keybd_event(VK_MENU, 0, 0, 0);
7180     keybd_event('N', 0, 0, 0);
7181     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7182     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7183     pump_msg_loop(hwnd, hAccel);
7184     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7185
7186     trace("testing Ctrl+Alt+VK_N press/release 1\n");
7187     flush_sequence();
7188     keybd_event(VK_CONTROL, 0, 0, 0);
7189     keybd_event(VK_MENU, 0, 0, 0);
7190     keybd_event('N', 0, 0, 0);
7191     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7192     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7193     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7194     pump_msg_loop(hwnd, hAccel);
7195     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7196
7197     ret = DestroyAcceleratorTable(hAccel);
7198     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7199
7200     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7201     assert(hAccel != 0);
7202
7203     trace("testing VK_N press/release\n");
7204     flush_sequence();
7205     keybd_event('N', 0, 0, 0);
7206     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7207     pump_msg_loop(hwnd, hAccel);
7208     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7209
7210     trace("testing Shift+VK_N press/release\n");
7211     flush_sequence();
7212     keybd_event(VK_SHIFT, 0, 0, 0);
7213     keybd_event('N', 0, 0, 0);
7214     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7215     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7216     pump_msg_loop(hwnd, hAccel);
7217     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7218
7219     trace("testing Ctrl+VK_N press/release 2\n");
7220     flush_sequence();
7221     keybd_event(VK_CONTROL, 0, 0, 0);
7222     keybd_event('N', 0, 0, 0);
7223     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7224     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7225     pump_msg_loop(hwnd, hAccel);
7226     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7227
7228     trace("testing Alt+VK_N press/release 2\n");
7229     flush_sequence();
7230     keybd_event(VK_MENU, 0, 0, 0);
7231     keybd_event('N', 0, 0, 0);
7232     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7233     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7234     pump_msg_loop(hwnd, hAccel);
7235     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7236
7237     trace("testing Ctrl+Alt+VK_N press/release 2\n");
7238     flush_sequence();
7239     keybd_event(VK_CONTROL, 0, 0, 0);
7240     keybd_event(VK_MENU, 0, 0, 0);
7241     keybd_event('N', 0, 0, 0);
7242     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7243     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7244     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7245     pump_msg_loop(hwnd, hAccel);
7246     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7247
7248     trace("testing Ctrl+Shift+VK_N press/release\n");
7249     flush_sequence();
7250     keybd_event(VK_CONTROL, 0, 0, 0);
7251     keybd_event(VK_SHIFT, 0, 0, 0);
7252     keybd_event('N', 0, 0, 0);
7253     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7254     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7255     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7256     pump_msg_loop(hwnd, hAccel);
7257     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7258
7259     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7260     flush_sequence();
7261     keybd_event(VK_CONTROL, 0, 0, 0);
7262     keybd_event(VK_MENU, 0, 0, 0);
7263     keybd_event(VK_SHIFT, 0, 0, 0);
7264     keybd_event('N', 0, 0, 0);
7265     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7266     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7267     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7268     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7269     pump_msg_loop(hwnd, hAccel);
7270     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7271
7272     ret = DestroyAcceleratorTable(hAccel);
7273     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7274     hAccel = 0;
7275
7276     trace("testing Alt press/release\n");
7277     flush_sequence();
7278     keybd_event(VK_MENU, 0, 0, 0);
7279     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7280     keybd_event(VK_MENU, 0, 0, 0);
7281     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7282     pump_msg_loop(hwnd, 0);
7283     /* this test doesn't pass in Wine for managed windows */
7284     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7285
7286     trace("testing VK_F1 press/release\n");
7287     keybd_event(VK_F1, 0, 0, 0);
7288     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7289     pump_msg_loop(hwnd, 0);
7290     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7291
7292     trace("testing VK_APPS press/release\n");
7293     keybd_event(VK_APPS, 0, 0, 0);
7294     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7295     pump_msg_loop(hwnd, 0);
7296     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7297
7298     trace("testing VK_F10 press/release\n");
7299     keybd_event(VK_F10, 0, 0, 0);
7300     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7301     keybd_event(VK_F10, 0, 0, 0);
7302     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7303     pump_msg_loop(hwnd, 0);
7304     ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7305
7306     trace("testing SHIFT+F10 press/release\n");
7307     keybd_event(VK_SHIFT, 0, 0, 0);
7308     keybd_event(VK_F10, 0, 0, 0);
7309     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7310     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7311     keybd_event(VK_ESCAPE, 0, 0, 0);
7312     keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7313     pump_msg_loop(hwnd, 0);
7314     ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7315
7316     trace("testing Shift+MouseButton press/release\n");
7317     /* first, move mouse pointer inside of the window client area */
7318     GetClientRect(hwnd, &rc);
7319     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7320     rc.left += (rc.right - rc.left)/2;
7321     rc.top += (rc.bottom - rc.top)/2;
7322     SetCursorPos(rc.left, rc.top);
7323     SetActiveWindow(hwnd);
7324
7325     flush_events();
7326     flush_sequence();
7327     GetCursorPos(&pt);
7328     if (pt.x == rc.left && pt.y == rc.top)
7329     {
7330         int i;
7331         keybd_event(VK_SHIFT, 0, 0, 0);
7332         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7333         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7334         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7335         pump_msg_loop(hwnd, 0);
7336         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7337         if (i < sequence_cnt)
7338             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7339         else
7340             skip( "Shift+MouseButton event didn't get to the window\n" );
7341     }
7342
7343 done:
7344     if (hAccel) DestroyAcceleratorTable(hAccel);
7345     DestroyWindow(hwnd);
7346 }
7347
7348 /************* window procedures ********************/
7349
7350 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
7351                              WPARAM wParam, LPARAM lParam)
7352 {
7353     static LONG defwndproc_counter = 0;
7354     static LONG beginpaint_counter = 0;
7355     LRESULT ret;
7356     struct recvd_message msg;
7357
7358     if (ignore_message( message )) return 0;
7359
7360     switch (message)
7361     {
7362         case WM_ENABLE:
7363         {
7364             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7365             ok((BOOL)wParam == !(style & WS_DISABLED),
7366                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7367             break;
7368         }
7369
7370         case WM_CAPTURECHANGED:
7371             if (test_DestroyWindow_flag)
7372             {
7373                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7374                 if (style & WS_CHILD)
7375                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7376                 else if (style & WS_POPUP)
7377                     lParam = WND_POPUP_ID;
7378                 else
7379                     lParam = WND_PARENT_ID;
7380             }
7381             break;
7382
7383         case WM_NCDESTROY:
7384         {
7385             HWND capture;
7386
7387             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7388             capture = GetCapture();
7389             if (capture)
7390             {
7391                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7392                 trace("current capture %p, releasing...\n", capture);
7393                 ReleaseCapture();
7394             }
7395         }
7396         /* fall through */
7397         case WM_DESTROY:
7398             if (pGetAncestor)
7399                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7400             if (test_DestroyWindow_flag)
7401             {
7402                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7403                 if (style & WS_CHILD)
7404                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7405                 else if (style & WS_POPUP)
7406                     lParam = WND_POPUP_ID;
7407                 else
7408                     lParam = WND_PARENT_ID;
7409             }
7410             break;
7411
7412         /* test_accelerators() depends on this */
7413         case WM_NCHITTEST:
7414             return HTCLIENT;
7415
7416         /* ignore */
7417         case WM_MOUSEMOVE:
7418         case WM_MOUSEACTIVATE:
7419         case WM_NCMOUSEMOVE:
7420         case WM_SETCURSOR:
7421         case WM_IME_SELECT:
7422             return 0;
7423     }
7424
7425     msg.hwnd = hwnd;
7426     msg.message = message;
7427     msg.flags = sent|wparam|lparam;
7428     if (defwndproc_counter) msg.flags |= defwinproc;
7429     if (beginpaint_counter) msg.flags |= beginpaint;
7430     msg.wParam = wParam;
7431     msg.lParam = lParam;
7432     msg.descr = "MsgCheckProc";
7433     add_message(&msg);
7434
7435     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7436     {
7437         HWND parent = GetParent(hwnd);
7438         RECT rc;
7439         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7440
7441         GetClientRect(parent, &rc);
7442         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7443         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7444               minmax->ptReserved.x, minmax->ptReserved.y,
7445               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7446               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7447               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7448               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7449
7450         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7451            minmax->ptMaxSize.x, rc.right);
7452         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7453            minmax->ptMaxSize.y, rc.bottom);
7454     }
7455
7456     if (message == WM_PAINT)
7457     {
7458         PAINTSTRUCT ps;
7459         beginpaint_counter++;
7460         BeginPaint( hwnd, &ps );
7461         beginpaint_counter--;
7462         EndPaint( hwnd, &ps );
7463         return 0;
7464     }
7465
7466     defwndproc_counter++;
7467     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
7468                   : DefWindowProcA(hwnd, message, wParam, lParam);
7469     defwndproc_counter--;
7470
7471     return ret;
7472 }
7473
7474 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7475 {
7476     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7477 }
7478
7479 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7480 {
7481     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7482 }
7483
7484 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7485 {
7486     static LONG defwndproc_counter = 0;
7487     LRESULT ret;
7488     struct recvd_message msg;
7489
7490     if (ignore_message( message )) return 0;
7491
7492     switch (message)
7493     {
7494     case WM_QUERYENDSESSION:
7495     case WM_ENDSESSION:
7496         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7497         break;
7498     }
7499
7500     msg.hwnd = hwnd;
7501     msg.message = message;
7502     msg.flags = sent|wparam|lparam;
7503     if (defwndproc_counter) msg.flags |= defwinproc;
7504     msg.wParam = wParam;
7505     msg.lParam = lParam;
7506     msg.descr = "popup";
7507     add_message(&msg);
7508
7509     if (message == WM_CREATE)
7510     {
7511         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7512         SetWindowLongA(hwnd, GWL_STYLE, style);
7513     }
7514
7515     defwndproc_counter++;
7516     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7517     defwndproc_counter--;
7518
7519     return ret;
7520 }
7521
7522 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7523 {
7524     static LONG defwndproc_counter = 0;
7525     static LONG beginpaint_counter = 0;
7526     LRESULT ret;
7527     struct recvd_message msg;
7528
7529     if (ignore_message( message )) return 0;
7530
7531     if (log_all_parent_messages ||
7532         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7533         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7534         message == WM_ENABLE || message == WM_ENTERIDLE ||
7535         message == WM_DRAWITEM || message == WM_COMMAND ||
7536         message == WM_IME_SETCONTEXT)
7537     {
7538         switch (message)
7539         {
7540             /* ignore */
7541             case WM_NCHITTEST:
7542                 return HTCLIENT;
7543             case WM_SETCURSOR:
7544             case WM_MOUSEMOVE:
7545             case WM_NCMOUSEMOVE:
7546                 return 0;
7547
7548             case WM_ERASEBKGND:
7549             {
7550                 RECT rc;
7551                 INT ret = GetClipBox((HDC)wParam, &rc);
7552
7553                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7554                        ret, rc.left, rc.top, rc.right, rc.bottom);
7555                 break;
7556             }
7557         }
7558
7559         msg.hwnd = hwnd;
7560         msg.message = message;
7561         msg.flags = sent|parent|wparam|lparam;
7562         if (defwndproc_counter) msg.flags |= defwinproc;
7563         if (beginpaint_counter) msg.flags |= beginpaint;
7564         msg.wParam = wParam;
7565         msg.lParam = lParam;
7566         msg.descr = "parent";
7567         add_message(&msg);
7568     }
7569
7570     if (message == WM_PAINT)
7571     {
7572         PAINTSTRUCT ps;
7573         beginpaint_counter++;
7574         BeginPaint( hwnd, &ps );
7575         beginpaint_counter--;
7576         EndPaint( hwnd, &ps );
7577         return 0;
7578     }
7579
7580     defwndproc_counter++;
7581     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7582     defwndproc_counter--;
7583
7584     return ret;
7585 }
7586
7587 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7588 {
7589     static LONG defwndproc_counter = 0;
7590     LRESULT ret;
7591     struct recvd_message msg;
7592
7593     if (ignore_message( message )) return 0;
7594
7595     if (test_def_id)
7596     {
7597         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7598         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7599         if (after_end_dialog)
7600             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7601         else
7602             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7603     }
7604
7605     msg.hwnd = hwnd;
7606     msg.message = message;
7607     msg.flags = sent|wparam|lparam;
7608     if (defwndproc_counter) msg.flags |= defwinproc;
7609     msg.wParam = wParam;
7610     msg.lParam = lParam;
7611     msg.descr = "dialog";
7612     add_message(&msg);
7613
7614     defwndproc_counter++;
7615     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7616     defwndproc_counter--;
7617
7618     return ret;
7619 }
7620
7621 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7622 {
7623     static LONG defwndproc_counter = 0;
7624     LRESULT ret;
7625     struct recvd_message msg;
7626
7627     /* log only specific messages we are interested in */
7628     switch (message)
7629     {
7630 #if 0 /* probably log these as well */
7631     case WM_ACTIVATE:
7632     case WM_SETFOCUS:
7633     case WM_KILLFOCUS:
7634 #endif
7635     case WM_SHOWWINDOW:
7636     case WM_SIZE:
7637     case WM_MOVE:
7638     case WM_GETMINMAXINFO:
7639     case WM_WINDOWPOSCHANGING:
7640     case WM_WINDOWPOSCHANGED:
7641         break;
7642
7643     default: /* ignore */
7644         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7645         return DefWindowProcA(hwnd, message, wParam, lParam);
7646     }
7647
7648     msg.hwnd = hwnd;
7649     msg.message = message;
7650     msg.flags = sent|wparam|lparam;
7651     if (defwndproc_counter) msg.flags |= defwinproc;
7652     msg.wParam = wParam;
7653     msg.lParam = lParam;
7654     msg.descr = "show";
7655     add_message(&msg);
7656
7657     defwndproc_counter++;
7658     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7659     defwndproc_counter--;
7660
7661     return ret;
7662 }
7663
7664 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7665 {
7666     switch (msg)
7667     {
7668         case WM_CREATE: return 0;
7669         case WM_PAINT:
7670         {
7671             MSG msg2;
7672             static int i = 0;
7673
7674             if (i < 256)
7675             {
7676                 i++;
7677                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7678                 {
7679                     TranslateMessage(&msg2);
7680                     DispatchMessage(&msg2);
7681                 }
7682                 i--;
7683             }
7684             else ok(broken(1), "infinite loop\n");
7685             if ( i == 0)
7686                 paint_loop_done = 1;
7687             return DefWindowProcA(hWnd,msg,wParam,lParam);
7688         }
7689     }
7690     return DefWindowProcA(hWnd,msg,wParam,lParam);
7691 }
7692
7693 static BOOL RegisterWindowClasses(void)
7694 {
7695     WNDCLASSA cls;
7696     WNDCLASSW clsW;
7697
7698     cls.style = 0;
7699     cls.lpfnWndProc = MsgCheckProcA;
7700     cls.cbClsExtra = 0;
7701     cls.cbWndExtra = 0;
7702     cls.hInstance = GetModuleHandleA(0);
7703     cls.hIcon = 0;
7704     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7705     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7706     cls.lpszMenuName = NULL;
7707     cls.lpszClassName = "TestWindowClass";
7708     if(!RegisterClassA(&cls)) return FALSE;
7709
7710     cls.lpfnWndProc = ShowWindowProcA;
7711     cls.lpszClassName = "ShowWindowClass";
7712     if(!RegisterClassA(&cls)) return FALSE;
7713
7714     cls.lpfnWndProc = PopupMsgCheckProcA;
7715     cls.lpszClassName = "TestPopupClass";
7716     if(!RegisterClassA(&cls)) return FALSE;
7717
7718     cls.lpfnWndProc = ParentMsgCheckProcA;
7719     cls.lpszClassName = "TestParentClass";
7720     if(!RegisterClassA(&cls)) return FALSE;
7721
7722     cls.lpfnWndProc = DefWindowProcA;
7723     cls.lpszClassName = "SimpleWindowClass";
7724     if(!RegisterClassA(&cls)) return FALSE;
7725
7726     cls.lpfnWndProc = PaintLoopProcA;
7727     cls.lpszClassName = "PaintLoopWindowClass";
7728     if(!RegisterClassA(&cls)) return FALSE;
7729
7730     cls.style = CS_NOCLOSE;
7731     cls.lpszClassName = "NoCloseWindowClass";
7732     if(!RegisterClassA(&cls)) return FALSE;
7733
7734     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7735     cls.style = 0;
7736     cls.hInstance = GetModuleHandleA(0);
7737     cls.hbrBackground = 0;
7738     cls.lpfnWndProc = TestDlgProcA;
7739     cls.lpszClassName = "TestDialogClass";
7740     if(!RegisterClassA(&cls)) return FALSE;
7741
7742     clsW.style = 0;
7743     clsW.lpfnWndProc = MsgCheckProcW;
7744     clsW.cbClsExtra = 0;
7745     clsW.cbWndExtra = 0;
7746     clsW.hInstance = GetModuleHandleW(0);
7747     clsW.hIcon = 0;
7748     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7749     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7750     clsW.lpszMenuName = NULL;
7751     clsW.lpszClassName = testWindowClassW;
7752     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7753
7754     return TRUE;
7755 }
7756
7757 static BOOL is_our_logged_class(HWND hwnd)
7758 {
7759     char buf[256];
7760
7761     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7762     {
7763         if (!lstrcmpiA(buf, "TestWindowClass") ||
7764             !lstrcmpiA(buf, "ShowWindowClass") ||
7765             !lstrcmpiA(buf, "TestParentClass") ||
7766             !lstrcmpiA(buf, "TestPopupClass") ||
7767             !lstrcmpiA(buf, "SimpleWindowClass") ||
7768             !lstrcmpiA(buf, "TestDialogClass") ||
7769             !lstrcmpiA(buf, "MDI_frame_class") ||
7770             !lstrcmpiA(buf, "MDI_client_class") ||
7771             !lstrcmpiA(buf, "MDI_child_class") ||
7772             !lstrcmpiA(buf, "my_button_class") ||
7773             !lstrcmpiA(buf, "my_edit_class") ||
7774             !lstrcmpiA(buf, "static") ||
7775             !lstrcmpiA(buf, "ListBox") ||
7776             !lstrcmpiA(buf, "ComboBox") ||
7777             !lstrcmpiA(buf, "MyDialogClass") ||
7778             !lstrcmpiA(buf, "#32770") ||
7779             !lstrcmpiA(buf, "#32768"))
7780         return TRUE;
7781     }
7782     return FALSE;
7783 }
7784
7785 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7786
7787     HWND hwnd;
7788
7789     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7790
7791     if (nCode == HCBT_CLICKSKIPPED)
7792     {
7793         /* ignore this event, XP sends it a lot when switching focus between windows */
7794         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7795     }
7796
7797     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7798     {
7799         struct recvd_message msg;
7800
7801         msg.hwnd = 0;
7802         msg.message = nCode;
7803         msg.flags = hook|wparam|lparam;
7804         msg.wParam = wParam;
7805         msg.lParam = lParam;
7806         msg.descr = "CBT";
7807         add_message(&msg);
7808
7809         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7810     }
7811
7812     if (nCode == HCBT_DESTROYWND)
7813     {
7814         if (test_DestroyWindow_flag)
7815         {
7816             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7817             if (style & WS_CHILD)
7818                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7819             else if (style & WS_POPUP)
7820                 lParam = WND_POPUP_ID;
7821             else
7822                 lParam = WND_PARENT_ID;
7823         }
7824     }
7825
7826     /* Log also SetFocus(0) calls */
7827     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7828
7829     if (is_our_logged_class(hwnd))
7830     {
7831         struct recvd_message msg;
7832
7833         msg.hwnd = hwnd;
7834         msg.message = nCode;
7835         msg.flags = hook|wparam|lparam;
7836         msg.wParam = wParam;
7837         msg.lParam = lParam;
7838         msg.descr = "CBT";
7839         add_message(&msg);
7840     }
7841     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7842 }
7843
7844 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7845                                     DWORD event,
7846                                     HWND hwnd,
7847                                     LONG object_id,
7848                                     LONG child_id,
7849                                     DWORD thread_id,
7850                                     DWORD event_time)
7851 {
7852     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7853
7854     /* ignore mouse cursor events */
7855     if (object_id == OBJID_CURSOR) return;
7856
7857     if (!hwnd || is_our_logged_class(hwnd))
7858     {
7859         struct recvd_message msg;
7860
7861         msg.hwnd = hwnd;
7862         msg.message = event;
7863         msg.flags = winevent_hook|wparam|lparam;
7864         msg.wParam = object_id;
7865         msg.lParam = child_id;
7866         msg.descr = "WEH";
7867         add_message(&msg);
7868     }
7869 }
7870
7871 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7872 static const WCHAR wszAnsi[] = {'U',0};
7873
7874 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7875 {
7876     switch (uMsg)
7877     {
7878     case CB_FINDSTRINGEXACT:
7879         trace("String: %p\n", (LPCWSTR)lParam);
7880         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7881             return 1;
7882         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7883             return 0;
7884         return -1;
7885     }
7886     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7887 }
7888
7889 static const struct message WmGetTextLengthAfromW[] = {
7890     { WM_GETTEXTLENGTH, sent },
7891     { WM_GETTEXT, sent|optional },
7892     { 0 }
7893 };
7894
7895 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7896
7897 /* dummy window proc for WM_GETTEXTLENGTH test */
7898 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7899 {
7900     switch(msg)
7901     {
7902     case WM_GETTEXTLENGTH:
7903         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7904     case WM_GETTEXT:
7905         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7906         return lstrlenW( (LPWSTR)lp );
7907     default:
7908         return DefWindowProcW( hwnd, msg, wp, lp );
7909     }
7910 }
7911
7912 static void test_message_conversion(void)
7913 {
7914     static const WCHAR wszMsgConversionClass[] =
7915         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7916     WNDCLASSW cls;
7917     LRESULT lRes;
7918     HWND hwnd;
7919     WNDPROC wndproc, newproc;
7920     BOOL ret;
7921
7922     cls.style = 0;
7923     cls.lpfnWndProc = MsgConversionProcW;
7924     cls.cbClsExtra = 0;
7925     cls.cbWndExtra = 0;
7926     cls.hInstance = GetModuleHandleW(NULL);
7927     cls.hIcon = NULL;
7928     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7929     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7930     cls.lpszMenuName = NULL;
7931     cls.lpszClassName = wszMsgConversionClass;
7932     /* this call will fail on Win9x, but that doesn't matter as this test is
7933      * meaningless on those platforms */
7934     if(!RegisterClassW(&cls)) return;
7935
7936     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7937                            100, 100, 200, 200, 0, 0, 0, NULL);
7938     ok(hwnd != NULL, "Window creation failed\n");
7939
7940     /* {W, A} -> A */
7941
7942     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7943     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7944     ok(lRes == 0, "String should have been converted\n");
7945     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7946     ok(lRes == 1, "String shouldn't have been converted\n");
7947
7948     /* {W, A} -> W */
7949
7950     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7951     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7952     ok(lRes == 1, "String shouldn't have been converted\n");
7953     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7954     ok(lRes == 1, "String shouldn't have been converted\n");
7955
7956     /* Synchronous messages */
7957
7958     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7959     ok(lRes == 0, "String should have been converted\n");
7960     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7961     ok(lRes == 1, "String shouldn't have been converted\n");
7962
7963     /* Asynchronous messages */
7964
7965     SetLastError(0);
7966     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7967     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7968         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7969     SetLastError(0);
7970     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7971     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7972         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7973     SetLastError(0);
7974     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7975     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7976         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7977     SetLastError(0);
7978     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7979     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7980         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7981     SetLastError(0);
7982     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7983     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7984         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7985     SetLastError(0);
7986     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7987     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7988         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7989     SetLastError(0);
7990     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7991     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7992         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7993     SetLastError(0);
7994     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7995     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7996         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7997
7998     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7999
8000     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8001                           WS_OVERLAPPEDWINDOW,
8002                           100, 100, 200, 200, 0, 0, 0, NULL);
8003     assert(hwnd);
8004     flush_sequence();
8005     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8006     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8007     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8008         "got bad length %ld\n", lRes );
8009
8010     flush_sequence();
8011     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8012                             hwnd, WM_GETTEXTLENGTH, 0, 0);
8013     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8014     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8015         "got bad length %ld\n", lRes );
8016
8017     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8018     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8019     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8020     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8021                                      NULL, 0, NULL, NULL ) ||
8022         broken(lRes == lstrlenW(dummy_window_text) + 37),
8023         "got bad length %ld\n", lRes );
8024
8025     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
8026     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8027     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8028                                      NULL, 0, NULL, NULL ) ||
8029         broken(lRes == lstrlenW(dummy_window_text) + 37),
8030         "got bad length %ld\n", lRes );
8031
8032     ret = DestroyWindow(hwnd);
8033     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8034 }
8035
8036 struct timer_info
8037 {
8038     HWND hWnd;
8039     HANDLE handles[2];
8040     DWORD id;
8041 };
8042
8043 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8044 {
8045 }
8046
8047 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8048 {
8049     /* Crash on purpose */
8050     *(volatile int *)0 = 2;
8051 }
8052
8053 #define TIMER_ID  0x19
8054
8055 static DWORD WINAPI timer_thread_proc(LPVOID x)
8056 {
8057     struct timer_info *info = x;
8058     DWORD r;
8059
8060     r = KillTimer(info->hWnd, 0x19);
8061     ok(r,"KillTimer failed in thread\n");
8062     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8063     ok(r,"SetTimer failed in thread\n");
8064     ok(r==TIMER_ID,"SetTimer id different\n");
8065     r = SetEvent(info->handles[0]);
8066     ok(r,"SetEvent failed in thread\n");
8067     return 0;
8068 }
8069
8070 static void test_timers(void)
8071 {
8072     struct timer_info info;
8073     DWORD id;
8074     MSG msg;
8075
8076     info.hWnd = CreateWindow ("TestWindowClass", NULL,
8077        WS_OVERLAPPEDWINDOW ,
8078        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8079        NULL, NULL, 0);
8080
8081     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8082     ok(info.id, "SetTimer failed\n");
8083     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8084     info.handles[0] = CreateEvent(NULL,0,0,NULL);
8085     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8086
8087     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8088
8089     WaitForSingleObject(info.handles[1], INFINITE);
8090
8091     CloseHandle(info.handles[0]);
8092     CloseHandle(info.handles[1]);
8093
8094     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8095
8096     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8097
8098     /* Test timer callback with crash */
8099     SetLastError(0xdeadbeef);
8100     info.hWnd = CreateWindowW(testWindowClassW, NULL,
8101                               WS_OVERLAPPEDWINDOW ,
8102                               CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8103                               NULL, NULL, 0);
8104     if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
8105         (!pGetMenuInfo)) /* Win95/NT4 */
8106     {
8107         win_skip("Test would crash on Win9x/WinMe/NT4\n");
8108         DestroyWindow(info.hWnd);
8109         return;
8110     }
8111     info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
8112     ok(info.id, "SetTimer failed\n");
8113     Sleep(150);
8114     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8115
8116     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8117 }
8118
8119 static int count = 0;
8120 static VOID CALLBACK callback_count(
8121     HWND hwnd,
8122     UINT uMsg,
8123     UINT_PTR idEvent,
8124     DWORD dwTime
8125 )
8126 {
8127     count++;
8128 }
8129
8130 static void test_timers_no_wnd(void)
8131 {
8132     UINT_PTR id, id2;
8133     MSG msg;
8134
8135     count = 0;
8136     id = SetTimer(NULL, 0, 100, callback_count);
8137     ok(id != 0, "did not get id from SetTimer.\n");
8138     id2 = SetTimer(NULL, id, 200, callback_count);
8139     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8140     Sleep(150);
8141     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8142     ok(count == 0, "did not get zero count as expected (%i).\n", count);
8143     Sleep(150);
8144     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8145     ok(count == 1, "did not get one count as expected (%i).\n", count);
8146     KillTimer(NULL, id);
8147     Sleep(250);
8148     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8149     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8150 }
8151
8152 /* Various win events with arbitrary parameters */
8153 static const struct message WmWinEventsSeq[] = {
8154     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8155     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8156     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8157     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8158     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8159     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8160     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8161     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8162     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8163     /* our win event hook ignores OBJID_CURSOR events */
8164     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8165     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8166     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8167     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8168     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8169     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8170     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8171     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8172     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8173     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8174     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8175     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8176     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8177     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8178     { 0 }
8179 };
8180 static const struct message WmWinEventCaretSeq[] = {
8181     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8182     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8183     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8184     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8185     { 0 }
8186 };
8187 static const struct message WmWinEventCaretSeq_2[] = {
8188     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8189     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8190     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8191     { 0 }
8192 };
8193 static const struct message WmWinEventAlertSeq[] = {
8194     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8195     { 0 }
8196 };
8197 static const struct message WmWinEventAlertSeq_2[] = {
8198     /* create window in the thread proc */
8199     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8200     /* our test event */
8201     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8202     { 0 }
8203 };
8204 static const struct message WmGlobalHookSeq_1[] = {
8205     /* create window in the thread proc */
8206     { HCBT_CREATEWND, hook|lparam, 0, 2 },
8207     /* our test events */
8208     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8209     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8210     { 0 }
8211 };
8212 static const struct message WmGlobalHookSeq_2[] = {
8213     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8214     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8215     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8216     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8217     { 0 }
8218 };
8219
8220 static const struct message WmMouseLLHookSeq[] = {
8221     { WM_MOUSEMOVE, hook },
8222     { WM_LBUTTONUP, hook },
8223     { WM_MOUSEMOVE, hook },
8224     { 0 }
8225 };
8226
8227 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8228                                          DWORD event,
8229                                          HWND hwnd,
8230                                          LONG object_id,
8231                                          LONG child_id,
8232                                          DWORD thread_id,
8233                                          DWORD event_time)
8234 {
8235     char buf[256];
8236
8237     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8238     {
8239         if (!lstrcmpiA(buf, "TestWindowClass") ||
8240             !lstrcmpiA(buf, "static"))
8241         {
8242             struct recvd_message msg;
8243
8244             msg.hwnd = hwnd;
8245             msg.message = event;
8246             msg.flags = winevent_hook|wparam|lparam;
8247             msg.wParam = object_id;
8248             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8249             msg.descr = "WEH_2";
8250             add_message(&msg);
8251         }
8252     }
8253 }
8254
8255 static HHOOK hCBT_global_hook;
8256 static DWORD cbt_global_hook_thread_id;
8257
8258 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
8259
8260     HWND hwnd;
8261     char buf[256];
8262
8263     if (nCode == HCBT_SYSCOMMAND)
8264     {
8265         struct recvd_message msg;
8266
8267         msg.hwnd = 0;
8268         msg.message = nCode;
8269         msg.flags = hook|wparam|lparam;
8270         msg.wParam = wParam;
8271         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8272         msg.descr = "CBT_2";
8273         add_message(&msg);
8274
8275         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8276     }
8277     /* WH_MOUSE_LL hook */
8278     if (nCode == HC_ACTION)
8279     {
8280         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8281
8282         /* we can't test for real mouse events */
8283         if (mhll->flags & LLMHF_INJECTED)
8284         {
8285             struct recvd_message msg;
8286
8287             memset (&msg, 0, sizeof (msg));
8288             msg.message = wParam;
8289             msg.flags = hook;
8290             msg.descr = "CBT_2";
8291             add_message(&msg);
8292         }
8293         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8294     }
8295
8296     /* Log also SetFocus(0) calls */
8297     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8298
8299     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8300     {
8301         if (!lstrcmpiA(buf, "TestWindowClass") ||
8302             !lstrcmpiA(buf, "static"))
8303         {
8304             struct recvd_message msg;
8305
8306             msg.hwnd = hwnd;
8307             msg.message = nCode;
8308             msg.flags = hook|wparam|lparam;
8309             msg.wParam = wParam;
8310             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8311             msg.descr = "CBT_2";
8312             add_message(&msg);
8313         }
8314     }
8315     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8316 }
8317
8318 static DWORD WINAPI win_event_global_thread_proc(void *param)
8319 {
8320     HWND hwnd;
8321     MSG msg;
8322     HANDLE hevent = *(HANDLE *)param;
8323
8324     assert(pNotifyWinEvent);
8325
8326     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8327     assert(hwnd);
8328     trace("created thread window %p\n", hwnd);
8329
8330     *(HWND *)param = hwnd;
8331
8332     flush_sequence();
8333     /* this event should be received only by our new hook proc,
8334      * an old one does not expect an event from another thread.
8335      */
8336     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8337     SetEvent(hevent);
8338
8339     while (GetMessage(&msg, 0, 0, 0))
8340     {
8341         TranslateMessage(&msg);
8342         DispatchMessage(&msg);
8343     }
8344     return 0;
8345 }
8346
8347 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8348 {
8349     HWND hwnd;
8350     MSG msg;
8351     HANDLE hevent = *(HANDLE *)param;
8352
8353     flush_sequence();
8354     /* these events should be received only by our new hook proc,
8355      * an old one does not expect an event from another thread.
8356      */
8357
8358     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8359     assert(hwnd);
8360     trace("created thread window %p\n", hwnd);
8361
8362     *(HWND *)param = hwnd;
8363
8364     /* Windows doesn't like when a thread plays games with the focus,
8365        that leads to all kinds of misbehaviours and failures to activate
8366        a window. So, better keep next lines commented out.
8367     SetFocus(0);
8368     SetFocus(hwnd);*/
8369
8370     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8371     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8372
8373     SetEvent(hevent);
8374
8375     while (GetMessage(&msg, 0, 0, 0))
8376     {
8377         TranslateMessage(&msg);
8378         DispatchMessage(&msg);
8379     }
8380     return 0;
8381 }
8382
8383 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8384 {
8385     HWND hwnd;
8386     MSG msg;
8387     HANDLE hevent = *(HANDLE *)param;
8388
8389     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8390     assert(hwnd);
8391     trace("created thread window %p\n", hwnd);
8392
8393     *(HWND *)param = hwnd;
8394
8395     flush_sequence();
8396
8397     /* Windows doesn't like when a thread plays games with the focus,
8398      * that leads to all kinds of misbehaviours and failures to activate
8399      * a window. So, better don't generate a mouse click message below.
8400      */
8401     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8402     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8403     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8404
8405     SetEvent(hevent);
8406     while (GetMessage(&msg, 0, 0, 0))
8407     {
8408         TranslateMessage(&msg);
8409         DispatchMessage(&msg);
8410     }
8411     return 0;
8412 }
8413
8414 static void test_winevents(void)
8415 {
8416     BOOL ret;
8417     MSG msg;
8418     HWND hwnd, hwnd2;
8419     UINT i;
8420     HANDLE hthread, hevent;
8421     DWORD tid;
8422     HWINEVENTHOOK hhook;
8423     const struct message *events = WmWinEventsSeq;
8424
8425     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8426                            WS_OVERLAPPEDWINDOW,
8427                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8428                            NULL, NULL, 0);
8429     assert(hwnd);
8430
8431     /****** start of global hook test *************/
8432     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8433     if (!hCBT_global_hook)
8434     {
8435         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8436         skip( "cannot set global hook\n" );
8437         return;
8438     }
8439
8440     hevent = CreateEventA(NULL, 0, 0, NULL);
8441     assert(hevent);
8442     hwnd2 = hevent;
8443
8444     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8445     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8446
8447     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8448
8449     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8450
8451     flush_sequence();
8452     /* this one should be received only by old hook proc */
8453     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8454     /* this one should be received only by old hook proc */
8455     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8456
8457     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8458
8459     ret = UnhookWindowsHookEx(hCBT_global_hook);
8460     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8461
8462     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8463     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8464     CloseHandle(hthread);
8465     CloseHandle(hevent);
8466     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8467     /****** end of global hook test *************/
8468
8469     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8470     {
8471         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8472         return;
8473     }
8474
8475     flush_sequence();
8476
8477     if (0)
8478     {
8479     /* this test doesn't pass under Win9x */
8480     /* win2k ignores events with hwnd == 0 */
8481     SetLastError(0xdeadbeef);
8482     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8483     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8484        GetLastError() == 0xdeadbeef, /* Win9x */
8485        "unexpected error %d\n", GetLastError());
8486     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8487     }
8488
8489     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8490         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8491
8492     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8493
8494     /****** start of event filtering test *************/
8495     hhook = pSetWinEventHook(
8496         EVENT_OBJECT_SHOW, /* 0x8002 */
8497         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8498         GetModuleHandleA(0), win_event_global_hook_proc,
8499         GetCurrentProcessId(), 0,
8500         WINEVENT_INCONTEXT);
8501     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8502
8503     hevent = CreateEventA(NULL, 0, 0, NULL);
8504     assert(hevent);
8505     hwnd2 = hevent;
8506
8507     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8508     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8509
8510     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8511
8512     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8513
8514     flush_sequence();
8515     /* this one should be received only by old hook proc */
8516     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8517     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8518     /* this one should be received only by old hook proc */
8519     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8520
8521     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8522
8523     ret = pUnhookWinEvent(hhook);
8524     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8525
8526     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8527     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8528     CloseHandle(hthread);
8529     CloseHandle(hevent);
8530     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8531     /****** end of event filtering test *************/
8532
8533     /****** start of out of context event test *************/
8534     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8535         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8536         WINEVENT_OUTOFCONTEXT);
8537     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8538
8539     hevent = CreateEventA(NULL, 0, 0, NULL);
8540     assert(hevent);
8541     hwnd2 = hevent;
8542
8543     flush_sequence();
8544
8545     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8546     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8547
8548     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8549
8550     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8551     /* process pending winevent messages */
8552     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8553     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8554
8555     flush_sequence();
8556     /* this one should be received only by old hook proc */
8557     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8558     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8559     /* this one should be received only by old hook proc */
8560     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8561
8562     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8563     /* process pending winevent messages */
8564     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8565     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8566
8567     ret = pUnhookWinEvent(hhook);
8568     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8569
8570     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8571     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8572     CloseHandle(hthread);
8573     CloseHandle(hevent);
8574     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8575     /****** end of out of context event test *************/
8576
8577     /****** start of MOUSE_LL hook test *************/
8578     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8579     /* WH_MOUSE_LL is not supported on Win9x platforms */
8580     if (!hCBT_global_hook)
8581     {
8582         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8583         goto skip_mouse_ll_hook_test;
8584     }
8585
8586     hevent = CreateEventA(NULL, 0, 0, NULL);
8587     assert(hevent);
8588     hwnd2 = hevent;
8589
8590     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8591     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8592
8593     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8594         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8595
8596     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8597     flush_sequence();
8598
8599     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8600     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8601     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8602
8603     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8604
8605     ret = UnhookWindowsHookEx(hCBT_global_hook);
8606     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8607
8608     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8609     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8610     CloseHandle(hthread);
8611     CloseHandle(hevent);
8612     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8613     /****** end of MOUSE_LL hook test *************/
8614 skip_mouse_ll_hook_test:
8615
8616     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8617 }
8618
8619 static void test_set_hook(void)
8620 {
8621     BOOL ret;
8622     HHOOK hhook;
8623     HWINEVENTHOOK hwinevent_hook;
8624
8625     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8626     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8627     UnhookWindowsHookEx(hhook);
8628
8629     if (0)
8630     {
8631     /* this test doesn't pass under Win9x: BUG! */
8632     SetLastError(0xdeadbeef);
8633     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8634     ok(!hhook, "global hook requires hModule != 0\n");
8635     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8636     }
8637
8638     SetLastError(0xdeadbeef);
8639     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8640     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8641     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8642        GetLastError() == 0xdeadbeef, /* Win9x */
8643        "unexpected error %d\n", GetLastError());
8644
8645     SetLastError(0xdeadbeef);
8646     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8647     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8648        GetLastError() == 0xdeadbeef, /* Win9x */
8649        "unexpected error %d\n", GetLastError());
8650
8651     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8652
8653     /* even process local incontext hooks require hmodule */
8654     SetLastError(0xdeadbeef);
8655     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8656         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8657     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8658     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8659        GetLastError() == 0xdeadbeef, /* Win9x */
8660        "unexpected error %d\n", GetLastError());
8661
8662     /* even thread local incontext hooks require hmodule */
8663     SetLastError(0xdeadbeef);
8664     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8665         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8666     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8667     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8668        GetLastError() == 0xdeadbeef, /* Win9x */
8669        "unexpected error %d\n", GetLastError());
8670
8671     if (0)
8672     {
8673     /* these 3 tests don't pass under Win9x */
8674     SetLastError(0xdeadbeef);
8675     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8676         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8677     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8678     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8679
8680     SetLastError(0xdeadbeef);
8681     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8682         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8683     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8684     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8685
8686     SetLastError(0xdeadbeef);
8687     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8688         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8689     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8690     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8691     }
8692
8693     SetLastError(0xdeadbeef);
8694     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8695         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8696     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8697     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8698     ret = pUnhookWinEvent(hwinevent_hook);
8699     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8700
8701 todo_wine {
8702     /* This call succeeds under win2k SP4, but fails under Wine.
8703        Does win2k test/use passed process id? */
8704     SetLastError(0xdeadbeef);
8705     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8706         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8707     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8708     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8709     ret = pUnhookWinEvent(hwinevent_hook);
8710     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8711 }
8712
8713     SetLastError(0xdeadbeef);
8714     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8715     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8716         GetLastError() == 0xdeadbeef, /* Win9x */
8717         "unexpected error %d\n", GetLastError());
8718 }
8719
8720 static const struct message ScrollWindowPaint1[] = {
8721     { WM_PAINT, sent },
8722     { WM_ERASEBKGND, sent|beginpaint },
8723     { WM_GETTEXTLENGTH, sent|optional },
8724     { WM_PAINT, sent|optional },
8725     { WM_NCPAINT, sent|beginpaint|optional },
8726     { WM_GETTEXT, sent|beginpaint|optional },
8727     { WM_GETTEXT, sent|beginpaint|optional },
8728     { WM_GETTEXT, sent|beginpaint|optional },
8729     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8730     { WM_ERASEBKGND, sent|beginpaint|optional },
8731     { 0 }
8732 };
8733
8734 static const struct message ScrollWindowPaint2[] = {
8735     { WM_PAINT, sent },
8736     { 0 }
8737 };
8738
8739 static void test_scrollwindowex(void)
8740 {
8741     HWND hwnd, hchild;
8742     RECT rect={0,0,130,130};
8743
8744     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8745             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8746             100, 100, 200, 200, 0, 0, 0, NULL);
8747     ok (hwnd != 0, "Failed to create overlapped window\n");
8748     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8749             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8750             10, 10, 150, 150, hwnd, 0, 0, NULL);
8751     ok (hchild != 0, "Failed to create child\n");
8752     UpdateWindow(hwnd);
8753     flush_events();
8754     flush_sequence();
8755
8756     /* scroll without the child window */
8757     trace("start scroll\n");
8758     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8759             SW_ERASE|SW_INVALIDATE);
8760     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8761     trace("end scroll\n");
8762     flush_sequence();
8763     flush_events();
8764     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8765     flush_events();
8766     flush_sequence();
8767
8768     /* Now without the SW_ERASE flag */
8769     trace("start scroll\n");
8770     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8771     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8772     trace("end scroll\n");
8773     flush_sequence();
8774     flush_events();
8775     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8776     flush_events();
8777     flush_sequence();
8778
8779     /* now scroll the child window as well */
8780     trace("start scroll\n");
8781     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8782             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8783     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8784     /* windows sometimes a WM_MOVE */
8785     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8786     trace("end scroll\n");
8787     flush_sequence();
8788     flush_events();
8789     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8790     flush_events();
8791     flush_sequence();
8792
8793     /* now scroll with ScrollWindow() */
8794     trace("start scroll with ScrollWindow\n");
8795     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8796     trace("end scroll\n");
8797     flush_sequence();
8798     flush_events();
8799     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8800
8801     ok(DestroyWindow(hchild), "failed to destroy window\n");
8802     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8803     flush_sequence();
8804 }
8805
8806 static const struct message destroy_window_with_children[] = {
8807     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8808     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8809     { 0x0090, sent|optional },
8810     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8811     { 0x0090, sent|optional },
8812     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8813     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8814     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8815     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8816     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8817     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8818     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8819     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8820     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8821     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8822     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8823     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8824     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8825     { 0 }
8826 };
8827
8828 static void test_DestroyWindow(void)
8829 {
8830     BOOL ret;
8831     HWND parent, child1, child2, child3, child4, test;
8832     UINT_PTR child_id = WND_CHILD_ID + 1;
8833
8834     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8835                              100, 100, 200, 200, 0, 0, 0, NULL);
8836     assert(parent != 0);
8837     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8838                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8839     assert(child1 != 0);
8840     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8841                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8842     assert(child2 != 0);
8843     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8844                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8845     assert(child3 != 0);
8846     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8847                              0, 0, 50, 50, parent, 0, 0, NULL);
8848     assert(child4 != 0);
8849
8850     /* test owner/parent of child2 */
8851     test = GetParent(child2);
8852     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8853     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8854     if(pGetAncestor) {
8855         test = pGetAncestor(child2, GA_PARENT);
8856         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8857     }
8858     test = GetWindow(child2, GW_OWNER);
8859     ok(!test, "wrong owner %p\n", test);
8860
8861     test = SetParent(child2, parent);
8862     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8863
8864     /* test owner/parent of the parent */
8865     test = GetParent(parent);
8866     ok(!test, "wrong parent %p\n", test);
8867     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8868     if(pGetAncestor) {
8869         test = pGetAncestor(parent, GA_PARENT);
8870         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8871     }
8872     test = GetWindow(parent, GW_OWNER);
8873     ok(!test, "wrong owner %p\n", test);
8874
8875     /* test owner/parent of child1 */
8876     test = GetParent(child1);
8877     ok(test == parent, "wrong parent %p\n", test);
8878     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8879     if(pGetAncestor) {
8880         test = pGetAncestor(child1, GA_PARENT);
8881         ok(test == parent, "wrong parent %p\n", test);
8882     }
8883     test = GetWindow(child1, GW_OWNER);
8884     ok(!test, "wrong owner %p\n", test);
8885
8886     /* test owner/parent of child2 */
8887     test = GetParent(child2);
8888     ok(test == parent, "wrong parent %p\n", test);
8889     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8890     if(pGetAncestor) {
8891         test = pGetAncestor(child2, GA_PARENT);
8892         ok(test == parent, "wrong parent %p\n", test);
8893     }
8894     test = GetWindow(child2, GW_OWNER);
8895     ok(!test, "wrong owner %p\n", test);
8896
8897     /* test owner/parent of child3 */
8898     test = GetParent(child3);
8899     ok(test == child1, "wrong parent %p\n", test);
8900     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8901     if(pGetAncestor) {
8902         test = pGetAncestor(child3, GA_PARENT);
8903         ok(test == child1, "wrong parent %p\n", test);
8904     }
8905     test = GetWindow(child3, GW_OWNER);
8906     ok(!test, "wrong owner %p\n", test);
8907
8908     /* test owner/parent of child4 */
8909     test = GetParent(child4);
8910     ok(test == parent, "wrong parent %p\n", test);
8911     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8912     if(pGetAncestor) {
8913         test = pGetAncestor(child4, GA_PARENT);
8914         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8915     }
8916     test = GetWindow(child4, GW_OWNER);
8917     ok(test == parent, "wrong owner %p\n", test);
8918
8919     flush_sequence();
8920
8921     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8922            parent, child1, child2, child3, child4);
8923
8924     SetCapture(child4);
8925     test = GetCapture();
8926     ok(test == child4, "wrong capture window %p\n", test);
8927
8928     test_DestroyWindow_flag = TRUE;
8929     ret = DestroyWindow(parent);
8930     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8931     test_DestroyWindow_flag = FALSE;
8932     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8933
8934     ok(!IsWindow(parent), "parent still exists\n");
8935     ok(!IsWindow(child1), "child1 still exists\n");
8936     ok(!IsWindow(child2), "child2 still exists\n");
8937     ok(!IsWindow(child3), "child3 still exists\n");
8938     ok(!IsWindow(child4), "child4 still exists\n");
8939
8940     test = GetCapture();
8941     ok(!test, "wrong capture window %p\n", test);
8942 }
8943
8944
8945 static const struct message WmDispatchPaint[] = {
8946     { WM_NCPAINT, sent },
8947     { WM_GETTEXT, sent|defwinproc|optional },
8948     { WM_GETTEXT, sent|defwinproc|optional },
8949     { WM_ERASEBKGND, sent },
8950     { 0 }
8951 };
8952
8953 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8954 {
8955     if (message == WM_PAINT) return 0;
8956     return MsgCheckProcA( hwnd, message, wParam, lParam );
8957 }
8958
8959 static void test_DispatchMessage(void)
8960 {
8961     RECT rect;
8962     MSG msg;
8963     int count;
8964     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8965                                100, 100, 200, 200, 0, 0, 0, NULL);
8966     ShowWindow( hwnd, SW_SHOW );
8967     UpdateWindow( hwnd );
8968     flush_events();
8969     flush_sequence();
8970     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8971
8972     SetRect( &rect, -5, -5, 5, 5 );
8973     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8974     count = 0;
8975     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8976     {
8977         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8978         else
8979         {
8980             flush_sequence();
8981             DispatchMessage( &msg );
8982             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8983             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8984             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8985             if (++count > 10) break;
8986         }
8987     }
8988     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8989
8990     trace("now without DispatchMessage\n");
8991     flush_sequence();
8992     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8993     count = 0;
8994     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8995     {
8996         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8997         else
8998         {
8999             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9000             flush_sequence();
9001             /* this will send WM_NCCPAINT just like DispatchMessage does */
9002             GetUpdateRgn( hwnd, hrgn, TRUE );
9003             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9004             DeleteObject( hrgn );
9005             GetClientRect( hwnd, &rect );
9006             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
9007             ok( !count, "Got multiple WM_PAINTs\n" );
9008             if (++count > 10) break;
9009         }
9010     }
9011     DestroyWindow(hwnd);
9012 }
9013
9014
9015 static const struct message WmUser[] = {
9016     { WM_USER, sent },
9017     { 0 }
9018 };
9019
9020 struct sendmsg_info
9021 {
9022     HWND  hwnd;
9023     DWORD timeout;
9024     DWORD ret;
9025 };
9026
9027 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9028 {
9029     struct sendmsg_info *info = arg;
9030     SetLastError( 0xdeadbeef );
9031     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9032     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9033                         broken(GetLastError() == 0),  /* win9x */
9034                         "unexpected error %d\n", GetLastError());
9035     return 0;
9036 }
9037
9038 static void wait_for_thread( HANDLE thread )
9039 {
9040     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9041     {
9042         MSG msg;
9043         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9044     }
9045 }
9046
9047 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9048 {
9049     if (message == WM_USER) Sleep(200);
9050     return MsgCheckProcA( hwnd, message, wParam, lParam );
9051 }
9052
9053 static void test_SendMessageTimeout(void)
9054 {
9055     HANDLE thread;
9056     struct sendmsg_info info;
9057     DWORD tid;
9058     BOOL is_win9x;
9059
9060     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9061                                100, 100, 200, 200, 0, 0, 0, NULL);
9062     flush_events();
9063     flush_sequence();
9064
9065     info.timeout = 1000;
9066     info.ret = 0xdeadbeef;
9067     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9068     wait_for_thread( thread );
9069     CloseHandle( thread );
9070     ok( info.ret == 1, "SendMessageTimeout failed\n" );
9071     ok_sequence( WmUser, "WmUser", FALSE );
9072
9073     info.timeout = 1;
9074     info.ret = 0xdeadbeef;
9075     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9076     Sleep(100);  /* SendMessageTimeout should time out here */
9077     wait_for_thread( thread );
9078     CloseHandle( thread );
9079     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9080     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9081
9082     /* 0 means infinite timeout (but not on win9x) */
9083     info.timeout = 0;
9084     info.ret = 0xdeadbeef;
9085     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9086     Sleep(100);
9087     wait_for_thread( thread );
9088     CloseHandle( thread );
9089     is_win9x = !info.ret;
9090     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9091     else ok_sequence( WmUser, "WmUser", FALSE );
9092
9093     /* timeout is treated as signed despite the prototype (but not on win9x) */
9094     info.timeout = 0x7fffffff;
9095     info.ret = 0xdeadbeef;
9096     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9097     Sleep(100);
9098     wait_for_thread( thread );
9099     CloseHandle( thread );
9100     ok( info.ret == 1, "SendMessageTimeout failed\n" );
9101     ok_sequence( WmUser, "WmUser", FALSE );
9102
9103     info.timeout = 0x80000000;
9104     info.ret = 0xdeadbeef;
9105     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9106     Sleep(100);
9107     wait_for_thread( thread );
9108     CloseHandle( thread );
9109     if (is_win9x)
9110     {
9111         ok( info.ret == 1, "SendMessageTimeout failed\n" );
9112         ok_sequence( WmUser, "WmUser", FALSE );
9113     }
9114     else
9115     {
9116         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9117         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9118     }
9119
9120     /* now check for timeout during message processing */
9121     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9122     info.timeout = 100;
9123     info.ret = 0xdeadbeef;
9124     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9125     wait_for_thread( thread );
9126     CloseHandle( thread );
9127     /* we should time out but still get the message */
9128     ok( info.ret == 0, "SendMessageTimeout failed\n" );
9129     ok_sequence( WmUser, "WmUser", FALSE );
9130
9131     DestroyWindow( info.hwnd );
9132 }
9133
9134
9135 /****************** edit message test *************************/
9136 #define ID_EDIT 0x1234
9137 static const struct message sl_edit_setfocus[] =
9138 {
9139     { HCBT_SETFOCUS, hook },
9140     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9141     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9142     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9143     { WM_SETFOCUS, sent|wparam, 0 },
9144     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9145     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9146     { WM_CTLCOLOREDIT, sent|parent },
9147     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9148     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9149     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9150     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9151     { 0 }
9152 };
9153 static const struct message ml_edit_setfocus[] =
9154 {
9155     { HCBT_SETFOCUS, hook },
9156     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9157     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9158     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9159     { WM_SETFOCUS, sent|wparam, 0 },
9160     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9161     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9162     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9163     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9164     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9165     { 0 }
9166 };
9167 static const struct message sl_edit_killfocus[] =
9168 {
9169     { HCBT_SETFOCUS, hook },
9170     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9171     { WM_KILLFOCUS, sent|wparam, 0 },
9172     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9173     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9174     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9175     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9176     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9177     { 0 }
9178 };
9179 static const struct message sl_edit_lbutton_dblclk[] =
9180 {
9181     { WM_LBUTTONDBLCLK, sent },
9182     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9183     { 0 }
9184 };
9185 static const struct message sl_edit_lbutton_down[] =
9186 {
9187     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9188     { HCBT_SETFOCUS, hook },
9189     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9190     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9191     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9192     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9193     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9194     { WM_CTLCOLOREDIT, sent|parent },
9195     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9196     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9197     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9198     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9199     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9200     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9201     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9202     { WM_CTLCOLOREDIT, sent|parent|optional },
9203     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9204     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9205     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9206     { 0 }
9207 };
9208 static const struct message ml_edit_lbutton_down[] =
9209 {
9210     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9211     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9212     { HCBT_SETFOCUS, hook },
9213     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9214     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9215     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9216     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9217     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9218     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9219     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9220     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9221     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9222     { 0 }
9223 };
9224 static const struct message sl_edit_lbutton_up[] =
9225 {
9226     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9227     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9228     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9229     { WM_CAPTURECHANGED, sent|defwinproc },
9230     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9231     { 0 }
9232 };
9233 static const struct message ml_edit_lbutton_up[] =
9234 {
9235     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9236     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9237     { WM_CAPTURECHANGED, sent|defwinproc },
9238     { 0 }
9239 };
9240
9241 static WNDPROC old_edit_proc;
9242
9243 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9244 {
9245     static LONG defwndproc_counter = 0;
9246     LRESULT ret;
9247     struct recvd_message msg;
9248
9249     if (ignore_message( message )) return 0;
9250
9251     msg.hwnd = hwnd;
9252     msg.message = message;
9253     msg.flags = sent|wparam|lparam;
9254     if (defwndproc_counter) msg.flags |= defwinproc;
9255     msg.wParam = wParam;
9256     msg.lParam = lParam;
9257     msg.descr = "edit";
9258     add_message(&msg);
9259
9260     defwndproc_counter++;
9261     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9262     defwndproc_counter--;
9263
9264     return ret;
9265 }
9266
9267 static void subclass_edit(void)
9268 {
9269     WNDCLASSA cls;
9270
9271     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9272
9273     old_edit_proc = cls.lpfnWndProc;
9274
9275     cls.hInstance = GetModuleHandle(0);
9276     cls.lpfnWndProc = edit_hook_proc;
9277     cls.lpszClassName = "my_edit_class";
9278     UnregisterClass(cls.lpszClassName, cls.hInstance);
9279     if (!RegisterClassA(&cls)) assert(0);
9280 }
9281
9282 static void test_edit_messages(void)
9283 {
9284     HWND hwnd, parent;
9285     DWORD dlg_code;
9286
9287     subclass_edit();
9288     log_all_parent_messages++;
9289
9290     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9291                              100, 100, 200, 200, 0, 0, 0, NULL);
9292     ok (parent != 0, "Failed to create parent window\n");
9293
9294     /* test single line edit */
9295     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9296                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9297     ok(hwnd != 0, "Failed to create edit window\n");
9298
9299     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9300     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9301
9302     ShowWindow(hwnd, SW_SHOW);
9303     UpdateWindow(hwnd);
9304     SetFocus(0);
9305     flush_sequence();
9306
9307     SetFocus(hwnd);
9308     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9309
9310     SetFocus(0);
9311     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9312
9313     SetFocus(0);
9314     ReleaseCapture();
9315     flush_sequence();
9316
9317     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9318     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9319
9320     SetFocus(0);
9321     ReleaseCapture();
9322     flush_sequence();
9323
9324     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9325     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9326
9327     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9328     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9329
9330     DestroyWindow(hwnd);
9331
9332     /* test multiline edit */
9333     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9334                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9335     ok(hwnd != 0, "Failed to create edit window\n");
9336
9337     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9338     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9339        "wrong dlg_code %08x\n", dlg_code);
9340
9341     ShowWindow(hwnd, SW_SHOW);
9342     UpdateWindow(hwnd);
9343     SetFocus(0);
9344     flush_sequence();
9345
9346     SetFocus(hwnd);
9347     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9348
9349     SetFocus(0);
9350     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9351
9352     SetFocus(0);
9353     ReleaseCapture();
9354     flush_sequence();
9355
9356     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9357     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9358
9359     SetFocus(0);
9360     ReleaseCapture();
9361     flush_sequence();
9362
9363     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9364     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9365
9366     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9367     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9368
9369     DestroyWindow(hwnd);
9370     DestroyWindow(parent);
9371
9372     log_all_parent_messages--;
9373 }
9374
9375 /**************************** End of Edit test ******************************/
9376
9377 static const struct message WmKeyDownSkippedSeq[] =
9378 {
9379     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9380     { 0 }
9381 };
9382 static const struct message WmKeyDownWasDownSkippedSeq[] =
9383 {
9384     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9385     { 0 }
9386 };
9387 static const struct message WmKeyUpSkippedSeq[] =
9388 {
9389     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9390     { 0 }
9391 };
9392 static const struct message WmUserKeyUpSkippedSeq[] =
9393 {
9394     { WM_USER, sent },
9395     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9396     { 0 }
9397 };
9398
9399 #define EV_STOP 0
9400 #define EV_SENDMSG 1
9401 #define EV_ACK 2
9402
9403 struct peekmsg_info
9404 {
9405     HWND  hwnd;
9406     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9407 };
9408
9409 static DWORD CALLBACK send_msg_thread_2(void *param)
9410 {
9411     DWORD ret;
9412     struct peekmsg_info *info = param;
9413
9414     trace("thread: looping\n");
9415     SetEvent(info->hevent[EV_ACK]);
9416
9417     while (1)
9418     {
9419         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9420
9421         switch (ret)
9422         {
9423         case WAIT_OBJECT_0 + EV_STOP:
9424             trace("thread: exiting\n");
9425             return 0;
9426
9427         case WAIT_OBJECT_0 + EV_SENDMSG:
9428             trace("thread: sending message\n");
9429             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9430                 "SendNotifyMessageA failed error %u\n", GetLastError());
9431             SetEvent(info->hevent[EV_ACK]);
9432             break;
9433
9434         default:
9435             trace("unexpected return: %04x\n", ret);
9436             assert(0);
9437             break;
9438         }
9439     }
9440     return 0;
9441 }
9442
9443 static void test_PeekMessage(void)
9444 {
9445     MSG msg;
9446     HANDLE hthread;
9447     DWORD tid, qstatus;
9448     UINT qs_all_input = QS_ALLINPUT;
9449     UINT qs_input = QS_INPUT;
9450     BOOL ret;
9451     struct peekmsg_info info;
9452
9453     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9454                               100, 100, 200, 200, 0, 0, 0, NULL);
9455     assert(info.hwnd);
9456     ShowWindow(info.hwnd, SW_SHOW);
9457     UpdateWindow(info.hwnd);
9458     SetFocus(info.hwnd);
9459
9460     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9461     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9462     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9463
9464     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9465     WaitForSingleObject(info.hevent[EV_ACK], 10000);
9466
9467     flush_events();
9468     flush_sequence();
9469
9470     SetLastError(0xdeadbeef);
9471     qstatus = GetQueueStatus(qs_all_input);
9472     if (GetLastError() == ERROR_INVALID_FLAGS)
9473     {
9474         trace("QS_RAWINPUT not supported on this platform\n");
9475         qs_all_input &= ~QS_RAWINPUT;
9476         qs_input &= ~QS_RAWINPUT;
9477     }
9478     if (qstatus & QS_POSTMESSAGE)
9479     {
9480         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9481         qstatus = GetQueueStatus(qs_all_input);
9482     }
9483     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9484
9485     trace("signalling to send message\n");
9486     SetEvent(info.hevent[EV_SENDMSG]);
9487     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9488
9489     /* pass invalid QS_xxxx flags */
9490     SetLastError(0xdeadbeef);
9491     qstatus = GetQueueStatus(0xffffffff);
9492     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9493     if (!qstatus)
9494     {
9495         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9496         qstatus = GetQueueStatus(qs_all_input);
9497     }
9498     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9499     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9500        "wrong qstatus %08x\n", qstatus);
9501
9502     msg.message = 0;
9503     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9504     ok(!ret,
9505        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9506         msg.message);
9507     ok_sequence(WmUser, "WmUser", FALSE);
9508
9509     qstatus = GetQueueStatus(qs_all_input);
9510     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9511
9512     keybd_event('N', 0, 0, 0);
9513     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9514     qstatus = GetQueueStatus(qs_all_input);
9515     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9516     {
9517         skip( "queuing key events not supported\n" );
9518         goto done;
9519     }
9520     ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9521        /* keybd_event seems to trigger a sent message on NT4 */
9522        qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9523        "wrong qstatus %08x\n", qstatus);
9524
9525     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9526     qstatus = GetQueueStatus(qs_all_input);
9527     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9528        qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9529        "wrong qstatus %08x\n", qstatus);
9530
9531     InvalidateRect(info.hwnd, NULL, FALSE);
9532     qstatus = GetQueueStatus(qs_all_input);
9533     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9534        qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9535        "wrong qstatus %08x\n", qstatus);
9536
9537     trace("signalling to send message\n");
9538     SetEvent(info.hevent[EV_SENDMSG]);
9539     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9540
9541     qstatus = GetQueueStatus(qs_all_input);
9542     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9543        "wrong qstatus %08x\n", qstatus);
9544
9545     msg.message = 0;
9546     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9547     if (ret && msg.message == WM_CHAR)
9548     {
9549         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9550         goto done;
9551     }
9552     ok(!ret,
9553        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9554         msg.message);
9555     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9556     {
9557         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9558         goto done;
9559     }
9560     ok_sequence(WmUser, "WmUser", FALSE);
9561
9562     qstatus = GetQueueStatus(qs_all_input);
9563     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9564        "wrong qstatus %08x\n", qstatus);
9565
9566     trace("signalling to send message\n");
9567     SetEvent(info.hevent[EV_SENDMSG]);
9568     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9569
9570     qstatus = GetQueueStatus(qs_all_input);
9571     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9572        "wrong qstatus %08x\n", qstatus);
9573
9574     msg.message = 0;
9575     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9576     ok(!ret,
9577        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9578         msg.message);
9579     ok_sequence(WmUser, "WmUser", FALSE);
9580
9581     qstatus = GetQueueStatus(qs_all_input);
9582     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9583        "wrong qstatus %08x\n", qstatus);
9584
9585     msg.message = 0;
9586     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9587     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9588        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9589        ret, msg.message, msg.wParam);
9590     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9591
9592     qstatus = GetQueueStatus(qs_all_input);
9593     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9594        "wrong qstatus %08x\n", qstatus);
9595
9596     msg.message = 0;
9597     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9598     ok(!ret,
9599        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9600         msg.message);
9601     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9602
9603     qstatus = GetQueueStatus(qs_all_input);
9604     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9605        "wrong qstatus %08x\n", qstatus);
9606
9607     msg.message = 0;
9608     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9609     ok(ret && msg.message == WM_PAINT,
9610        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9611     DispatchMessageA(&msg);
9612     ok_sequence(WmPaint, "WmPaint", FALSE);
9613
9614     qstatus = GetQueueStatus(qs_all_input);
9615     ok(qstatus == MAKELONG(0, QS_KEY),
9616        "wrong qstatus %08x\n", qstatus);
9617
9618     msg.message = 0;
9619     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9620     ok(!ret,
9621        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9622         msg.message);
9623     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9624
9625     qstatus = GetQueueStatus(qs_all_input);
9626     ok(qstatus == MAKELONG(0, QS_KEY),
9627        "wrong qstatus %08x\n", qstatus);
9628
9629     trace("signalling to send message\n");
9630     SetEvent(info.hevent[EV_SENDMSG]);
9631     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9632
9633     qstatus = GetQueueStatus(qs_all_input);
9634     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9635        "wrong qstatus %08x\n", qstatus);
9636
9637     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9638
9639     qstatus = GetQueueStatus(qs_all_input);
9640     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9641        "wrong qstatus %08x\n", qstatus);
9642
9643     msg.message = 0;
9644     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9645     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9646        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9647        ret, msg.message, msg.wParam);
9648     ok_sequence(WmUser, "WmUser", FALSE);
9649
9650     qstatus = GetQueueStatus(qs_all_input);
9651     ok(qstatus == MAKELONG(0, QS_KEY),
9652        "wrong qstatus %08x\n", qstatus);
9653
9654     msg.message = 0;
9655     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9656     ok(!ret,
9657        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9658         msg.message);
9659     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9660
9661     qstatus = GetQueueStatus(qs_all_input);
9662     ok(qstatus == MAKELONG(0, QS_KEY),
9663        "wrong qstatus %08x\n", qstatus);
9664
9665     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9666
9667     qstatus = GetQueueStatus(qs_all_input);
9668     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9669        "wrong qstatus %08x\n", qstatus);
9670
9671     trace("signalling to send message\n");
9672     SetEvent(info.hevent[EV_SENDMSG]);
9673     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9674
9675     qstatus = GetQueueStatus(qs_all_input);
9676     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9677        "wrong qstatus %08x\n", qstatus);
9678
9679     msg.message = 0;
9680     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9681     ok(!ret,
9682        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9683         msg.message);
9684     ok_sequence(WmUser, "WmUser", FALSE);
9685
9686     qstatus = GetQueueStatus(qs_all_input);
9687     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9688        "wrong qstatus %08x\n", qstatus);
9689
9690     msg.message = 0;
9691     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9692         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9693     else /* workaround for a missing QS_RAWINPUT support */
9694         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9695     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9696        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9697        ret, msg.message, msg.wParam);
9698     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9699
9700     qstatus = GetQueueStatus(qs_all_input);
9701     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9702        "wrong qstatus %08x\n", qstatus);
9703
9704     msg.message = 0;
9705     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9706         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9707     else /* workaround for a missing QS_RAWINPUT support */
9708         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9709     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9710        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9711        ret, msg.message, msg.wParam);
9712     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9713
9714     qstatus = GetQueueStatus(qs_all_input);
9715     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9716        "wrong qstatus %08x\n", qstatus);
9717
9718     msg.message = 0;
9719     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9720     ok(!ret,
9721        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9722         msg.message);
9723     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9724
9725     qstatus = GetQueueStatus(qs_all_input);
9726     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9727        "wrong qstatus %08x\n", qstatus);
9728
9729     msg.message = 0;
9730     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9731     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9732        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9733        ret, msg.message, msg.wParam);
9734     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9735
9736     qstatus = GetQueueStatus(qs_all_input);
9737     ok(qstatus == 0,
9738        "wrong qstatus %08x\n", qstatus);
9739
9740     msg.message = 0;
9741     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9742     ok(!ret,
9743        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9744         msg.message);
9745     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9746
9747     qstatus = GetQueueStatus(qs_all_input);
9748     ok(qstatus == 0,
9749        "wrong qstatus %08x\n", qstatus);
9750
9751     /* test whether presence of the quit flag in the queue affects
9752      * the queue state
9753      */
9754     PostQuitMessage(0x1234abcd);
9755
9756     qstatus = GetQueueStatus(qs_all_input);
9757     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9758        "wrong qstatus %08x\n", qstatus);
9759
9760     PostMessageA(info.hwnd, WM_USER, 0, 0);
9761
9762     qstatus = GetQueueStatus(qs_all_input);
9763     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9764        "wrong qstatus %08x\n", qstatus);
9765
9766     msg.message = 0;
9767     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9768     ok(ret && msg.message == WM_USER,
9769        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9770     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9771
9772     qstatus = GetQueueStatus(qs_all_input);
9773     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9774        "wrong qstatus %08x\n", qstatus);
9775
9776     msg.message = 0;
9777     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9778     ok(ret && msg.message == WM_QUIT,
9779        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9780     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9781     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9782     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9783
9784     qstatus = GetQueueStatus(qs_all_input);
9785 todo_wine {
9786     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9787        "wrong qstatus %08x\n", qstatus);
9788 }
9789
9790     msg.message = 0;
9791     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9792     ok(!ret,
9793        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9794         msg.message);
9795     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9796
9797     qstatus = GetQueueStatus(qs_all_input);
9798     ok(qstatus == 0,
9799        "wrong qstatus %08x\n", qstatus);
9800
9801     /* some GetMessage tests */
9802
9803     keybd_event('N', 0, 0, 0);
9804     qstatus = GetQueueStatus(qs_all_input);
9805     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9806
9807     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9808     qstatus = GetQueueStatus(qs_all_input);
9809     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9810
9811     if (qstatus)
9812     {
9813         ret = GetMessageA( &msg, 0, 0, 0 );
9814         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9815            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9816            ret, msg.message, msg.wParam);
9817         qstatus = GetQueueStatus(qs_all_input);
9818         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9819     }
9820
9821     if (qstatus)
9822     {
9823         ret = GetMessageA( &msg, 0, 0, 0 );
9824         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9825            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9826            ret, msg.message, msg.wParam);
9827         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9828         qstatus = GetQueueStatus(qs_all_input);
9829         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9830     }
9831
9832     keybd_event('N', 0, 0, 0);
9833     qstatus = GetQueueStatus(qs_all_input);
9834     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9835
9836     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9837     qstatus = GetQueueStatus(qs_all_input);
9838     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9839
9840     if (qstatus & (QS_KEY << 16))
9841     {
9842         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9843         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9844            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9845            ret, msg.message, msg.wParam);
9846         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9847         qstatus = GetQueueStatus(qs_all_input);
9848         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9849     }
9850
9851     if (qstatus)
9852     {
9853         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9854         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9855            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9856            ret, msg.message, msg.wParam);
9857         qstatus = GetQueueStatus(qs_all_input);
9858         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9859     }
9860
9861     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9862     qstatus = GetQueueStatus(qs_all_input);
9863     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9864
9865     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9866     qstatus = GetQueueStatus(qs_all_input);
9867     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9868
9869     trace("signalling to send message\n");
9870     SetEvent(info.hevent[EV_SENDMSG]);
9871     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9872     qstatus = GetQueueStatus(qs_all_input);
9873     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9874        "wrong qstatus %08x\n", qstatus);
9875
9876     if (qstatus & (QS_KEY << 16))
9877     {
9878         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9879         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9880            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9881            ret, msg.message, msg.wParam);
9882         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9883         qstatus = GetQueueStatus(qs_all_input);
9884         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9885     }
9886
9887     if (qstatus)
9888     {
9889         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9890         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9891            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9892            ret, msg.message, msg.wParam);
9893         qstatus = GetQueueStatus(qs_all_input);
9894         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9895     }
9896 done:
9897     trace("signalling to exit\n");
9898     SetEvent(info.hevent[EV_STOP]);
9899
9900     WaitForSingleObject(hthread, INFINITE);
9901
9902     CloseHandle(hthread);
9903     CloseHandle(info.hevent[0]);
9904     CloseHandle(info.hevent[1]);
9905     CloseHandle(info.hevent[2]);
9906
9907     DestroyWindow(info.hwnd);
9908 }
9909
9910 static void wait_move_event(HWND hwnd, int x, int y)
9911 {
9912     MSG msg;
9913     DWORD time;
9914     BOOL  ret;
9915     int go = 0;
9916
9917     time = GetTickCount();
9918     while (GetTickCount() - time < 200 && !go) {
9919         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9920         go  = ret && msg.pt.x > x && msg.pt.y > y;
9921         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9922     }
9923 }
9924
9925 #define STEP 5
9926 static void test_PeekMessage2(void)
9927 {
9928     HWND hwnd;
9929     BOOL ret;
9930     MSG msg;
9931     UINT message;
9932     DWORD time1, time2, time3;
9933     int x1, y1, x2, y2, x3, y3;
9934     POINT pos;
9935
9936     time1 = time2 = time3 = 0;
9937     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9938
9939     /* Initialise window and make sure it is ready for events */
9940     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9941                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9942     assert(hwnd);
9943     trace("Window for test_PeekMessage2 %p\n", hwnd);
9944     ShowWindow(hwnd, SW_SHOW);
9945     UpdateWindow(hwnd);
9946     SetFocus(hwnd);
9947     GetCursorPos(&pos);
9948     SetCursorPos(100, 100);
9949     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9950     flush_events();
9951
9952     /* Do initial mousemove, wait until we can see it
9953        and then do our test peek with PM_NOREMOVE. */
9954     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9955     wait_move_event(hwnd, 100-STEP, 100-STEP);
9956
9957     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9958     if (!ret)
9959     {
9960         skip( "queuing mouse events not supported\n" );
9961         goto done;
9962     }
9963     else
9964     {
9965         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9966         message = msg.message;
9967         time1 = msg.time;
9968         x1 = msg.pt.x;
9969         y1 = msg.pt.y;
9970         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9971     }
9972
9973     /* Allow time to advance a bit, and then simulate the user moving their
9974      * mouse around. After that we peek again with PM_NOREMOVE.
9975      * Although the previous mousemove message was never removed, the
9976      * mousemove we now peek should reflect the recent mouse movements
9977      * because the input queue will merge the move events. */
9978     Sleep(100);
9979     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9980     wait_move_event(hwnd, x1, y1);
9981
9982     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9983     ok(ret, "no message available\n");
9984     if (ret) {
9985         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9986         message = msg.message;
9987         time2 = msg.time;
9988         x2 = msg.pt.x;
9989         y2 = msg.pt.y;
9990         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9991         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9992         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9993     }
9994
9995     /* Have another go, to drive the point home */
9996     Sleep(100);
9997     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9998     wait_move_event(hwnd, x2, y2);
9999
10000     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10001     ok(ret, "no message available\n");
10002     if (ret) {
10003         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10004         message = msg.message;
10005         time3 = msg.time;
10006         x3 = msg.pt.x;
10007         y3 = msg.pt.y;
10008         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10009         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10010         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10011     }
10012
10013 done:
10014     DestroyWindow(hwnd);
10015     SetCursorPos(pos.x, pos.y);
10016     flush_events();
10017 }
10018
10019 static void test_quit_message(void)
10020 {
10021     MSG msg;
10022     BOOL ret;
10023
10024     /* test using PostQuitMessage */
10025     flush_events();
10026     PostQuitMessage(0xbeef);
10027
10028     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10029     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10030     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10031     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10032
10033     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10034     ok(ret, "PostMessage failed with error %d\n", GetLastError());
10035
10036     ret = GetMessage(&msg, NULL, 0, 0);
10037     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10038     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10039
10040     /* note: WM_QUIT message received after WM_USER message */
10041     ret = GetMessage(&msg, NULL, 0, 0);
10042     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10043     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10044     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10045
10046     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10047     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10048
10049     /* now test with PostThreadMessage - different behaviour! */
10050     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10051
10052     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10053     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10054     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10055     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10056
10057     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10058     ok(ret, "PostMessage failed with error %d\n", GetLastError());
10059
10060     /* note: we receive the WM_QUIT message first this time */
10061     ret = GetMessage(&msg, NULL, 0, 0);
10062     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10063     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10064     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10065
10066     ret = GetMessage(&msg, NULL, 0, 0);
10067     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10068     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10069 }
10070
10071 static const struct message WmMouseHoverSeq[] = {
10072     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10073     { WM_MOUSEACTIVATE, sent|optional },
10074     { WM_TIMER, sent|optional }, /* XP sends it */
10075     { WM_SYSTIMER, sent },
10076     { WM_MOUSEHOVER, sent|wparam, 0 },
10077     { 0 }
10078 };
10079
10080 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10081 {
10082     MSG msg;
10083     DWORD start_ticks, end_ticks;
10084
10085     start_ticks = GetTickCount();
10086     /* add some deviation (50%) to cover not expected delays */
10087     start_ticks += timeout / 2;
10088
10089     do
10090     {
10091         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10092         {
10093             /* Timer proc messages are not dispatched to the window proc,
10094              * and therefore not logged.
10095              */
10096             if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10097             {
10098                 struct recvd_message s_msg;
10099
10100                 s_msg.hwnd = msg.hwnd;
10101                 s_msg.message = msg.message;
10102                 s_msg.flags = sent|wparam|lparam;
10103                 s_msg.wParam = msg.wParam;
10104                 s_msg.lParam = msg.lParam;
10105                 s_msg.descr = "msg_loop";
10106                 add_message(&s_msg);
10107             }
10108             DispatchMessage(&msg);
10109         }
10110
10111         end_ticks = GetTickCount();
10112
10113         /* inject WM_MOUSEMOVE to see how it changes tracking */
10114         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10115         {
10116             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10117             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10118
10119             inject_mouse_move = FALSE;
10120         }
10121     } while (start_ticks + timeout >= end_ticks);
10122 }
10123
10124 static void test_TrackMouseEvent(void)
10125 {
10126     TRACKMOUSEEVENT tme;
10127     BOOL ret;
10128     HWND hwnd, hchild;
10129     RECT rc_parent, rc_child;
10130     UINT default_hover_time, hover_width = 0, hover_height = 0;
10131
10132 #define track_hover(track_hwnd, track_hover_time) \
10133     tme.cbSize = sizeof(tme); \
10134     tme.dwFlags = TME_HOVER; \
10135     tme.hwndTrack = track_hwnd; \
10136     tme.dwHoverTime = track_hover_time; \
10137     SetLastError(0xdeadbeef); \
10138     ret = pTrackMouseEvent(&tme); \
10139     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10140
10141 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10142     tme.cbSize = sizeof(tme); \
10143     tme.dwFlags = TME_QUERY; \
10144     tme.hwndTrack = (HWND)0xdeadbeef; \
10145     tme.dwHoverTime = 0xdeadbeef; \
10146     SetLastError(0xdeadbeef); \
10147     ret = pTrackMouseEvent(&tme); \
10148     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10149     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10150     ok(tme.dwFlags == (expected_track_flags), \
10151        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10152     ok(tme.hwndTrack == (expected_track_hwnd), \
10153        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10154     ok(tme.dwHoverTime == (expected_hover_time), \
10155        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10156
10157 #define track_hover_cancel(track_hwnd) \
10158     tme.cbSize = sizeof(tme); \
10159     tme.dwFlags = TME_HOVER | TME_CANCEL; \
10160     tme.hwndTrack = track_hwnd; \
10161     tme.dwHoverTime = 0xdeadbeef; \
10162     SetLastError(0xdeadbeef); \
10163     ret = pTrackMouseEvent(&tme); \
10164     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10165
10166     default_hover_time = 0xdeadbeef;
10167     SetLastError(0xdeadbeef);
10168     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10169     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10170        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10171     if (!ret) default_hover_time = 400;
10172     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10173
10174     SetLastError(0xdeadbeef);
10175     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10176     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10177        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10178     if (!ret) hover_width = 4;
10179     SetLastError(0xdeadbeef);
10180     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10181     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10182        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10183     if (!ret) hover_height = 4;
10184     trace("hover rect is %u x %d\n", hover_width, hover_height);
10185
10186     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10187                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10188                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10189                           NULL, NULL, 0);
10190     assert(hwnd);
10191
10192     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10193                           WS_CHILD | WS_BORDER | WS_VISIBLE,
10194                           50, 50, 200, 200, hwnd,
10195                           NULL, NULL, 0);
10196     assert(hchild);
10197
10198     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10199     flush_events();
10200     flush_sequence();
10201
10202     tme.cbSize = 0;
10203     tme.dwFlags = TME_QUERY;
10204     tme.hwndTrack = (HWND)0xdeadbeef;
10205     tme.dwHoverTime = 0xdeadbeef;
10206     SetLastError(0xdeadbeef);
10207     ret = pTrackMouseEvent(&tme);
10208     ok(!ret, "TrackMouseEvent should fail\n");
10209     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10210        "not expected error %u\n", GetLastError());
10211
10212     tme.cbSize = sizeof(tme);
10213     tme.dwFlags = TME_HOVER;
10214     tme.hwndTrack = (HWND)0xdeadbeef;
10215     tme.dwHoverTime = 0xdeadbeef;
10216     SetLastError(0xdeadbeef);
10217     ret = pTrackMouseEvent(&tme);
10218     ok(!ret, "TrackMouseEvent should fail\n");
10219     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10220        "not expected error %u\n", GetLastError());
10221
10222     tme.cbSize = sizeof(tme);
10223     tme.dwFlags = TME_HOVER | TME_CANCEL;
10224     tme.hwndTrack = (HWND)0xdeadbeef;
10225     tme.dwHoverTime = 0xdeadbeef;
10226     SetLastError(0xdeadbeef);
10227     ret = pTrackMouseEvent(&tme);
10228     ok(!ret, "TrackMouseEvent should fail\n");
10229     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10230        "not expected error %u\n", GetLastError());
10231
10232     GetWindowRect(hwnd, &rc_parent);
10233     GetWindowRect(hchild, &rc_child);
10234     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10235
10236     /* Process messages so that the system updates its internal current
10237      * window and hittest, otherwise TrackMouseEvent calls don't have any
10238      * effect.
10239      */
10240     flush_events();
10241     flush_sequence();
10242
10243     track_query(0, NULL, 0);
10244     track_hover(hchild, 0);
10245     track_query(0, NULL, 0);
10246
10247     flush_events();
10248     flush_sequence();
10249
10250     track_hover(hwnd, 0);
10251     tme.cbSize = sizeof(tme);
10252     tme.dwFlags = TME_QUERY;
10253     tme.hwndTrack = (HWND)0xdeadbeef;
10254     tme.dwHoverTime = 0xdeadbeef;
10255     SetLastError(0xdeadbeef);
10256     ret = pTrackMouseEvent(&tme);
10257     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10258     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10259     if (!tme.dwFlags)
10260     {
10261         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10262         DestroyWindow( hwnd );
10263         return;
10264     }
10265     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10266     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10267     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10268        tme.dwHoverTime, default_hover_time);
10269
10270     pump_msg_loop_timeout(default_hover_time, FALSE);
10271     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10272
10273     track_query(0, NULL, 0);
10274
10275     track_hover(hwnd, HOVER_DEFAULT);
10276     track_query(TME_HOVER, hwnd, default_hover_time);
10277
10278     Sleep(default_hover_time / 2);
10279     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10280     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10281
10282     track_query(TME_HOVER, hwnd, default_hover_time);
10283
10284     pump_msg_loop_timeout(default_hover_time, FALSE);
10285     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10286
10287     track_query(0, NULL, 0);
10288
10289     track_hover(hwnd, HOVER_DEFAULT);
10290     track_query(TME_HOVER, hwnd, default_hover_time);
10291
10292     pump_msg_loop_timeout(default_hover_time, TRUE);
10293     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10294
10295     track_query(0, NULL, 0);
10296
10297     track_hover(hwnd, HOVER_DEFAULT);
10298     track_query(TME_HOVER, hwnd, default_hover_time);
10299     track_hover_cancel(hwnd);
10300
10301     DestroyWindow(hwnd);
10302
10303 #undef track_hover
10304 #undef track_query
10305 #undef track_hover_cancel
10306 }
10307
10308
10309 static const struct message WmSetWindowRgn[] = {
10310     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10311     { WM_NCCALCSIZE, sent|wparam, 1 },
10312     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10313     { WM_GETTEXT, sent|defwinproc|optional },
10314     { WM_ERASEBKGND, sent|optional },
10315     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10316     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10317     { 0 }
10318 };
10319
10320 static const struct message WmSetWindowRgn_no_redraw[] = {
10321     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10322     { WM_NCCALCSIZE, sent|wparam, 1 },
10323     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10324     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10325     { 0 }
10326 };
10327
10328 static const struct message WmSetWindowRgn_clear[] = {
10329     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10330     { WM_NCCALCSIZE, sent|wparam, 1 },
10331     { WM_NCPAINT, sent|optional },
10332     { WM_GETTEXT, sent|defwinproc|optional },
10333     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10334     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10335     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10336     { WM_NCPAINT, sent|optional },
10337     { WM_GETTEXT, sent|defwinproc|optional },
10338     { WM_ERASEBKGND, sent|optional },
10339     { WM_WINDOWPOSCHANGING, sent|optional },
10340     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10341     { WM_NCPAINT, sent|optional },
10342     { WM_GETTEXT, sent|defwinproc|optional },
10343     { WM_ERASEBKGND, sent|optional },
10344     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10345     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10346     { WM_NCPAINT, sent|optional },
10347     { WM_GETTEXT, sent|defwinproc|optional },
10348     { WM_ERASEBKGND, sent|optional },
10349     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10350     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10351     { 0 }
10352 };
10353
10354 static void test_SetWindowRgn(void)
10355 {
10356     HRGN hrgn;
10357     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10358                                 100, 100, 200, 200, 0, 0, 0, NULL);
10359     ok( hwnd != 0, "Failed to create overlapped window\n" );
10360
10361     ShowWindow( hwnd, SW_SHOW );
10362     UpdateWindow( hwnd );
10363     flush_events();
10364     flush_sequence();
10365
10366     trace("testing SetWindowRgn\n");
10367     hrgn = CreateRectRgn( 0, 0, 150, 150 );
10368     SetWindowRgn( hwnd, hrgn, TRUE );
10369     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10370
10371     hrgn = CreateRectRgn( 30, 30, 160, 160 );
10372     SetWindowRgn( hwnd, hrgn, FALSE );
10373     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10374
10375     hrgn = CreateRectRgn( 0, 0, 180, 180 );
10376     SetWindowRgn( hwnd, hrgn, TRUE );
10377     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10378
10379     SetWindowRgn( hwnd, 0, TRUE );
10380     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10381
10382     DestroyWindow( hwnd );
10383 }
10384
10385 /*************************** ShowWindow() test ******************************/
10386 static const struct message WmShowNormal[] = {
10387     { WM_SHOWWINDOW, sent|wparam, 1 },
10388     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10389     { HCBT_ACTIVATE, hook },
10390     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10391     { HCBT_SETFOCUS, hook },
10392     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10393     { 0 }
10394 };
10395 static const struct message WmShow[] = {
10396     { WM_SHOWWINDOW, sent|wparam, 1 },
10397     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10398     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10399     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10400     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10401     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10402     { 0 }
10403 };
10404 static const struct message WmShowNoActivate_1[] = {
10405     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10406     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10407     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10408     { WM_MOVE, sent|defwinproc|optional },
10409     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10410     { 0 }
10411 };
10412 static const struct message WmShowNoActivate_2[] = {
10413     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10414     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10415     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10416     { WM_MOVE, sent|defwinproc },
10417     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10418     { HCBT_SETFOCUS, hook|optional },
10419     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10420     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10421     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10422     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10423     { 0 }
10424 };
10425 static const struct message WmShowNA_1[] = {
10426     { WM_SHOWWINDOW, sent|wparam, 1 },
10427     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10428     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10429     { 0 }
10430 };
10431 static const struct message WmShowNA_2[] = {
10432     { WM_SHOWWINDOW, sent|wparam, 1 },
10433     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10434     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10435     { 0 }
10436 };
10437 static const struct message WmRestore_1[] = {
10438     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10439     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10440     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10441     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10442     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10443     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10444     { WM_MOVE, sent|defwinproc },
10445     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10446     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10447     { 0 }
10448 };
10449 static const struct message WmRestore_2[] = {
10450     { WM_SHOWWINDOW, sent|wparam, 1 },
10451     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10452     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10453     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10454     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10455     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10456     { 0 }
10457 };
10458 static const struct message WmRestore_3[] = {
10459     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10460     { WM_GETMINMAXINFO, sent },
10461     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10462     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10463     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10464     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10465     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10466     { WM_MOVE, sent|defwinproc },
10467     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10468     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10469     { 0 }
10470 };
10471 static const struct message WmRestore_4[] = {
10472     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10473     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10474     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10475     { WM_MOVE, sent|defwinproc|optional },
10476     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10477     { 0 }
10478 };
10479 static const struct message WmRestore_5[] = {
10480     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10481     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10482     { HCBT_ACTIVATE, hook|optional },
10483     { HCBT_SETFOCUS, hook|optional },
10484     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10485     { WM_MOVE, sent|defwinproc|optional },
10486     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10487     { 0 }
10488 };
10489 static const struct message WmHide_1[] = {
10490     { WM_SHOWWINDOW, sent|wparam, 0 },
10491     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10493     { HCBT_ACTIVATE, hook|optional },
10494     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10495     { 0 }
10496 };
10497 static const struct message WmHide_2[] = {
10498     { WM_SHOWWINDOW, sent|wparam, 0 },
10499     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10500     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10501     { HCBT_ACTIVATE, hook|optional },
10502     { 0 }
10503 };
10504 static const struct message WmHide_3[] = {
10505     { WM_SHOWWINDOW, sent|wparam, 0 },
10506     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10507     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10508     { HCBT_SETFOCUS, hook|optional },
10509     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10510     { 0 }
10511 };
10512 static const struct message WmShowMinimized_1[] = {
10513     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10514     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10515     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10516     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10517     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10518     { WM_MOVE, sent|defwinproc },
10519     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10520     { 0 }
10521 };
10522 static const struct message WmMinimize_1[] = {
10523     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10524     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10525     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10526     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10527     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10528     { WM_MOVE, sent|defwinproc },
10529     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10530     { 0 }
10531 };
10532 static const struct message WmMinimize_2[] = {
10533     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10534     { HCBT_SETFOCUS, hook|optional },
10535     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10536     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10537     { WM_MOVE, sent|defwinproc },
10538     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10539     { 0 }
10540 };
10541 static const struct message WmMinimize_3[] = {
10542     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10543     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10544     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10545     { WM_MOVE, sent|defwinproc },
10546     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10547     { 0 }
10548 };
10549 static const struct message WmShowMinNoActivate[] = {
10550     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10551     { WM_WINDOWPOSCHANGING, sent },
10552     { WM_WINDOWPOSCHANGED, sent },
10553     { WM_MOVE, sent|defwinproc|optional },
10554     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10555     { 0 }
10556 };
10557 static const struct message WmMinMax_1[] = {
10558     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10559     { 0 }
10560 };
10561 static const struct message WmMinMax_2[] = {
10562     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10563     { WM_GETMINMAXINFO, sent|optional },
10564     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10565     { HCBT_ACTIVATE, hook|optional },
10566     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10567     { HCBT_SETFOCUS, hook|optional },
10568     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10569     { WM_MOVE, sent|defwinproc|optional },
10570     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10571     { HCBT_SETFOCUS, hook|optional },
10572     { 0 }
10573 };
10574 static const struct message WmMinMax_3[] = {
10575     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10576     { HCBT_SETFOCUS, hook|optional },
10577     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10578     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10579     { WM_MOVE, sent|defwinproc|optional },
10580     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10581     { 0 }
10582 };
10583 static const struct message WmMinMax_4[] = {
10584     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10585     { 0 }
10586 };
10587 static const struct message WmShowMaximized_1[] = {
10588     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10589     { WM_GETMINMAXINFO, sent },
10590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10591     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10592     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10593     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10594     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10595     { WM_MOVE, sent|defwinproc },
10596     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10597     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10598     { 0 }
10599 };
10600 static const struct message WmShowMaximized_2[] = {
10601     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10602     { WM_GETMINMAXINFO, sent },
10603     { WM_WINDOWPOSCHANGING, sent|optional },
10604     { HCBT_ACTIVATE, hook|optional },
10605     { WM_WINDOWPOSCHANGED, sent|optional },
10606     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10607     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10608     { WM_WINDOWPOSCHANGING, sent|optional },
10609     { HCBT_SETFOCUS, hook|optional },
10610     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10611     { WM_MOVE, sent|defwinproc },
10612     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10613     { HCBT_SETFOCUS, hook|optional },
10614     { 0 }
10615 };
10616 static const struct message WmShowMaximized_3[] = {
10617     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10618     { WM_GETMINMAXINFO, sent|optional },
10619     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10620     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10621     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10622     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10623     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10624     { WM_MOVE, sent|defwinproc|optional },
10625     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10626     { 0 }
10627 };
10628
10629 static void test_ShowWindow(void)
10630 {
10631     /* ShowWindow commands in random order */
10632     static const struct
10633     {
10634         INT cmd; /* ShowWindow command */
10635         LPARAM ret; /* ShowWindow return value */
10636         DWORD style; /* window style after the command */
10637         const struct message *msg; /* message sequence the command produces */
10638         INT wp_cmd, wp_flags; /* window placement after the command */
10639         POINT wp_min, wp_max; /* window placement after the command */
10640         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10641     } sw[] =
10642     {
10643 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
10644            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10645 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
10646            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10647 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1,
10648            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10649 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10650            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10651 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
10652            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10653 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
10654            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10655 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
10656            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10657 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10658            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10659 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
10660            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10661 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10662            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10663 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
10664            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10665 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
10666            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10667 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
10668            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10669 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10670            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10671 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
10672            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10673 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10674            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10675 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
10676            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10677 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10678            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10679 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10680            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10681 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10682            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10683 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10684            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10685 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
10686            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, TRUE },
10687 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
10688            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10689 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10690            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10691 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10692            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10693 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
10694            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10695 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
10696            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10697 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10698            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10699 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10700            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10701 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
10702            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10703 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10704            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10705 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
10706            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10707 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10708            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10709 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
10710            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10711 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
10712            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10713 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10714            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10715 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
10716            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10717 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10718            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10719 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10720            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10721 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
10722            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10723 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10724            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10725 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
10726            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10727 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10728            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10729 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10730            SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10731 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10732            SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10733 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
10734            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10735 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
10736            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10737 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
10738            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10739 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
10740            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10741 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10742            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10743 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10744            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10745 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
10746            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10747 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10748            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-1,-1}, {-1,-1}, FALSE },
10749 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
10750            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10751 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10752            SW_SHOWMINIMIZED, 0, {-1,-1}, {-1,-1}, FALSE },
10753 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
10754            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10755 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10756            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE }
10757     };
10758     HWND hwnd;
10759     DWORD style;
10760     LPARAM ret;
10761     INT i;
10762     WINDOWPLACEMENT wp;
10763     RECT win_rc, work_rc = {0, 0, 0, 0};
10764
10765 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10766     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10767                           120, 120, 90, 90,
10768                           0, 0, 0, NULL);
10769     assert(hwnd);
10770
10771     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10772     ok(style == 0, "expected style 0, got %08x\n", style);
10773
10774     flush_events();
10775     flush_sequence();
10776
10777     if (pGetMonitorInfoA && pMonitorFromPoint)
10778     {
10779         HMONITOR hmon;
10780         MONITORINFO mi;
10781         POINT pt = {0, 0};
10782
10783         SetLastError(0xdeadbeef);
10784         hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
10785         ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
10786
10787         mi.cbSize = sizeof(mi);
10788         SetLastError(0xdeadbeef);
10789         ret = pGetMonitorInfoA(hmon, &mi);
10790         ok(ret, "GetMonitorInfo error %u\n", GetLastError());
10791         trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
10792             mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
10793             mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
10794         work_rc = mi.rcWork;
10795     }
10796
10797     GetWindowRect(hwnd, &win_rc);
10798     OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
10799
10800     wp.length = sizeof(wp);
10801     SetLastError(0xdeadbeaf);
10802     ret = GetWindowPlacement(hwnd, &wp);
10803     ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10804     ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
10805     ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
10806     ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
10807        "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10808     ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
10809        "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10810     if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
10811     ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10812        "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10813         win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10814         wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10815         wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10816     else
10817     ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10818        "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10819         win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10820         wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10821         wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10822
10823     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10824     {
10825         static const char * const sw_cmd_name[13] =
10826         {
10827             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10828             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10829             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10830             "SW_NORMALNA" /* 0xCC */
10831         };
10832         char comment[64];
10833         INT idx; /* index into the above array of names */
10834
10835         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10836
10837         style = GetWindowLong(hwnd, GWL_STYLE);
10838         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10839         ret = ShowWindow(hwnd, sw[i].cmd);
10840         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10841         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10842         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10843
10844         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10845         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10846
10847         wp.length = sizeof(wp);
10848         SetLastError(0xdeadbeaf);
10849         ret = GetWindowPlacement(hwnd, &wp);
10850         ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10851         ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
10852         ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
10853 if (0) /* FIXME: Wine behaves completely different here */
10854 {
10855         /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
10856         if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
10857             (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
10858         todo_wine
10859         ok((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
10860            (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
10861            "expected -32000,-32000 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10862         else
10863         ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
10864            "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10865
10866         ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
10867            "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10868         ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10869            "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10870             win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10871             wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10872             wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10873 }
10874         flush_events();
10875         flush_sequence();
10876     }
10877
10878     DestroyWindow(hwnd);
10879 }
10880
10881 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10882 {
10883     struct recvd_message msg;
10884
10885     if (ignore_message( message )) return 0;
10886
10887     msg.hwnd = hwnd;
10888     msg.message = message;
10889     msg.flags = sent|wparam|lparam;
10890     msg.wParam = wParam;
10891     msg.lParam = lParam;
10892     msg.descr = "dialog";
10893     add_message(&msg);
10894
10895     /* calling DefDlgProc leads to a recursion under XP */
10896
10897     switch (message)
10898     {
10899     case WM_INITDIALOG:
10900     case WM_GETDLGCODE:
10901         return 0;
10902     }
10903     return 1;
10904 }
10905
10906 static const struct message WmDefDlgSetFocus_1[] = {
10907     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10908     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10909     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10910     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10911     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10912     { HCBT_SETFOCUS, hook },
10913     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10914     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10915     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10916     { WM_SETFOCUS, sent|wparam, 0 },
10917     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10918     { WM_CTLCOLOREDIT, sent },
10919     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10920     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10921     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10922     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10923     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10924     { 0 }
10925 };
10926 static const struct message WmDefDlgSetFocus_2[] = {
10927     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10928     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10929     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10930     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10931     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10932     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10933     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10934     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10935     { 0 }
10936 };
10937 /* Creation of a dialog */
10938 static const struct message WmCreateDialogParamSeq_1[] = {
10939     { HCBT_CREATEWND, hook },
10940     { WM_NCCREATE, sent },
10941     { WM_NCCALCSIZE, sent|wparam, 0 },
10942     { WM_CREATE, sent },
10943     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10944     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10945     { WM_MOVE, sent },
10946     { WM_SETFONT, sent },
10947     { WM_INITDIALOG, sent },
10948     { WM_CHANGEUISTATE, sent|optional },
10949     { 0 }
10950 };
10951 /* Creation of a dialog */
10952 static const struct message WmCreateDialogParamSeq_2[] = {
10953     { HCBT_CREATEWND, hook },
10954     { WM_NCCREATE, sent },
10955     { WM_NCCALCSIZE, sent|wparam, 0 },
10956     { WM_CREATE, sent },
10957     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10958     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10959     { WM_MOVE, sent },
10960     { WM_CHANGEUISTATE, sent|optional },
10961     { 0 }
10962 };
10963
10964 static void test_dialog_messages(void)
10965 {
10966     WNDCLASS cls;
10967     HWND hdlg, hedit1, hedit2, hfocus;
10968     LRESULT ret;
10969
10970 #define set_selection(hctl, start, end) \
10971     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10972     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10973
10974 #define check_selection(hctl, start, end) \
10975     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10976     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10977
10978     subclass_edit();
10979
10980     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10981                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10982                           0, 0, 100, 100, 0, 0, 0, NULL);
10983     ok(hdlg != 0, "Failed to create custom dialog window\n");
10984
10985     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10986                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10987                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10988     ok(hedit1 != 0, "Failed to create edit control\n");
10989     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10990                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10991                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10992     ok(hedit2 != 0, "Failed to create edit control\n");
10993
10994     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10995     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10996
10997     hfocus = GetFocus();
10998     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10999
11000     SetFocus(hedit2);
11001     hfocus = GetFocus();
11002     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11003
11004     check_selection(hedit1, 0, 0);
11005     check_selection(hedit2, 0, 0);
11006
11007     set_selection(hedit2, 0, -1);
11008     check_selection(hedit2, 0, 3);
11009
11010     SetFocus(0);
11011     hfocus = GetFocus();
11012     ok(hfocus == 0, "wrong focus %p\n", hfocus);
11013
11014     flush_sequence();
11015     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11016     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11017     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11018
11019     hfocus = GetFocus();
11020     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11021
11022     check_selection(hedit1, 0, 5);
11023     check_selection(hedit2, 0, 3);
11024
11025     flush_sequence();
11026     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11027     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11028     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11029
11030     hfocus = GetFocus();
11031     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11032
11033     check_selection(hedit1, 0, 5);
11034     check_selection(hedit2, 0, 3);
11035
11036     EndDialog(hdlg, 0);
11037     DestroyWindow(hedit1);
11038     DestroyWindow(hedit2);
11039     DestroyWindow(hdlg);
11040     flush_sequence();
11041
11042 #undef set_selection
11043 #undef check_selection
11044
11045     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11046     cls.lpszClassName = "MyDialogClass";
11047     cls.hInstance = GetModuleHandle(0);
11048     /* need a cast since a dlgproc is used as a wndproc */
11049     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
11050     if (!RegisterClass(&cls)) assert(0);
11051
11052     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11053     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11054     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11055     EndDialog(hdlg, 0);
11056     DestroyWindow(hdlg);
11057     flush_sequence();
11058
11059     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11060     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11061     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11062     EndDialog(hdlg, 0);
11063     DestroyWindow(hdlg);
11064     flush_sequence();
11065
11066     UnregisterClass(cls.lpszClassName, cls.hInstance);
11067 }
11068
11069 static void test_nullCallback(void)
11070 {
11071     HWND hwnd;
11072
11073     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11074                            100, 100, 200, 200, 0, 0, 0, NULL);
11075     ok (hwnd != 0, "Failed to create overlapped window\n");
11076
11077     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11078     flush_events();
11079     DestroyWindow(hwnd);
11080 }
11081
11082 /* SetActiveWindow( 0 ) hwnd visible */
11083 static const struct message SetActiveWindowSeq0[] =
11084 {
11085     { HCBT_ACTIVATE, hook|optional },
11086     { WM_NCACTIVATE, sent|wparam, 0 },
11087     { WM_GETTEXT, sent|defwinproc|optional },
11088     { WM_ACTIVATE, sent|wparam, 0 },
11089     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11090     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11091     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11092     { WM_KILLFOCUS, sent|optional },
11093     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11094     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11095     { WM_NCACTIVATE, sent|wparam|optional, 1 },
11096     { WM_GETTEXT, sent|defwinproc|optional },
11097     { WM_ACTIVATE, sent|wparam|optional, 1 },
11098     { HCBT_SETFOCUS, hook|optional },
11099     { WM_KILLFOCUS, sent|defwinproc|optional },
11100     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11101     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11102     { WM_IME_SETCONTEXT, sent|optional },
11103     { WM_IME_SETCONTEXT, sent|optional },
11104     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11105     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11106     { WM_SETFOCUS, sent|defwinproc|optional },
11107     { WM_GETTEXT, sent|optional },
11108     { 0 }
11109 };
11110 /* SetActiveWindow( hwnd ) hwnd visible */
11111 static const struct message SetActiveWindowSeq1[] =
11112 {
11113     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11114     { 0 }
11115 };
11116 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11117 static const struct message SetActiveWindowSeq2[] =
11118 {
11119     { HCBT_ACTIVATE, hook },
11120     { WM_NCACTIVATE, sent|wparam, 0 },
11121     { WM_GETTEXT, sent|defwinproc|optional },
11122     { WM_ACTIVATE, sent|wparam, 0 },
11123     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11124     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11125     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11126     { WM_NCPAINT, sent|optional },
11127     { WM_GETTEXT, sent|defwinproc|optional },
11128     { WM_ERASEBKGND, sent|optional },
11129     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11130     { WM_NCACTIVATE, sent|wparam, 1 },
11131     { WM_GETTEXT, sent|defwinproc|optional },
11132     { WM_ACTIVATE, sent|wparam, 1 },
11133     { HCBT_SETFOCUS, hook },
11134     { WM_KILLFOCUS, sent|defwinproc },
11135     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11136     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11137     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11138     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11139     { WM_SETFOCUS, sent|defwinproc },
11140     { WM_GETTEXT, sent|optional },
11141     { 0 }
11142 };
11143
11144 /* SetActiveWindow( hwnd ) hwnd not visible */
11145 static const struct message SetActiveWindowSeq3[] =
11146 {
11147     { HCBT_ACTIVATE, hook },
11148     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11149     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11150     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11151     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11152     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11153     { WM_ACTIVATEAPP, sent|wparam, 1 },
11154     { WM_ACTIVATEAPP, sent|wparam, 1 },
11155     { WM_NCACTIVATE, sent|wparam, 1 },
11156     { WM_ACTIVATE, sent|wparam, 1 },
11157     { HCBT_SETFOCUS, hook },
11158     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11159     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11160     { WM_SETFOCUS, sent|defwinproc },
11161     { 0 }
11162 };
11163 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11164 static const struct message SetActiveWindowSeq4[] =
11165 {
11166     { HCBT_ACTIVATE, hook },
11167     { WM_NCACTIVATE, sent|wparam, 0 },
11168     { WM_GETTEXT, sent|defwinproc|optional },
11169     { WM_ACTIVATE, sent|wparam, 0 },
11170     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11171     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11172     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11173     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11174     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11175     { WM_NCACTIVATE, sent|wparam, 1 },
11176     { WM_GETTEXT, sent|defwinproc|optional },
11177     { WM_ACTIVATE, sent|wparam, 1 },
11178     { HCBT_SETFOCUS, hook },
11179     { WM_KILLFOCUS, sent|defwinproc },
11180     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11181     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11182     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11183     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11184     { WM_SETFOCUS, sent|defwinproc },
11185     { 0 }
11186 };
11187
11188
11189 static void test_SetActiveWindow(void)
11190 {
11191     HWND hwnd, popup, ret;
11192
11193     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11194                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11195                            100, 100, 200, 200, 0, 0, 0, NULL);
11196
11197     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11198                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11199                            100, 100, 200, 200, hwnd, 0, 0, NULL);
11200
11201     ok(hwnd != 0, "Failed to create overlapped window\n");
11202     ok(popup != 0, "Failed to create popup window\n");
11203     SetForegroundWindow( popup );
11204     flush_sequence();
11205
11206     trace("SetActiveWindow(0)\n");
11207     ret = SetActiveWindow(0);
11208     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11209     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11210     flush_sequence();
11211
11212     trace("SetActiveWindow(hwnd), hwnd visible\n");
11213     ret = SetActiveWindow(hwnd);
11214     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11215     flush_sequence();
11216
11217     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11218     ret = SetActiveWindow(popup);
11219     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11220     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11221     flush_sequence();
11222
11223     ShowWindow(hwnd, SW_HIDE);
11224     ShowWindow(popup, SW_HIDE);
11225     flush_sequence();
11226
11227     trace("SetActiveWindow(hwnd), hwnd not visible\n");
11228     ret = SetActiveWindow(hwnd);
11229     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11230     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11231     flush_sequence();
11232
11233     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11234     ret = SetActiveWindow(popup);
11235     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11236     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11237     flush_sequence();
11238
11239     trace("done\n");
11240
11241     DestroyWindow(hwnd);
11242 }
11243
11244 static const struct message SetForegroundWindowSeq[] =
11245 {
11246     { WM_NCACTIVATE, sent|wparam, 0 },
11247     { WM_GETTEXT, sent|defwinproc|optional },
11248     { WM_ACTIVATE, sent|wparam, 0 },
11249     { WM_ACTIVATEAPP, sent|wparam, 0 },
11250     { WM_KILLFOCUS, sent },
11251     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11252     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11253     { 0 }
11254 };
11255
11256 static void test_SetForegroundWindow(void)
11257 {
11258     HWND hwnd;
11259
11260     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11261                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11262                            100, 100, 200, 200, 0, 0, 0, NULL);
11263     ok (hwnd != 0, "Failed to create overlapped window\n");
11264     SetForegroundWindow( hwnd );
11265     flush_sequence();
11266
11267     trace("SetForegroundWindow( 0 )\n");
11268     SetForegroundWindow( 0 );
11269     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11270     trace("SetForegroundWindow( GetDesktopWindow() )\n");
11271     SetForegroundWindow( GetDesktopWindow() );
11272     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11273                                         "foreground top level window", FALSE);
11274     trace("done\n");
11275
11276     DestroyWindow(hwnd);
11277 }
11278
11279 static void test_dbcs_wm_char(void)
11280 {
11281     BYTE dbch[2];
11282     WCHAR wch, bad_wch;
11283     HWND hwnd, hwnd2;
11284     MSG msg;
11285     DWORD time;
11286     POINT pt;
11287     DWORD_PTR res;
11288     CPINFOEXA cpinfo;
11289     UINT i, j, k;
11290     struct message wmCharSeq[2];
11291
11292     if (!pGetCPInfoExA)
11293     {
11294         win_skip("GetCPInfoExA is not available\n");
11295         return;
11296     }
11297
11298     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11299     if (cpinfo.MaxCharSize != 2)
11300     {
11301         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11302         return;
11303     }
11304
11305     dbch[0] = dbch[1] = 0;
11306     wch = 0;
11307     bad_wch = cpinfo.UnicodeDefaultChar;
11308     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11309         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11310             for (k = 128; k <= 255; k++)
11311             {
11312                 char str[2];
11313                 WCHAR wstr[2];
11314                 str[0] = j;
11315                 str[1] = k;
11316                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11317                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11318                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
11319                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11320                 {
11321                     dbch[0] = j;
11322                     dbch[1] = k;
11323                     wch = wstr[0];
11324                     break;
11325                 }
11326             }
11327
11328     if (!wch)
11329     {
11330         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11331         return;
11332     }
11333     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11334            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11335
11336     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11337                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11338     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11339                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11340     ok (hwnd != 0, "Failed to create overlapped window\n");
11341     ok (hwnd2 != 0, "Failed to create overlapped window\n");
11342     flush_sequence();
11343
11344     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11345     wmCharSeq[0].message = WM_CHAR;
11346     wmCharSeq[0].flags = sent|wparam;
11347     wmCharSeq[0].wParam = wch;
11348
11349     /* posted message */
11350     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11351     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11352     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11353     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11354     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11355     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11356     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11357
11358     /* posted thread message */
11359     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11360     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11361     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11362     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11363     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11364     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11365     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11366
11367     /* sent message */
11368     flush_sequence();
11369     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11370     ok_sequence( WmEmptySeq, "no messages", FALSE );
11371     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11372     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11373     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11374
11375     /* sent message with timeout */
11376     flush_sequence();
11377     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11378     ok_sequence( WmEmptySeq, "no messages", FALSE );
11379     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11380     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11381     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11382
11383     /* sent message with timeout and callback */
11384     flush_sequence();
11385     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11386     ok_sequence( WmEmptySeq, "no messages", FALSE );
11387     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11388     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11389     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11390
11391     /* sent message with callback */
11392     flush_sequence();
11393     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11394     ok_sequence( WmEmptySeq, "no messages", FALSE );
11395     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11396     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11397     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11398
11399     /* direct window proc call */
11400     flush_sequence();
11401     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11402     ok_sequence( WmEmptySeq, "no messages", FALSE );
11403     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11404     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11405
11406     /* dispatch message */
11407     msg.hwnd = hwnd;
11408     msg.message = WM_CHAR;
11409     msg.wParam = dbch[0];
11410     msg.lParam = 0;
11411     DispatchMessageA( &msg );
11412     ok_sequence( WmEmptySeq, "no messages", FALSE );
11413     msg.wParam = dbch[1];
11414     DispatchMessageA( &msg );
11415     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11416
11417     /* window handle is irrelevant */
11418     flush_sequence();
11419     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11420     ok_sequence( WmEmptySeq, "no messages", FALSE );
11421     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11422     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11423     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11424
11425     /* interleaved post and send */
11426     flush_sequence();
11427     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11428     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11429     ok_sequence( WmEmptySeq, "no messages", FALSE );
11430     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11431     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11432     ok_sequence( WmEmptySeq, "no messages", FALSE );
11433     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11434     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11435     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11436     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11437     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11438     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11439     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11440
11441     /* interleaved sent message and winproc */
11442     flush_sequence();
11443     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11444     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11445     ok_sequence( WmEmptySeq, "no messages", FALSE );
11446     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11447     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11448     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11449     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11450
11451     /* interleaved winproc and dispatch */
11452     msg.hwnd = hwnd;
11453     msg.message = WM_CHAR;
11454     msg.wParam = dbch[0];
11455     msg.lParam = 0;
11456     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11457     DispatchMessageA( &msg );
11458     ok_sequence( WmEmptySeq, "no messages", FALSE );
11459     msg.wParam = dbch[1];
11460     DispatchMessageA( &msg );
11461     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11462     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11463     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11464
11465     /* interleaved sends */
11466     flush_sequence();
11467     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11468     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11469     ok_sequence( WmEmptySeq, "no messages", FALSE );
11470     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11471     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11472     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11473     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11474
11475     /* dbcs WM_CHAR */
11476     flush_sequence();
11477     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11478     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11479     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11480
11481     /* other char messages are not magic */
11482     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11483     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11484     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11485     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11486     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11487     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11488     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11489     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11490     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11491     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11492
11493     /* test retrieving messages */
11494
11495     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11496     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11497     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11498     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11499     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11500     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11501     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11502     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11503     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11504     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11505
11506     /* message filters */
11507     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11508     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11509     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11510     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11511     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11512     /* message id is filtered, hwnd is not */
11513     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11514     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11515     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11516     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11517     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11518     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11519
11520     /* mixing GetMessage and PostMessage */
11521     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11522     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11523     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11524     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11525     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11526     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11527     time = msg.time;
11528     pt = msg.pt;
11529     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11530     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11531     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11532     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11533     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11534     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11535     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11536     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 );
11537     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11538
11539     /* without PM_REMOVE */
11540     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11541     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11542     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11543     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11544     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11545     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11546     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11547     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11548     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11549     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11550     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11551     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11552     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11553     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11554     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11555     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11556     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11557     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11558
11559     DestroyWindow(hwnd);
11560 }
11561
11562 #define ID_LISTBOX 0x000f
11563
11564 static const struct message wm_lb_setcursel_0[] =
11565 {
11566     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11567     { WM_CTLCOLORLISTBOX, sent|parent },
11568     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11569     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11570     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11571     { 0 }
11572 };
11573 static const struct message wm_lb_setcursel_1[] =
11574 {
11575     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11576     { WM_CTLCOLORLISTBOX, sent|parent },
11577     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11578     { WM_CTLCOLORLISTBOX, sent|parent },
11579     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11580     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11581     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11582     { 0 }
11583 };
11584 static const struct message wm_lb_setcursel_2[] =
11585 {
11586     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11587     { WM_CTLCOLORLISTBOX, sent|parent },
11588     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11589     { WM_CTLCOLORLISTBOX, sent|parent },
11590     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11591     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11592     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11593     { 0 }
11594 };
11595 static const struct message wm_lb_click_0[] =
11596 {
11597     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11598     { HCBT_SETFOCUS, hook },
11599     { WM_KILLFOCUS, sent|parent },
11600     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11601     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11602     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11603     { WM_SETFOCUS, sent|defwinproc },
11604
11605     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11606     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11607     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11608     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11609     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11610
11611     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11612     { WM_CTLCOLORLISTBOX, sent|parent },
11613     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11614     { WM_CTLCOLORLISTBOX, sent|parent },
11615     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11616     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11617
11618     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11619     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11620
11621     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11622     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11623     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11624     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11625     { 0 }
11626 };
11627 static const struct message wm_lb_deletestring[] =
11628 {
11629     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11630     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11631     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11632     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11633     { 0 }
11634 };
11635 static const struct message wm_lb_deletestring_reset[] =
11636 {
11637     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11638     { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11639     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11640     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11641     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11642     { 0 }
11643 };
11644
11645 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11646
11647 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11648
11649 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11650 {
11651     static LONG defwndproc_counter = 0;
11652     LRESULT ret;
11653     struct recvd_message msg;
11654
11655     /* do not log painting messages */
11656     if (message != WM_PAINT &&
11657         message != WM_NCPAINT &&
11658         message != WM_SYNCPAINT &&
11659         message != WM_ERASEBKGND &&
11660         message != WM_NCHITTEST &&
11661         message != WM_GETTEXT &&
11662         !ignore_message( message ))
11663     {
11664         msg.hwnd = hwnd;
11665         msg.message = message;
11666         msg.flags = sent|wparam|lparam;
11667         if (defwndproc_counter) msg.flags |= defwinproc;
11668         msg.wParam = wp;
11669         msg.lParam = lp;
11670         msg.descr = "listbox";
11671         add_message(&msg);
11672     }
11673
11674     defwndproc_counter++;
11675     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11676     defwndproc_counter--;
11677
11678     return ret;
11679 }
11680
11681 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11682                                int caret_index, int top_index, int line)
11683 {
11684     LRESULT ret;
11685
11686     /* calling an orig proc helps to avoid unnecessary message logging */
11687     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11688     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11689     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11690     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11691     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11692     ok_(__FILE__, line)(ret == caret_index ||
11693                         broken(cur_sel == -1 && caret_index == 0 && ret == -1),  /* nt4 */
11694                         "expected caret index %d, got %ld\n", caret_index, ret);
11695     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11696     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11697 }
11698
11699 static void test_listbox_messages(void)
11700 {
11701     HWND parent, listbox;
11702     LRESULT ret;
11703
11704     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11705                              100, 100, 200, 200, 0, 0, 0, NULL);
11706     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11707                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11708                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11709     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11710
11711     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11712
11713     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11714     ok(ret == 0, "expected 0, got %ld\n", ret);
11715     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11716     ok(ret == 1, "expected 1, got %ld\n", ret);
11717     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11718     ok(ret == 2, "expected 2, got %ld\n", ret);
11719
11720     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11721
11722     flush_sequence();
11723
11724     log_all_parent_messages++;
11725
11726     trace("selecting item 0\n");
11727     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11728     ok(ret == 0, "expected 0, got %ld\n", ret);
11729     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11730     check_lb_state(listbox, 3, 0, 0, 0);
11731     flush_sequence();
11732
11733     trace("selecting item 1\n");
11734     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11735     ok(ret == 1, "expected 1, got %ld\n", ret);
11736     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11737     check_lb_state(listbox, 3, 1, 1, 0);
11738
11739     trace("selecting item 2\n");
11740     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11741     ok(ret == 2, "expected 2, got %ld\n", ret);
11742     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11743     check_lb_state(listbox, 3, 2, 2, 0);
11744
11745     trace("clicking on item 0\n");
11746     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11747     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11748     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11749     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11750     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11751     check_lb_state(listbox, 3, 0, 0, 0);
11752     flush_sequence();
11753
11754     trace("deleting item 0\n");
11755     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11756     ok(ret == 2, "expected 2, got %ld\n", ret);
11757     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11758     check_lb_state(listbox, 2, -1, 0, 0);
11759     flush_sequence();
11760
11761     trace("deleting item 0\n");
11762     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11763     ok(ret == 1, "expected 1, got %ld\n", ret);
11764     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11765     check_lb_state(listbox, 1, -1, 0, 0);
11766     flush_sequence();
11767
11768     trace("deleting item 0\n");
11769     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11770     ok(ret == 0, "expected 0, got %ld\n", ret);
11771     ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11772     check_lb_state(listbox, 0, -1, 0, 0);
11773     flush_sequence();
11774
11775     trace("deleting item 0\n");
11776     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11777     ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11778     check_lb_state(listbox, 0, -1, 0, 0);
11779     flush_sequence();
11780
11781     log_all_parent_messages--;
11782
11783     DestroyWindow(listbox);
11784     DestroyWindow(parent);
11785 }
11786
11787 /*************************** Menu test ******************************/
11788 static const struct message wm_popup_menu_1[] =
11789 {
11790     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11791     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11792     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11793     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11794     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11795     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11796     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11797     { WM_INITMENU, sent|lparam, 0, 0 },
11798     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11799     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11800     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11801     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11802     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11803     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11804     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
11805     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11806     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11807     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11808     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11809     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11810     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11811     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11812     { 0 }
11813 };
11814 static const struct message wm_popup_menu_2[] =
11815 {
11816     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11817     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11818     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11819     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11820     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11821     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11822     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11823     { WM_INITMENU, sent|lparam, 0, 0 },
11824     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11825     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11826     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11827     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11828     { HCBT_CREATEWND, hook },
11829     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11830                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11831     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11832     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11833     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11834     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11835     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11836     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11837     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11838     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11839     { HCBT_DESTROYWND, hook },
11840     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11841     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11842     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11843     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11844     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11845     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11846     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11847     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11848     { 0 }
11849 };
11850 static const struct message wm_popup_menu_3[] =
11851 {
11852     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11853     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11854     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11855     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11856     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11857     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11858     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11859     { WM_INITMENU, sent|lparam, 0, 0 },
11860     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11861     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11862     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11863     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11864     { HCBT_CREATEWND, hook },
11865     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11866                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11867     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11868     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11869     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11870     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11871     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11872     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11873     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11874     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11875     { HCBT_DESTROYWND, hook },
11876     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11877     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11878     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11879     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11880     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11881     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11882     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11883     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11884     { 0 }
11885 };
11886
11887 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11888 {
11889     if (message == WM_ENTERIDLE ||
11890         message == WM_INITMENU ||
11891         message == WM_INITMENUPOPUP ||
11892         message == WM_MENUSELECT ||
11893         message == WM_PARENTNOTIFY ||
11894         message == WM_ENTERMENULOOP ||
11895         message == WM_EXITMENULOOP ||
11896         message == WM_UNINITMENUPOPUP ||
11897         message == WM_KEYDOWN ||
11898         message == WM_KEYUP ||
11899         message == WM_CHAR ||
11900         message == WM_SYSKEYDOWN ||
11901         message == WM_SYSKEYUP ||
11902         message == WM_SYSCHAR ||
11903         message == WM_COMMAND ||
11904         message == WM_MENUCOMMAND)
11905     {
11906         struct recvd_message msg;
11907
11908         msg.hwnd = hwnd;
11909         msg.message = message;
11910         msg.flags = sent|wparam|lparam;
11911         msg.wParam = wp;
11912         msg.lParam = lp;
11913         msg.descr = "parent_menu_proc";
11914         add_message(&msg);
11915     }
11916
11917     return DefWindowProcA(hwnd, message, wp, lp);
11918 }
11919
11920 static void set_menu_style(HMENU hmenu, DWORD style)
11921 {
11922     MENUINFO mi;
11923     BOOL ret;
11924
11925     mi.cbSize = sizeof(mi);
11926     mi.fMask = MIM_STYLE;
11927     mi.dwStyle = style;
11928     SetLastError(0xdeadbeef);
11929     ret = pSetMenuInfo(hmenu, &mi);
11930     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11931 }
11932
11933 static DWORD get_menu_style(HMENU hmenu)
11934 {
11935     MENUINFO mi;
11936     BOOL ret;
11937
11938     mi.cbSize = sizeof(mi);
11939     mi.fMask = MIM_STYLE;
11940     mi.dwStyle = 0;
11941     SetLastError(0xdeadbeef);
11942     ret = pGetMenuInfo(hmenu, &mi);
11943     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11944
11945     return mi.dwStyle;
11946 }
11947
11948 static void test_menu_messages(void)
11949 {
11950     MSG msg;
11951     WNDCLASSA cls;
11952     HMENU hmenu, hmenu_popup;
11953     HWND hwnd;
11954     DWORD style;
11955
11956     if (!pGetMenuInfo || !pSetMenuInfo)
11957     {
11958         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11959         return;
11960     }
11961     cls.style = 0;
11962     cls.lpfnWndProc = parent_menu_proc;
11963     cls.cbClsExtra = 0;
11964     cls.cbWndExtra = 0;
11965     cls.hInstance = GetModuleHandleA(0);
11966     cls.hIcon = 0;
11967     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11968     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11969     cls.lpszMenuName = NULL;
11970     cls.lpszClassName = "TestMenuClass";
11971     UnregisterClass(cls.lpszClassName, cls.hInstance);
11972     if (!RegisterClassA(&cls)) assert(0);
11973
11974     SetLastError(0xdeadbeef);
11975     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11976                            100, 100, 200, 200, 0, 0, 0, NULL);
11977     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11978
11979     SetLastError(0xdeadbeef);
11980     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11981     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11982
11983     SetMenu(hwnd, hmenu);
11984     SetForegroundWindow( hwnd );
11985
11986     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11987     style = get_menu_style(hmenu);
11988     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11989
11990     hmenu_popup = GetSubMenu(hmenu, 0);
11991     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11992     style = get_menu_style(hmenu_popup);
11993     ok(style == 0, "expected 0, got %u\n", style);
11994
11995     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11996     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11997     style = get_menu_style(hmenu_popup);
11998     ok(style == 0, "expected 0, got %u\n", style);
11999
12000     /* Alt+E, Enter */
12001     trace("testing a popup menu command\n");
12002     flush_sequence();
12003     keybd_event(VK_MENU, 0, 0, 0);
12004     keybd_event('E', 0, 0, 0);
12005     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12006     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12007     keybd_event(VK_RETURN, 0, 0, 0);
12008     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12009     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12010     {
12011         TranslateMessage(&msg);
12012         DispatchMessage(&msg);
12013     }
12014     if (!sequence_cnt)  /* we didn't get any message */
12015     {
12016         skip( "queuing key events not supported\n" );
12017         goto done;
12018     }
12019     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12020     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12021     {
12022         win_skip( "menu tracking through VK_MENU not supported\n" );
12023         goto done;
12024     }
12025     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12026
12027     /* Alt+F, Right, Enter */
12028     trace("testing submenu of a popup menu command\n");
12029     flush_sequence();
12030     keybd_event(VK_MENU, 0, 0, 0);
12031     keybd_event('F', 0, 0, 0);
12032     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12033     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12034     keybd_event(VK_RIGHT, 0, 0, 0);
12035     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12036     keybd_event(VK_RETURN, 0, 0, 0);
12037     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12038     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12039     {
12040         TranslateMessage(&msg);
12041         DispatchMessage(&msg);
12042     }
12043     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12044
12045     set_menu_style(hmenu, 0);
12046     style = get_menu_style(hmenu);
12047     ok(style == 0, "expected 0, got %u\n", style);
12048
12049     hmenu_popup = GetSubMenu(hmenu, 0);
12050     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12051     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12052     style = get_menu_style(hmenu_popup);
12053     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12054
12055     hmenu_popup = GetSubMenu(hmenu_popup, 0);
12056     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12057     style = get_menu_style(hmenu_popup);
12058     ok(style == 0, "expected 0, got %u\n", style);
12059
12060     /* Alt+F, Right, Enter */
12061     trace("testing submenu of a popup menu command\n");
12062     flush_sequence();
12063     keybd_event(VK_MENU, 0, 0, 0);
12064     keybd_event('F', 0, 0, 0);
12065     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12066     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12067     keybd_event(VK_RIGHT, 0, 0, 0);
12068     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12069     keybd_event(VK_RETURN, 0, 0, 0);
12070     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12071     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12072     {
12073         TranslateMessage(&msg);
12074         DispatchMessage(&msg);
12075     }
12076     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12077
12078 done:
12079     DestroyWindow(hwnd);
12080     DestroyMenu(hmenu);
12081 }
12082
12083
12084 static void test_paintingloop(void)
12085 {
12086     HWND hwnd;
12087
12088     paint_loop_done = 0;
12089     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12090                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12091                                 100, 100, 100, 100, 0, 0, 0, NULL );
12092     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12093     ShowWindow(hwnd,SW_NORMAL);
12094     SetFocus(hwnd);
12095
12096     while (!paint_loop_done)
12097     {
12098         MSG msg;
12099         if (PeekMessageA(&msg, 0, 0, 0, 1))
12100         {
12101             TranslateMessage(&msg);
12102             DispatchMessage(&msg);
12103         }
12104     }
12105     DestroyWindow(hwnd);
12106 }
12107
12108 static void test_defwinproc(void)
12109 {
12110     HWND hwnd;
12111     MSG msg;
12112     int gotwmquit = FALSE;
12113     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12114     assert(hwnd);
12115     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12116     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12117         if( msg.message == WM_QUIT) gotwmquit = TRUE;
12118         DispatchMessageA( &msg );
12119     }
12120     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
12121     DestroyWindow( hwnd);
12122 }
12123
12124 #define clear_clipboard(hwnd)  clear_clipboard_(__LINE__, (hwnd))
12125 static void clear_clipboard_(int line, HWND hWnd)
12126 {
12127     BOOL succ;
12128     succ = OpenClipboard(hWnd);
12129     ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12130     succ = EmptyClipboard();
12131     ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12132     succ = CloseClipboard();
12133     ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12134 }
12135
12136 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12137 static void expect_HWND_(int line, HWND expected, HWND got)
12138 {
12139     ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12140 }
12141
12142 static WNDPROC pOldViewerProc;
12143
12144 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12145 {
12146     static BOOL recursion_guard;
12147
12148     if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12149     {
12150         recursion_guard = TRUE;
12151         clear_clipboard(hWnd);
12152         recursion_guard = FALSE;
12153     }
12154     return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12155 }
12156
12157 static void test_clipboard_viewers(void)
12158 {
12159     static struct message wm_change_cb_chain[] =
12160     {
12161         { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12162         { 0 }
12163     };
12164     static const struct message wm_clipboard_destroyed[] =
12165     {
12166         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12167         { 0 }
12168     };
12169     static struct message wm_clipboard_changed[] =
12170     {
12171         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12172         { 0 }
12173     };
12174     static struct message wm_clipboard_changed_and_owned[] =
12175     {
12176         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12177         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12178         { 0 }
12179     };
12180
12181     HINSTANCE hInst = GetModuleHandleA(NULL);
12182     HWND hWnd1, hWnd2, hWnd3;
12183     HWND hOrigViewer;
12184     HWND hRet;
12185
12186     hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12187         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12188         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12189         GetDesktopWindow(), NULL, hInst, NULL);
12190     hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12191         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12192         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12193         GetDesktopWindow(), NULL, hInst, NULL);
12194     hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12195         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12196         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12197         GetDesktopWindow(), NULL, hInst, NULL);
12198     trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12199     assert(hWnd1 && hWnd2 && hWnd3);
12200
12201     flush_sequence();
12202
12203     /* Test getting the clipboard viewer and setting the viewer to NULL. */
12204     hOrigViewer = GetClipboardViewer();
12205     hRet = SetClipboardViewer(NULL);
12206     ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12207     expect_HWND(hOrigViewer, hRet);
12208     expect_HWND(NULL, GetClipboardViewer());
12209
12210     /* Test registering hWnd1 as a viewer. */
12211     hRet = SetClipboardViewer(hWnd1);
12212     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12213     ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12214     expect_HWND(NULL, hRet);
12215     expect_HWND(hWnd1, GetClipboardViewer());
12216
12217     /* Test that changing the clipboard actually refreshes the registered viewer. */
12218     clear_clipboard(hWnd1);
12219     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12220     ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12221
12222     /* Again, but with different owner. */
12223     clear_clipboard(hWnd2);
12224     wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12225     ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12226
12227     /* Test re-registering same window. */
12228     hRet = SetClipboardViewer(hWnd1);
12229     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12230     ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12231     expect_HWND(hWnd1, hRet);
12232     expect_HWND(hWnd1, GetClipboardViewer());
12233
12234     /* Test ChangeClipboardChain. */
12235     ChangeClipboardChain(hWnd2, hWnd3);
12236     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12237     wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12238     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12239     expect_HWND(hWnd1, GetClipboardViewer());
12240
12241     ChangeClipboardChain(hWnd2, NULL);
12242     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12243     wm_change_cb_chain[0].lParam = 0;
12244     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12245     expect_HWND(hWnd1, GetClipboardViewer());
12246
12247     ChangeClipboardChain(NULL, hWnd2);
12248     ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12249     expect_HWND(hWnd1, GetClipboardViewer());
12250
12251     /* Actually change clipboard viewer with ChangeClipboardChain. */
12252     ChangeClipboardChain(hWnd1, hWnd2);
12253     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12254     expect_HWND(hWnd2, GetClipboardViewer());
12255
12256     /* Test that no refresh messages are sent when viewer has unregistered. */
12257     clear_clipboard(hWnd2);
12258     ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12259
12260     /* Register hWnd1 again. */
12261     ChangeClipboardChain(hWnd2, hWnd1);
12262     ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12263     expect_HWND(hWnd1, GetClipboardViewer());
12264
12265     /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12266      * changes the clipboard. When this happens, the system shouldn't send
12267      * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12268      */
12269     pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12270     clear_clipboard(hWnd2);
12271     /* The clipboard owner is changed in recursive_viewer_proc: */
12272     wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12273     ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12274
12275     /* Test unregistering. */
12276     ChangeClipboardChain(hWnd1, NULL);
12277     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12278     expect_HWND(NULL, GetClipboardViewer());
12279
12280     clear_clipboard(hWnd1);
12281     ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12282
12283     DestroyWindow(hWnd1);
12284     DestroyWindow(hWnd2);
12285     DestroyWindow(hWnd3);
12286     SetClipboardViewer(hOrigViewer);
12287 }
12288
12289 static void test_PostMessage(void)
12290 {
12291     static const struct
12292     {
12293         HWND hwnd;
12294         BOOL ret;
12295     } data[] =
12296     {
12297         { HWND_TOP /* 0 */, TRUE },
12298         { HWND_BROADCAST, TRUE },
12299         { HWND_BOTTOM, TRUE },
12300         { HWND_TOPMOST, TRUE },
12301         { HWND_NOTOPMOST, FALSE },
12302         { HWND_MESSAGE, FALSE },
12303         { (HWND)0xdeadbeef, FALSE }
12304     };
12305     int i;
12306     HWND hwnd;
12307     BOOL ret;
12308     MSG msg;
12309     static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12310
12311     SetLastError(0xdeadbeef);
12312     hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12313     if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12314     {
12315         win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12316         return;
12317     }
12318     assert(hwnd);
12319
12320     flush_events();
12321
12322     PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12323     PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12324
12325     for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12326     {
12327         memset(&msg, 0xab, sizeof(msg));
12328         ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12329         ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12330         if (data[i].ret)
12331         {
12332             if (data[i].hwnd)
12333                 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12334                    msg.wParam == 0x5678 && msg.lParam == 0x1234,
12335                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12336                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12337             else
12338                 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12339                    msg.wParam == 0x1234 && msg.lParam == 0x5678,
12340                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12341                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12342         }
12343     }
12344
12345     DestroyWindow(hwnd);
12346     flush_events();
12347 }
12348
12349 static const struct
12350 {
12351     DWORD exp, broken;
12352     BOOL todo;
12353 } wait_idle_expect[] =
12354 {
12355 /* 0 */  { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12356          { WAIT_TIMEOUT, 0,            FALSE },
12357          { WAIT_TIMEOUT, 0,            FALSE },
12358          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12359          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12360 /* 5 */  { WAIT_TIMEOUT, 0,            FALSE },
12361          { WAIT_TIMEOUT, 0,            FALSE },
12362          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12363          { 0,            0,            FALSE },
12364          { 0,            0,            FALSE },
12365 /* 10 */ { 0,            0,            FALSE },
12366          { 0,            0,            FALSE },
12367          { 0,            WAIT_TIMEOUT, FALSE },
12368          { 0,            0,            FALSE },
12369          { 0,            0,            FALSE },
12370 /* 15 */ { 0,            0,            FALSE },
12371          { WAIT_TIMEOUT, 0,            FALSE },
12372          { WAIT_TIMEOUT, 0,            FALSE },
12373          { WAIT_TIMEOUT, 0,            FALSE },
12374          { WAIT_TIMEOUT, 0,            FALSE },
12375 /* 20 */ { WAIT_TIMEOUT, 0,            FALSE },
12376 };
12377
12378 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12379 {
12380     MSG msg;
12381
12382     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12383     Sleep( 200 );
12384     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12385     return 0;
12386 }
12387
12388 static void do_wait_idle_child( int arg )
12389 {
12390     WNDCLASS cls;
12391     MSG msg;
12392     HWND hwnd = 0;
12393     HANDLE thread;
12394     DWORD id;
12395     HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12396     HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12397
12398     memset( &cls, 0, sizeof(cls) );
12399     cls.lpfnWndProc   = DefWindowProc;
12400     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12401     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12402     cls.lpszClassName = "TestClass";
12403     RegisterClass( &cls );
12404
12405     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* create the msg queue */
12406
12407     ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12408     ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12409
12410     switch (arg)
12411     {
12412     case 0:
12413         SetEvent( start_event );
12414         break;
12415     case 1:
12416         SetEvent( start_event );
12417         Sleep( 200 );
12418         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12419         break;
12420     case 2:
12421         SetEvent( start_event );
12422         Sleep( 200 );
12423         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12424         PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12425         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12426         break;
12427     case 3:
12428         SetEvent( start_event );
12429         Sleep( 200 );
12430         SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12431         break;
12432     case 4:
12433         SetEvent( start_event );
12434         Sleep( 200 );
12435         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12436         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12437         break;
12438     case 5:
12439         SetEvent( start_event );
12440         Sleep( 200 );
12441         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12442         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12443         break;
12444     case 6:
12445         SetEvent( start_event );
12446         Sleep( 200 );
12447         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12448         while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12449         {
12450             GetMessage( &msg, 0, 0, 0 );
12451             DispatchMessage( &msg );
12452         }
12453         break;
12454     case 7:
12455         SetEvent( start_event );
12456         Sleep( 200 );
12457         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12458         SetTimer( hwnd, 3, 1, NULL );
12459         Sleep( 200 );
12460         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12461         break;
12462     case 8:
12463         SetEvent( start_event );
12464         Sleep( 200 );
12465         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12466         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12467         break;
12468     case 9:
12469         SetEvent( start_event );
12470         Sleep( 200 );
12471         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12472         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12473         for (;;) GetMessage( &msg, 0, 0, 0 );
12474         break;
12475     case 10:
12476         SetEvent( start_event );
12477         Sleep( 200 );
12478         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12479         SetTimer( hwnd, 3, 1, NULL );
12480         Sleep( 200 );
12481         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12482         break;
12483     case 11:
12484         SetEvent( start_event );
12485         Sleep( 200 );
12486         return;  /* exiting the process makes WaitForInputIdle return success too */
12487     case 12:
12488         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12489         Sleep( 200 );
12490         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12491         SetEvent( start_event );
12492         break;
12493     case 13:
12494         SetEvent( start_event );
12495         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12496         Sleep( 200 );
12497         thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12498         WaitForSingleObject( thread, 10000 );
12499         CloseHandle( thread );
12500         break;
12501     case 14:
12502         SetEvent( start_event );
12503         Sleep( 200 );
12504         PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12505         break;
12506     case 15:
12507         SetEvent( start_event );
12508         Sleep( 200 );
12509         PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12510         break;
12511     case 16:
12512         SetEvent( start_event );
12513         Sleep( 200 );
12514         PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12515         break;
12516     case 17:
12517         SetEvent( start_event );
12518         Sleep( 200 );
12519         PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12520         break;
12521     case 18:
12522         SetEvent( start_event );
12523         Sleep( 200 );
12524         PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12525         break;
12526     case 19:
12527         SetEvent( start_event );
12528         Sleep( 200 );
12529         PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12530         break;
12531     case 20:
12532         SetEvent( start_event );
12533         Sleep( 200 );
12534         PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12535         break;
12536     }
12537     WaitForSingleObject( end_event, 2000 );
12538     CloseHandle( start_event );
12539     CloseHandle( end_event );
12540     if (hwnd) DestroyWindow( hwnd );
12541 }
12542
12543 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12544 {
12545     if (msg == WM_WININICHANGE) Sleep( 200 );  /* make sure the child waits */
12546     return DefWindowProcA( hwnd, msg, wp, lp );
12547 }
12548
12549 static DWORD CALLBACK wait_idle_thread( void *arg )
12550 {
12551     WNDCLASS cls;
12552     MSG msg;
12553     HWND hwnd;
12554
12555     memset( &cls, 0, sizeof(cls) );
12556     cls.lpfnWndProc   = wait_idle_proc;
12557     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12558     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12559     cls.lpszClassName = "TestClass";
12560     RegisterClass( &cls );
12561
12562     hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12563     while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12564     DestroyWindow(hwnd);
12565     return 0;
12566 }
12567
12568 static void test_WaitForInputIdle( char *argv0 )
12569 {
12570     char path[MAX_PATH];
12571     PROCESS_INFORMATION pi;
12572     STARTUPINFOA startup;
12573     BOOL ret;
12574     HANDLE start_event, end_event, thread;
12575     unsigned int i;
12576     DWORD id;
12577     const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12578     const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12579     BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12580
12581     if (console_app)  /* build the test with -mwindows for better coverage */
12582         trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12583
12584     start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12585     end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12586     ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12587     ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12588
12589     memset( &startup, 0, sizeof(startup) );
12590     startup.cb = sizeof(startup);
12591     startup.dwFlags = STARTF_USESHOWWINDOW;
12592     startup.wShowWindow = SW_SHOWNORMAL;
12593
12594     thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12595
12596     for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12597     {
12598         ResetEvent( start_event );
12599         ResetEvent( end_event );
12600         sprintf( path, "%s msg %u", argv0, i );
12601         ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12602         ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12603         if (ret)
12604         {
12605             ret = WaitForSingleObject( start_event, 5000 );
12606             ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12607             if (ret == WAIT_OBJECT_0)
12608             {
12609                 ret = WaitForInputIdle( pi.hProcess, 1000 );
12610                 if (ret == WAIT_FAILED)
12611                     ok( console_app ||
12612                         ret == wait_idle_expect[i].exp ||
12613                         broken(ret == wait_idle_expect[i].broken),
12614                         "%u: WaitForInputIdle error %08x expected %08x\n",
12615                         i, ret, wait_idle_expect[i].exp );
12616                 else if (wait_idle_expect[i].todo)
12617                     todo_wine
12618                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12619                         "%u: WaitForInputIdle error %08x expected %08x\n",
12620                         i, ret, wait_idle_expect[i].exp );
12621                 else
12622                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12623                         "%u: WaitForInputIdle error %08x expected %08x\n",
12624                         i, ret, wait_idle_expect[i].exp );
12625                 SetEvent( end_event );
12626                 WaitForSingleObject( pi.hProcess, 1000 );  /* give it a chance to exit on its own */
12627             }
12628             TerminateProcess( pi.hProcess, 0 );  /* just in case */
12629             winetest_wait_child_process( pi.hProcess );
12630             ret = WaitForInputIdle( pi.hProcess, 100 );
12631             ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12632             CloseHandle( pi.hProcess );
12633             CloseHandle( pi.hThread );
12634         }
12635     }
12636     CloseHandle( start_event );
12637     PostThreadMessage( id, WM_QUIT, 0, 0 );
12638     WaitForSingleObject( thread, 10000 );
12639     CloseHandle( thread );
12640 }
12641
12642 START_TEST(msg)
12643 {
12644     char **test_argv;
12645     BOOL ret;
12646     BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12647
12648     int argc = winetest_get_mainargs( &test_argv );
12649     if (argc >= 3)
12650     {
12651         unsigned int arg;
12652         /* Child process. */
12653         sscanf (test_argv[2], "%d", (unsigned int *) &arg);
12654         do_wait_idle_child( arg );
12655         return;
12656     }
12657
12658     init_procs();
12659
12660     if (!RegisterWindowClasses()) assert(0);
12661
12662     if (pSetWinEventHook)
12663     {
12664         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12665                                        GetModuleHandleA(0), win_event_proc,
12666                                        0, GetCurrentThreadId(),
12667                                        WINEVENT_INCONTEXT);
12668         if (pIsWinEventHookInstalled && hEvent_hook)
12669         {
12670             UINT event;
12671             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12672                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12673         }
12674     }
12675     if (!hEvent_hook) win_skip( "no win event hook support\n" );
12676
12677     cbt_hook_thread_id = GetCurrentThreadId();
12678     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12679     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12680
12681     test_winevents();
12682
12683     /* Fix message sequences before removing 4 lines below */
12684 #if 1
12685     if (pUnhookWinEvent && hEvent_hook)
12686     {
12687         ret = pUnhookWinEvent(hEvent_hook);
12688         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12689         pUnhookWinEvent = 0;
12690     }
12691     hEvent_hook = 0;
12692 #endif
12693
12694     test_PostMessage();
12695     test_ShowWindow();
12696     test_PeekMessage();
12697     test_PeekMessage2();
12698     test_WaitForInputIdle( test_argv[0] );
12699     test_scrollwindowex();
12700     test_messages();
12701     test_setwindowpos();
12702     test_showwindow();
12703     invisible_parent_tests();
12704     test_mdi_messages();
12705     test_button_messages();
12706     test_static_messages();
12707     test_listbox_messages();
12708     test_combobox_messages();
12709     test_wmime_keydown_message();
12710     test_paint_messages();
12711     test_interthread_messages();
12712     test_message_conversion();
12713     test_accelerators();
12714     test_timers();
12715     test_timers_no_wnd();
12716     if (hCBT_hook) test_set_hook();
12717     test_DestroyWindow();
12718     test_DispatchMessage();
12719     test_SendMessageTimeout();
12720     test_edit_messages();
12721     test_quit_message();
12722     test_SetActiveWindow();
12723
12724     if (!pTrackMouseEvent)
12725         win_skip("TrackMouseEvent is not available\n");
12726     else
12727         test_TrackMouseEvent();
12728
12729     test_SetWindowRgn();
12730     test_sys_menu();
12731     test_dialog_messages();
12732     test_nullCallback();
12733     test_dbcs_wm_char();
12734     test_menu_messages();
12735     test_paintingloop();
12736     test_defwinproc();
12737     test_clipboard_viewers();
12738     /* keep it the last test, under Windows it tends to break the tests
12739      * which rely on active/foreground windows being correct.
12740      */
12741     test_SetForegroundWindow();
12742
12743     UnhookWindowsHookEx(hCBT_hook);
12744     if (pUnhookWinEvent && hEvent_hook)
12745     {
12746         ret = pUnhookWinEvent(hEvent_hook);
12747         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12748         SetLastError(0xdeadbeef);
12749         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12750         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12751            GetLastError() == 0xdeadbeef, /* Win9x */
12752            "unexpected error %d\n", GetLastError());
12753     }
12754 }