wnaspi32: Make winaspi.dll into a stand-alone 16-bit module.
[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 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42 #define SWP_STATECHANGED        0x8000
43
44 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
45
46 #ifndef WM_KEYF1
47 #define WM_KEYF1 0x004d
48 #endif
49
50 #ifndef WM_SYSTIMER
51 #define WM_SYSTIMER         0x0118
52 #endif
53
54 #define WND_PARENT_ID           1
55 #define WND_POPUP_ID            2
56 #define WND_CHILD_ID            3
57
58 #ifndef WM_LBTRACKPOINT
59 #define WM_LBTRACKPOINT  0x0131
60 #endif
61
62 /* encoded DRAWITEMSTRUCT into an LPARAM */
63 typedef struct
64 {
65     union
66     {
67         struct
68         {
69             UINT type    : 4;  /* ODT_* flags */
70             UINT ctl_id  : 4;  /* Control ID */
71             UINT item_id : 4;  /* Menu item ID */
72             UINT action  : 4;  /* ODA_* flags */
73             UINT state   : 16; /* ODS_* flags */
74         } item;
75         LPARAM lp;
76     } u;
77 } DRAW_ITEM_STRUCT;
78
79 static BOOL test_DestroyWindow_flag;
80 static HWINEVENTHOOK hEvent_hook;
81 static HHOOK hCBT_hook;
82 static DWORD cbt_hook_thread_id;
83
84 static const WCHAR testWindowClassW[] =
85 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
86
87 /*
88 FIXME: add tests for these
89 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
90  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
91  WS_THICKFRAME: thick border
92  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
93  WS_BORDER (default for overlapped windows): single black border
94  none (default for child (and popup?) windows): no border
95 */
96
97 typedef enum {
98     sent=0x1,
99     posted=0x2,
100     parent=0x4,
101     wparam=0x8,
102     lparam=0x10,
103     defwinproc=0x20,
104     beginpaint=0x40,
105     optional=0x80,
106     hook=0x100,
107     winevent_hook=0x200
108 } msg_flags_t;
109
110 struct message {
111     UINT message;          /* the WM_* code */
112     msg_flags_t flags;     /* message props */
113     WPARAM wParam;         /* expected value of wParam */
114     LPARAM lParam;         /* expected value of lParam */
115     WPARAM wp_mask;        /* mask for wParam checks */
116     LPARAM lp_mask;        /* mask for lParam checks */
117 };
118
119 struct recvd_message {
120     UINT message;          /* the WM_* code */
121     msg_flags_t flags;     /* message props */
122     HWND hwnd;             /* window that received the message */
123     WPARAM wParam;         /* expected value of wParam */
124     LPARAM lParam;         /* expected value of lParam */
125     int line;              /* source line where logged */
126     const char *descr;     /* description for trace output */
127     char output[512];      /* trace output */
128 };
129
130 /* Empty message sequence */
131 static const struct message WmEmptySeq[] =
132 {
133     { 0 }
134 };
135 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
136 static const struct message WmCreateOverlappedSeq[] = {
137     { HCBT_CREATEWND, hook },
138     { WM_GETMINMAXINFO, sent },
139     { WM_NCCREATE, sent },
140     { WM_NCCALCSIZE, sent|wparam, 0 },
141     { 0x0093, sent|defwinproc|optional },
142     { 0x0094, sent|defwinproc|optional },
143     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
144     { WM_CREATE, sent },
145     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
146     { 0 }
147 };
148 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
149  * for a not visible overlapped window.
150  */
151 static const struct message WmSWP_ShowOverlappedSeq[] = {
152     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
153     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
154     { WM_NCPAINT, sent|wparam|optional, 1 },
155     { WM_GETTEXT, sent|defwinproc|optional },
156     { WM_ERASEBKGND, sent|optional },
157     { HCBT_ACTIVATE, hook },
158     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
159     { WM_NOTIFYFORMAT, sent|optional },
160     { WM_QUERYUISTATE, sent|optional },
161     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
162     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
163     { WM_ACTIVATEAPP, sent|wparam, 1 },
164     { WM_NCACTIVATE, sent|wparam, 1 },
165     { WM_GETTEXT, sent|defwinproc|optional },
166     { WM_ACTIVATE, sent|wparam, 1 },
167     { HCBT_SETFOCUS, hook },
168     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
169     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
170     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
171     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
172     { WM_GETTEXT, sent|optional },
173     { WM_NCPAINT, sent|wparam|optional, 1 },
174     { WM_GETTEXT, sent|defwinproc|optional },
175     { WM_ERASEBKGND, sent|optional },
176     /* Win9x adds SWP_NOZORDER below */
177     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
178     { WM_GETTEXT, sent|optional },
179     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
180     { WM_NCPAINT, sent|wparam|optional, 1 },
181     { WM_ERASEBKGND, sent|optional },
182     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
183     { WM_SYNCPAINT, sent|optional },
184     { WM_GETTITLEBARINFOEX, sent|optional },
185     { WM_PAINT, sent|optional },
186     { WM_NCPAINT, sent|beginpaint|optional },
187     { WM_GETTEXT, sent|defwinproc|optional },
188     { WM_ERASEBKGND, sent|beginpaint|optional },
189     { 0 }
190 };
191 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
192  * for a visible overlapped window.
193  */
194 static const struct message WmSWP_HideOverlappedSeq[] = {
195     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
196     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
197     { HCBT_ACTIVATE, hook|optional },
198     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
199     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
200     { WM_NCACTIVATE, sent|optional },
201     { WM_ACTIVATE, sent|optional },
202     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
203     { 0 }
204 };
205
206 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
207  * for a visible overlapped window.
208  */
209 static const struct message WmSWP_ResizeSeq[] = {
210     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
211     { WM_GETMINMAXINFO, sent|defwinproc },
212     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
213     { WM_NCPAINT, sent|optional },
214     { WM_GETTEXT, sent|defwinproc|optional },
215     { WM_ERASEBKGND, sent|optional },
216     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
217     { WM_SIZE, sent|defwinproc|optional },
218     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
219     { WM_NCPAINT, sent|optional },
220     { WM_GETTEXT, sent|defwinproc|optional },
221     { WM_ERASEBKGND, sent|optional },
222     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
223     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
224     { 0 }
225 };
226
227 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
228  * for a visible popup window.
229  */
230 static const struct message WmSWP_ResizePopupSeq[] = {
231     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
232     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
233     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
234     { WM_NCPAINT, sent|optional },
235     { WM_GETTEXT, sent|defwinproc|optional },
236     { WM_ERASEBKGND, sent|optional },
237     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
238     { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
239     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
240     { WM_NCPAINT, sent|optional },
241     { WM_GETTEXT, sent|defwinproc|optional },
242     { WM_ERASEBKGND, sent|optional },
243     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
244     { 0 }
245 };
246
247 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
248  * for a visible overlapped window.
249  */
250 static const struct message WmSWP_MoveSeq[] = {
251     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
252     { WM_NCPAINT, sent|optional },
253     { WM_GETTEXT, sent|defwinproc|optional },
254     { WM_ERASEBKGND, sent|optional },
255     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
256     { WM_MOVE, sent|defwinproc|wparam, 0 },
257     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
258     { 0 }
259 };
260 /* Resize with SetWindowPos(SWP_NOZORDER)
261  * for a visible overlapped window
262  * SWP_NOZORDER is stripped by the logging code
263  */
264 static const struct message WmSWP_ResizeNoZOrder[] = {
265     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
266     { WM_GETMINMAXINFO, sent|defwinproc },
267     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
268     { WM_NCPAINT, sent|optional },
269     { WM_GETTEXT, sent|defwinproc|optional },
270     { WM_ERASEBKGND, sent|optional },
271     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
272       SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
273     { WM_MOVE, sent|defwinproc|optional },
274     { WM_SIZE, sent|defwinproc|optional },
275     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
276     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
277     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
278     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
279     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
280     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281     { 0 }
282 };
283
284 /* Switch visible mdi children */
285 static const struct message WmSwitchChild[] = {
286     /* Switch MDI child */
287     { WM_MDIACTIVATE, sent },/* in the MDI client */
288     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
289     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
290     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
291     /* Deactivate 2nd MDI child */
292     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
293     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
294     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
295     /* Preparing for maximize and maximaze the 1st MDI child */
296     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
297     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
298     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
299     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
300     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
301     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
302     /* Lock redraw 2nd MDI child */
303     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
304     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
305     /* Restore 2nd MDI child */
306     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
307     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
308     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
309     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
310     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
311     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312     /* Redraw 2nd MDI child */
313     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
314     /* Redraw MDI frame */
315     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
316     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
317     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
318     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
319     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
320     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
321     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
322     { HCBT_SETFOCUS, hook },
323     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
324     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
325     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
326     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
327     { WM_SETFOCUS, sent },/* in the MDI client */
328     { HCBT_SETFOCUS, hook },
329     { WM_KILLFOCUS, sent },/* in the MDI client */
330     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
331     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
332     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
333     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
334     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
335     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
336     { 0 }
337 };
338
339 /* Switch visible not maximized mdi children */
340 static const struct message WmSwitchNotMaximizedChild[] = {
341     /* Switch not maximized MDI child */
342     { WM_MDIACTIVATE, sent },/* in the MDI client */
343     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
344     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
345     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
346     /* Deactivate 1st MDI child */
347     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
348     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
349     /* Activate 2nd MDI child */
350     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
351     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
352     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
353     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
354     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
355     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
356     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
357     { HCBT_SETFOCUS, hook },
358     { WM_KILLFOCUS, sent }, /* in the  MDI client */
359     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
360     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
361     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
362     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
363     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
364     { 0 }
365 };
366
367
368 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
369                 SWP_NOZORDER|SWP_FRAMECHANGED)
370  * for a visible overlapped window with WS_CLIPCHILDREN style set.
371  */
372 static const struct message WmSWP_FrameChanged_clip[] = {
373     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
374     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
375     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
376     { WM_GETTEXT, sent|parent|defwinproc|optional },
377     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
378     { WM_NCPAINT, sent }, /* wparam != 1 */
379     { WM_ERASEBKGND, sent },
380     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
382     { WM_PAINT, sent },
383     { 0 }
384 };
385 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
386                 SWP_NOZORDER|SWP_FRAMECHANGED)
387  * for a visible overlapped window.
388  */
389 static const struct message WmSWP_FrameChangedDeferErase[] = {
390     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
391     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
392     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
393     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
394     { WM_PAINT, sent|parent|optional },
395     { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
396     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
397     { WM_PAINT, sent },
398     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
399     { WM_ERASEBKGND, sent|beginpaint|optional },
400     { 0 }
401 };
402
403 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
404                 SWP_NOZORDER|SWP_FRAMECHANGED)
405  * for a visible overlapped window without WS_CLIPCHILDREN style set.
406  */
407 static const struct message WmSWP_FrameChanged_noclip[] = {
408     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
409     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
410     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
411     { WM_GETTEXT, sent|parent|defwinproc|optional },
412     { WM_ERASEBKGND, sent|parent|optional },
413     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
414     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
415     { WM_PAINT, sent },
416     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
417     { WM_ERASEBKGND, sent|beginpaint|optional },
418     { 0 }
419 };
420
421 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
422 static const struct message WmShowOverlappedSeq[] = {
423     { WM_SHOWWINDOW, sent|wparam, 1 },
424     { WM_NCPAINT, sent|wparam|optional, 1 },
425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
426     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
427     { WM_NCPAINT, sent|wparam|optional, 1 },
428     { WM_GETTEXT, sent|defwinproc|optional },
429     { WM_ERASEBKGND, sent|optional },
430     { HCBT_ACTIVATE, hook },
431     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
432     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
433     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
434     { WM_NCPAINT, sent|wparam|optional, 1 },
435     { WM_ACTIVATEAPP, sent|wparam, 1 },
436     { WM_NCACTIVATE, sent|wparam, 1 },
437     { WM_GETTEXT, sent|defwinproc|optional },
438     { WM_ACTIVATE, sent|wparam, 1 },
439     { HCBT_SETFOCUS, hook },
440     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
441     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
442     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
443     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
444     { WM_GETTEXT, sent|optional },
445     { WM_NCPAINT, sent|wparam|optional, 1 },
446     { WM_GETTEXT, sent|defwinproc|optional },
447     { WM_ERASEBKGND, sent|optional },
448     /* Win9x adds SWP_NOZORDER below */
449     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
450     { WM_NCCALCSIZE, sent|optional },
451     { WM_GETTEXT, sent|optional },
452     { WM_NCPAINT, sent|optional },
453     { WM_ERASEBKGND, sent|optional },
454     { WM_SYNCPAINT, sent|optional },
455 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
456        * messages. Does that mean that CreateWindow doesn't set initial
457        * window dimensions for overlapped windows?
458        */
459     { WM_SIZE, sent },
460     { WM_MOVE, sent },
461 #endif
462     { WM_PAINT, sent|optional },
463     { WM_NCPAINT, sent|beginpaint|optional },
464     { 0 }
465 };
466 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
467 static const struct message WmShowMaxOverlappedSeq[] = {
468     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
469     { WM_GETMINMAXINFO, sent },
470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
471     { WM_GETMINMAXINFO, sent|defwinproc },
472     { WM_NCCALCSIZE, sent|wparam, TRUE },
473     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
474     { HCBT_ACTIVATE, hook },
475     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
476     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
477     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
478     { WM_ACTIVATEAPP, sent|wparam, 1 },
479     { WM_NCACTIVATE, sent|wparam, 1 },
480     { WM_GETTEXT, sent|defwinproc|optional },
481     { WM_ACTIVATE, sent|wparam, 1 },
482     { HCBT_SETFOCUS, hook },
483     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
484     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
485     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
486     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
487     { WM_GETTEXT, sent|optional },
488     { WM_NCPAINT, sent|wparam|optional, 1 },
489     { WM_GETTEXT, sent|defwinproc|optional },
490     { WM_ERASEBKGND, sent|optional },
491     /* Win9x adds SWP_NOZORDER below */
492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
493     { WM_MOVE, sent|defwinproc },
494     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
495     { WM_GETTEXT, sent|optional },
496     { WM_NCCALCSIZE, sent|optional },
497     { WM_NCPAINT, sent|optional },
498     { WM_ERASEBKGND, sent|optional },
499     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
500     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501     { WM_SYNCPAINT, sent|optional },
502     { WM_GETTITLEBARINFOEX, sent|optional },
503     { WM_PAINT, sent|optional },
504     { WM_NCPAINT, sent|beginpaint|optional },
505     { WM_ERASEBKGND, sent|beginpaint|optional },
506     { 0 }
507 };
508 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
509 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
510     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
511     { WM_GETTEXT, sent|optional },
512     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
513     { WM_GETMINMAXINFO, sent|defwinproc },
514     { WM_NCCALCSIZE, sent|wparam, TRUE },
515     { WM_NCPAINT, sent|optional },
516     { WM_GETTEXT, sent|defwinproc|optional },
517     { WM_ERASEBKGND, sent|optional },
518     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
519     { WM_MOVE, sent|defwinproc|optional },
520     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
521     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
522     { WM_NCPAINT, sent|optional },
523     { WM_ERASEBKGND, sent|optional },
524     { WM_PAINT, sent|optional },
525     { WM_GETTITLEBARINFOEX, sent|optional },
526     { WM_NCPAINT, sent|beginpaint|optional },
527     { WM_ERASEBKGND, sent|beginpaint|optional },
528     { 0 }
529 };
530 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
531 static const struct message WmShowRestoreMinOverlappedSeq[] = {
532     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
533     { WM_QUERYOPEN, sent|optional },
534     { WM_GETTEXT, sent|optional },
535     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
536     { WM_GETMINMAXINFO, sent|defwinproc },
537     { WM_NCCALCSIZE, sent|wparam, TRUE },
538     { HCBT_ACTIVATE, hook },
539     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
540     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
541     { WM_ACTIVATEAPP, sent|wparam, 1 },
542     { WM_NCACTIVATE, sent|wparam, 1 },
543     { WM_GETTEXT, sent|defwinproc|optional },
544     { WM_ACTIVATE, sent|wparam, 1 },
545     { HCBT_SETFOCUS, hook },
546     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
547     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
548     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
549     { WM_GETTEXT, sent|optional },
550     { WM_NCPAINT, sent|wparam|optional, 1 },
551     { WM_GETTEXT, sent|defwinproc|optional },
552     { WM_ERASEBKGND, sent },
553     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
554     { WM_MOVE, sent|defwinproc },
555     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
556     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
557     { WM_NCPAINT, sent|wparam|optional, 1 },
558     { WM_ERASEBKGND, sent|optional },
559     { WM_ACTIVATE, sent|wparam, 1 },
560     { WM_GETTEXT, sent|optional },
561     { WM_PAINT, sent|optional },
562     { WM_GETTITLEBARINFOEX, sent|optional },
563     { WM_NCPAINT, sent|beginpaint|optional },
564     { WM_ERASEBKGND, sent|beginpaint|optional },
565     { 0 }
566 };
567 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
568 static const struct message WmShowMinOverlappedSeq[] = {
569     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
570     { HCBT_SETFOCUS, hook },
571     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
572     { WM_KILLFOCUS, sent },
573     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
574     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
575     { WM_GETTEXT, sent|optional },
576     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
577     { WM_GETMINMAXINFO, sent|defwinproc },
578     { WM_NCCALCSIZE, sent|wparam, TRUE },
579     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
580     { WM_NCPAINT, sent|optional },
581     { WM_GETTEXT, sent|defwinproc|optional },
582     { WM_WINDOWPOSCHANGED, sent },
583     { WM_MOVE, sent|defwinproc },
584     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
585     { WM_NCCALCSIZE, sent|optional },
586     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
587     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
589     { WM_NCACTIVATE, sent|wparam, 0 },
590     { WM_GETTEXT, sent|defwinproc|optional },
591     { WM_ACTIVATE, sent },
592     { WM_ACTIVATEAPP, sent|wparam, 0 },
593
594     /* Vista sometimes restores the window right away... */
595     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
596     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
597     { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
598     { WM_QUERYOPEN, sent|optional },
599     { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
600     { WM_GETMINMAXINFO, sent|optional|defwinproc },
601     { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
602     { HCBT_ACTIVATE, hook|optional },
603     { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
604     { WM_NCACTIVATE, sent|optional },
605     { WM_GETTEXT, sent|optional },
606     { WM_ACTIVATE, sent|optional|wparam, 1 },
607     { HCBT_SETFOCUS, hook|optional },
608     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
609     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
610     { WM_SETFOCUS, sent|optional },
611     { WM_NCPAINT, sent|optional },
612     { WM_GETTEXT, sent|defwinproc|optional },
613     { WM_ERASEBKGND, sent|optional },
614     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
615     { WM_MOVE, sent|defwinproc|optional },
616     { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
617     { WM_ACTIVATE, sent|optional|wparam, 1 },
618     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
619     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
620
621     { WM_PAINT, sent|optional },
622     { WM_NCPAINT, sent|beginpaint|optional },
623     { WM_ERASEBKGND, sent|beginpaint|optional },
624     { 0 }
625 };
626 /* ShowWindow(SW_HIDE) for a visible overlapped window */
627 static const struct message WmHideOverlappedSeq[] = {
628     { WM_SHOWWINDOW, sent|wparam, 0 },
629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
630     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
631     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
632     { WM_SIZE, sent|optional }, /* XP doesn't send it */
633     { WM_MOVE, sent|optional }, /* XP doesn't send it */
634     { WM_NCACTIVATE, sent|wparam, 0 },
635     { WM_ACTIVATE, sent|wparam, 0 },
636     { WM_ACTIVATEAPP, sent|wparam, 0 },
637     { WM_KILLFOCUS, sent|wparam, 0 },
638     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
639     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
640     { 0 }
641 };
642 /* DestroyWindow for a visible overlapped window */
643 static const struct message WmDestroyOverlappedSeq[] = {
644     { HCBT_DESTROYWND, hook },
645     { 0x0090, sent|optional },
646     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
647     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
648     { 0x0090, sent|optional },
649     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
650     { WM_NCACTIVATE, sent|optional|wparam, 0 },
651     { WM_ACTIVATE, sent|optional },
652     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
653     { WM_KILLFOCUS, sent|optional|wparam, 0 },
654     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
655     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
656     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
657     { WM_DESTROY, sent },
658     { WM_NCDESTROY, sent },
659     { 0 }
660 };
661 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
662 static const struct message WmCreateMaxPopupSeq[] = {
663     { HCBT_CREATEWND, hook },
664     { WM_NCCREATE, sent },
665     { WM_NCCALCSIZE, sent|wparam, 0 },
666     { WM_CREATE, sent },
667     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
668     { WM_SIZE, sent|wparam, SIZE_RESTORED },
669     { WM_MOVE, sent },
670     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
671     { WM_GETMINMAXINFO, sent },
672     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
673     { WM_NCCALCSIZE, sent|wparam, TRUE },
674     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
675     { WM_MOVE, sent|defwinproc },
676     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
677     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
678     { WM_SHOWWINDOW, sent|wparam, 1 },
679     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
680     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
681     { HCBT_ACTIVATE, hook },
682     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
683     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
684     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
685     { WM_NCPAINT, sent|wparam|optional, 1 },
686     { WM_ERASEBKGND, sent|optional },
687     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
688     { WM_ACTIVATEAPP, sent|wparam, 1 },
689     { WM_NCACTIVATE, sent },
690     { WM_ACTIVATE, sent|wparam, 1 },
691     { HCBT_SETFOCUS, hook },
692     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
693     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
694     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
695     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
696     { WM_GETTEXT, sent|optional },
697     { WM_SYNCPAINT, sent|wparam|optional, 4 },
698     { WM_NCPAINT, sent|wparam|optional, 1 },
699     { WM_ERASEBKGND, sent|optional },
700     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
701     { WM_ERASEBKGND, sent|defwinproc|optional },
702     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
703     { 0 }
704 };
705 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
706 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
707     { HCBT_CREATEWND, hook },
708     { WM_NCCREATE, sent },
709     { WM_NCCALCSIZE, sent|wparam, 0 },
710     { WM_CREATE, sent },
711     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
712     { WM_SIZE, sent|wparam, SIZE_RESTORED },
713     { WM_MOVE, sent },
714     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
715     { WM_GETMINMAXINFO, sent },
716     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
717     { WM_NCCALCSIZE, sent|wparam, TRUE },
718     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
719     { WM_MOVE, sent|defwinproc },
720     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
721     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
722     { 0 }
723 };
724 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
725 static const struct message WmShowMaxPopupResizedSeq[] = {
726     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
727     { WM_GETMINMAXINFO, sent },
728     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
729     { WM_NCCALCSIZE, sent|wparam, TRUE },
730     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
731     { HCBT_ACTIVATE, hook },
732     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
733     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
734     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
735     { WM_NCPAINT, sent|wparam|optional, 1 },
736     { WM_ERASEBKGND, sent|optional },
737     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
738     { WM_ACTIVATEAPP, sent|wparam, 1 },
739     { WM_NCACTIVATE, sent },
740     { WM_ACTIVATE, sent|wparam, 1 },
741     { HCBT_SETFOCUS, hook },
742     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
743     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
744     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
745     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
746     { WM_GETTEXT, sent|optional },
747     { WM_NCPAINT, sent|wparam|optional, 1 },
748     { WM_ERASEBKGND, sent|optional },
749     { WM_WINDOWPOSCHANGED, sent },
750     /* WinNT4.0 sends WM_MOVE */
751     { WM_MOVE, sent|defwinproc|optional },
752     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
753     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
754     { 0 }
755 };
756 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
757 static const struct message WmShowMaxPopupSeq[] = {
758     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
759     { WM_GETMINMAXINFO, sent },
760     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
761     { WM_NCCALCSIZE, sent|wparam, TRUE },
762     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
763     { HCBT_ACTIVATE, hook },
764     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
765     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
766     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
767     { WM_ACTIVATEAPP, sent|wparam, 1 },
768     { WM_NCACTIVATE, sent },
769     { WM_ACTIVATE, sent|wparam, 1 },
770     { HCBT_SETFOCUS, hook },
771     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
772     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
773     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
774     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
775     { WM_GETTEXT, sent|optional },
776     { WM_SYNCPAINT, sent|wparam|optional, 4 },
777     { WM_NCPAINT, sent|wparam|optional, 1 },
778     { WM_ERASEBKGND, sent|optional },
779     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
780     { WM_ERASEBKGND, sent|defwinproc|optional },
781     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
782     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
783     { 0 }
784 };
785 /* CreateWindow(WS_VISIBLE) for popup window */
786 static const struct message WmCreatePopupSeq[] = {
787     { HCBT_CREATEWND, hook },
788     { WM_NCCREATE, sent },
789     { WM_NCCALCSIZE, sent|wparam, 0 },
790     { WM_CREATE, sent },
791     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
792     { WM_SIZE, sent|wparam, SIZE_RESTORED },
793     { WM_MOVE, sent },
794     { WM_SHOWWINDOW, sent|wparam, 1 },
795     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
796     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
797     { HCBT_ACTIVATE, hook },
798     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
799     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
800     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
801     { WM_NCPAINT, sent|wparam|optional, 1 },
802     { WM_ERASEBKGND, sent|optional },
803     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
804     { WM_ACTIVATEAPP, sent|wparam, 1 },
805     { WM_NCACTIVATE, sent },
806     { WM_ACTIVATE, sent|wparam, 1 },
807     { HCBT_SETFOCUS, hook },
808     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
809     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
810     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
811     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
812     { WM_GETTEXT, sent|optional },
813     { WM_SYNCPAINT, sent|wparam|optional, 4 },
814     { WM_NCPAINT, sent|wparam|optional, 1 },
815     { WM_ERASEBKGND, sent|optional },
816     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
817     { 0 }
818 };
819 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
820 static const struct message WmShowVisMaxPopupSeq[] = {
821     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
822     { WM_GETMINMAXINFO, sent },
823     { WM_GETTEXT, sent|optional },
824     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
825     { WM_GETTEXT, sent|optional },
826     { WM_NCCALCSIZE, sent|wparam, TRUE },
827     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
828     { WM_NCPAINT, sent|wparam|optional, 1 },
829     { WM_ERASEBKGND, sent|optional },
830     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
831     { WM_MOVE, sent|defwinproc },
832     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
833     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
834     { 0 }
835 };
836 /* CreateWindow (for a child popup window, not initially visible) */
837 static const struct message WmCreateChildPopupSeq[] = {
838     { HCBT_CREATEWND, hook },
839     { WM_NCCREATE, sent }, 
840     { WM_NCCALCSIZE, sent|wparam, 0 },
841     { WM_CREATE, sent },
842     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
843     { WM_SIZE, sent|wparam, SIZE_RESTORED },
844     { WM_MOVE, sent },
845     { 0 }
846 };
847 /* CreateWindow (for a popup window, not initially visible,
848  * which sets WS_VISIBLE in WM_CREATE handler)
849  */
850 static const struct message WmCreateInvisiblePopupSeq[] = {
851     { HCBT_CREATEWND, hook },
852     { WM_NCCREATE, sent }, 
853     { WM_NCCALCSIZE, sent|wparam, 0 },
854     { WM_CREATE, sent },
855     { WM_STYLECHANGING, sent },
856     { WM_STYLECHANGED, sent },
857     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
858     { WM_SIZE, sent|wparam, SIZE_RESTORED },
859     { WM_MOVE, sent },
860     { 0 }
861 };
862 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
863  * for a popup window with WS_VISIBLE style set
864  */
865 static const struct message WmShowVisiblePopupSeq_2[] = {
866     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
867     { 0 }
868 };
869 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
870  * for a popup window with WS_VISIBLE style set
871  */
872 static const struct message WmShowVisiblePopupSeq_3[] = {
873     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
874     { HCBT_ACTIVATE, hook },
875     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
876     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
877     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
878     { WM_NCACTIVATE, sent },
879     { WM_ACTIVATE, sent|wparam, 1 },
880     { HCBT_SETFOCUS, hook },
881     { WM_KILLFOCUS, sent|parent },
882     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
883     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
884     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
885     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
886     { WM_SETFOCUS, sent|defwinproc },
887     { WM_GETTEXT, sent|optional },
888     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
889     { 0 }
890 };
891 /* CreateWindow (for child window, not initially visible) */
892 static const struct message WmCreateChildSeq[] = {
893     { HCBT_CREATEWND, hook },
894     { WM_NCCREATE, sent }, 
895     /* child is inserted into parent's child list after WM_NCCREATE returns */
896     { WM_NCCALCSIZE, sent|wparam, 0 },
897     { WM_CREATE, sent },
898     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
899     { WM_SIZE, sent|wparam, SIZE_RESTORED },
900     { WM_MOVE, sent },
901     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
902     { 0 }
903 };
904 /* CreateWindow (for maximized child window, not initially visible) */
905 static const struct message WmCreateMaximizedChildSeq[] = {
906     { HCBT_CREATEWND, hook },
907     { WM_NCCREATE, sent }, 
908     { WM_NCCALCSIZE, sent|wparam, 0 },
909     { WM_CREATE, sent },
910     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
911     { WM_SIZE, sent|wparam, SIZE_RESTORED },
912     { WM_MOVE, sent },
913     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
914     { WM_GETMINMAXINFO, sent },
915     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
916     { WM_NCCALCSIZE, sent|wparam, 1 },
917     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
918     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
919     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
920     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
921     { 0 }
922 };
923 /* CreateWindow (for a child window, initially visible) */
924 static const struct message WmCreateVisibleChildSeq[] = {
925     { HCBT_CREATEWND, hook },
926     { WM_NCCREATE, sent }, 
927     /* child is inserted into parent's child list after WM_NCCREATE returns */
928     { WM_NCCALCSIZE, sent|wparam, 0 },
929     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
930     { WM_CREATE, sent },
931     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
932     { WM_SIZE, sent|wparam, SIZE_RESTORED },
933     { WM_MOVE, sent },
934     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
935     { WM_SHOWWINDOW, sent|wparam, 1 },
936     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
937     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
938     { WM_ERASEBKGND, sent|parent|optional },
939     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
940     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
941     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
942     { 0 }
943 };
944 /* ShowWindow(SW_SHOW) for a not visible child window */
945 static const struct message WmShowChildSeq[] = {
946     { WM_SHOWWINDOW, sent|wparam, 1 },
947     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
948     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
949     { WM_ERASEBKGND, sent|parent|optional },
950     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
951     { 0 }
952 };
953 /* ShowWindow(SW_HIDE) for a visible child window */
954 static const struct message WmHideChildSeq[] = {
955     { WM_SHOWWINDOW, sent|wparam, 0 },
956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
957     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
958     { WM_ERASEBKGND, sent|parent|optional },
959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
960     { 0 }
961 };
962 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
963 static const struct message WmHideChildSeq2[] = {
964     { WM_SHOWWINDOW, sent|wparam, 0 },
965     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
966     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
967     { WM_ERASEBKGND, sent|parent|optional },
968     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
969     { 0 }
970 };
971 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
972  * for a not visible child window
973  */
974 static const struct message WmShowChildSeq_2[] = {
975     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
976     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
977     { WM_CHILDACTIVATE, sent },
978     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
979     { 0 }
980 };
981 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
982  * for a not visible child window
983  */
984 static const struct message WmShowChildSeq_3[] = {
985     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
986     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
987     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
988     { 0 }
989 };
990 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
991  * for a visible child window with a caption
992  */
993 static const struct message WmShowChildSeq_4[] = {
994     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
995     { WM_CHILDACTIVATE, sent },
996     { 0 }
997 };
998 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
999 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1000     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1001     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1002     { WM_NCCALCSIZE, sent|wparam, 1 },
1003     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1004     { WM_CHILDACTIVATE, sent|optional },
1005     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1006     { WM_MOVE, sent|defwinproc },
1007     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1008     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1009     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1010     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1011     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1012     { WM_GETTEXT, sent|optional },
1013     { 0 }
1014 };
1015 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1016 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1017     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1018     { 0 }
1019 };
1020 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1021 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1022     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1023     { WM_GETMINMAXINFO, sent },
1024     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1025     { WM_NCCALCSIZE, sent|wparam, 1 },
1026     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1027     { WM_CHILDACTIVATE, sent },
1028     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1029     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1030     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1031     { 0 }
1032 };
1033 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1034 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1035     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1036     { 0 }
1037 };
1038 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1039 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1040     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1041     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1042     { WM_NCCALCSIZE, sent|wparam, 1 },
1043     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1044     { WM_CHILDACTIVATE, sent },
1045     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1046     { WM_MOVE, sent|defwinproc },
1047     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1048     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1049     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1050     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1051     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1052     { WM_GETTEXT, sent|optional },
1053     { 0 }
1054 };
1055 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1056 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1057     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1058     { 0 }
1059 };
1060 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1061 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1062     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1063     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1064     { WM_NCCALCSIZE, sent|wparam, 1 },
1065     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1066     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1067     { WM_MOVE, sent|defwinproc },
1068     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1069     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1070     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1071     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1072     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1073     { WM_GETTEXT, sent|optional },
1074     { 0 }
1075 };
1076 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1077 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1078     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1079     { 0 }
1080 };
1081 /* ShowWindow(SW_SHOW) for child with invisible parent */
1082 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1083     { WM_SHOWWINDOW, sent|wparam, 1 },
1084     { 0 }
1085 };
1086 /* ShowWindow(SW_HIDE) for child with invisible parent */
1087 static const struct message WmHideChildInvisibleParentSeq[] = {
1088     { WM_SHOWWINDOW, sent|wparam, 0 },
1089     { 0 }
1090 };
1091 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1092 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1093     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1094     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1095     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1096     { 0 }
1097 };
1098 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1099 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1100     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1101     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1102     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1103     { 0 }
1104 };
1105 /* DestroyWindow for a visible child window */
1106 static const struct message WmDestroyChildSeq[] = {
1107     { HCBT_DESTROYWND, hook },
1108     { 0x0090, sent|optional },
1109     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1110     { WM_SHOWWINDOW, sent|wparam, 0 },
1111     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1112     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1113     { WM_ERASEBKGND, sent|parent|optional },
1114     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1115     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1116     { WM_KILLFOCUS, sent },
1117     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1118     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1119     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1120     { WM_SETFOCUS, sent|parent },
1121     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1122     { WM_DESTROY, sent },
1123     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1124     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1125     { WM_NCDESTROY, sent },
1126     { 0 }
1127 };
1128 /* DestroyWindow for a visible child window with invisible parent */
1129 static const struct message WmDestroyInvisibleChildSeq[] = {
1130     { HCBT_DESTROYWND, hook },
1131     { 0x0090, sent|optional },
1132     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1133     { WM_SHOWWINDOW, sent|wparam, 0 },
1134     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1135     { WM_DESTROY, sent },
1136     { WM_NCDESTROY, sent },
1137     { 0 }
1138 };
1139 /* Moving the mouse in nonclient area */
1140 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1141     { WM_NCHITTEST, sent },
1142     { WM_SETCURSOR, sent },
1143     { WM_NCMOUSEMOVE, posted },
1144     { 0 }
1145 };
1146 /* Moving the mouse in client area */
1147 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1148     { WM_NCHITTEST, sent },
1149     { WM_SETCURSOR, sent },
1150     { WM_MOUSEMOVE, posted },
1151     { 0 }
1152 };
1153 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1154 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1155     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1156     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1157     { WM_GETMINMAXINFO, sent|defwinproc },
1158     { WM_ENTERSIZEMOVE, sent|defwinproc },
1159     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1160     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1161     { WM_MOVE, sent|defwinproc },
1162     { WM_EXITSIZEMOVE, sent|defwinproc },
1163     { 0 }
1164 };
1165 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1166 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1167     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1168     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1169     { WM_GETMINMAXINFO, sent|defwinproc },
1170     { WM_ENTERSIZEMOVE, sent|defwinproc },
1171     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1172     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1173     { WM_GETMINMAXINFO, sent|defwinproc },
1174     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1175     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1176     { WM_GETTEXT, sent|defwinproc },
1177     { WM_ERASEBKGND, sent|defwinproc },
1178     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1179     { WM_MOVE, sent|defwinproc },
1180     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1181     { WM_EXITSIZEMOVE, sent|defwinproc },
1182     { 0 }
1183 };
1184 /* Resizing child window with MoveWindow (32) */
1185 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1186     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1187     { WM_NCCALCSIZE, sent|wparam, 1 },
1188     { WM_ERASEBKGND, sent|parent|optional },
1189     { WM_ERASEBKGND, sent|optional },
1190     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1191     { WM_MOVE, sent|defwinproc },
1192     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1193     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1194     { 0 }
1195 };
1196 /* Clicking on inactive button */
1197 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1198     { WM_NCHITTEST, sent },
1199     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1200     { WM_MOUSEACTIVATE, sent },
1201     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1202     { WM_SETCURSOR, sent },
1203     { WM_SETCURSOR, sent|parent|defwinproc },
1204     { WM_LBUTTONDOWN, posted },
1205     { WM_KILLFOCUS, posted|parent },
1206     { WM_SETFOCUS, posted },
1207     { WM_CTLCOLORBTN, posted|parent },
1208     { BM_SETSTATE, posted },
1209     { WM_CTLCOLORBTN, posted|parent },
1210     { WM_LBUTTONUP, posted },
1211     { BM_SETSTATE, posted },
1212     { WM_CTLCOLORBTN, posted|parent },
1213     { WM_COMMAND, posted|parent },
1214     { 0 }
1215 };
1216 /* Reparenting a button (16/32) */
1217 /* The last child (button) reparented gets topmost for its new parent. */
1218 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1219     { WM_SHOWWINDOW, sent|wparam, 0 },
1220     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1221     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1222     { WM_ERASEBKGND, sent|parent },
1223     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1224     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1225     { WM_CHILDACTIVATE, sent },
1226     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1227     { WM_MOVE, sent|defwinproc },
1228     { WM_SHOWWINDOW, sent|wparam, 1 },
1229     { 0 }
1230 };
1231 /* Creation of a custom dialog (32) */
1232 static const struct message WmCreateCustomDialogSeq[] = {
1233     { HCBT_CREATEWND, hook },
1234     { WM_GETMINMAXINFO, sent },
1235     { WM_NCCREATE, sent },
1236     { WM_NCCALCSIZE, sent|wparam, 0 },
1237     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1238     { WM_CREATE, sent },
1239     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1240     { WM_NOTIFYFORMAT, sent|optional },
1241     { WM_QUERYUISTATE, sent|optional },
1242     { WM_WINDOWPOSCHANGING, sent|optional },
1243     { WM_GETMINMAXINFO, sent|optional },
1244     { WM_NCCALCSIZE, sent|optional },
1245     { WM_WINDOWPOSCHANGED, sent|optional },
1246     { WM_SHOWWINDOW, sent|wparam, 1 },
1247     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1248     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1249     { HCBT_ACTIVATE, hook },
1250     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1251
1252
1253     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1254
1255     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1256
1257     { WM_NCACTIVATE, sent },
1258     { WM_GETTEXT, sent|optional|defwinproc },
1259     { WM_GETTEXT, sent|optional|defwinproc },
1260     { WM_GETTEXT, sent|optional|defwinproc },
1261     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1262     { WM_ACTIVATE, sent|wparam, 1 },
1263     { WM_GETTEXT, sent|optional },
1264     { WM_KILLFOCUS, sent|parent },
1265     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1266     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1267     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1268     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1269     { WM_SETFOCUS, sent },
1270     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1271     { WM_NCPAINT, sent|wparam, 1 },
1272     { WM_GETTEXT, sent|optional|defwinproc },
1273     { WM_GETTEXT, sent|optional|defwinproc },
1274     { WM_ERASEBKGND, sent },
1275     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1276     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1277     { WM_GETTEXT, sent|optional },
1278     { WM_GETTEXT, sent|optional },
1279     { WM_NCCALCSIZE, sent|optional },
1280     { WM_NCPAINT, sent|optional },
1281     { WM_GETTEXT, sent|optional|defwinproc },
1282     { WM_GETTEXT, sent|optional|defwinproc },
1283     { WM_ERASEBKGND, sent|optional },
1284     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1285     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1286     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1287     { WM_MOVE, sent },
1288     { 0 }
1289 };
1290 /* Calling EndDialog for a custom dialog (32) */
1291 static const struct message WmEndCustomDialogSeq[] = {
1292     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1293     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1294     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1295     { WM_GETTEXT, sent|optional },
1296     { HCBT_ACTIVATE, hook },
1297     { WM_NCACTIVATE, sent|wparam, 0 },
1298     { WM_GETTEXT, sent|optional|defwinproc },
1299     { WM_GETTEXT, sent|optional|defwinproc },
1300     { WM_ACTIVATE, sent|wparam, 0 },
1301     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1302     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1303     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1304     { WM_GETTEXT, sent|optional|defwinproc },
1305     { WM_GETTEXT, sent|optional|defwinproc },
1306     { HCBT_SETFOCUS, hook },
1307     { WM_KILLFOCUS, sent },
1308     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1309     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1310     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1311     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1312     { WM_SETFOCUS, sent|parent|defwinproc },
1313     { 0 }
1314 };
1315 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1316 static const struct message WmShowCustomDialogSeq[] = {
1317     { WM_SHOWWINDOW, sent|wparam, 1 },
1318     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1319     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1320     { HCBT_ACTIVATE, hook },
1321     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1322
1323     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1324
1325     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1326     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1327     { WM_NCACTIVATE, sent },
1328     { WM_ACTIVATE, sent|wparam, 1 },
1329     { WM_GETTEXT, sent|optional },
1330
1331     { WM_KILLFOCUS, sent|parent },
1332     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1333     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1334     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1335     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1336     { WM_SETFOCUS, sent },
1337     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1338     { WM_NCPAINT, sent|wparam, 1 },
1339     { WM_ERASEBKGND, sent },
1340     { WM_CTLCOLORDLG, sent|defwinproc },
1341     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1342     { 0 }
1343 };
1344 /* Creation and destruction of a modal dialog (32) */
1345 static const struct message WmModalDialogSeq[] = {
1346     { WM_CANCELMODE, sent|parent },
1347     { HCBT_SETFOCUS, hook },
1348     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1349     { WM_KILLFOCUS, sent|parent },
1350     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1351     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1352     { WM_ENABLE, sent|parent|wparam, 0 },
1353     { HCBT_CREATEWND, hook },
1354     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1355     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1356     { WM_SETFONT, sent },
1357     { WM_INITDIALOG, sent },
1358     { WM_CHANGEUISTATE, sent|optional },
1359     { WM_UPDATEUISTATE, sent|optional },
1360     { WM_SHOWWINDOW, sent },
1361     { HCBT_ACTIVATE, hook },
1362     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1363     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1364     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1365     { WM_NCACTIVATE, sent },
1366     { WM_GETTEXT, sent|optional },
1367     { WM_ACTIVATE, sent|wparam, 1 },
1368     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1369     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1370     { WM_NCPAINT, sent|optional },
1371     { WM_GETTEXT, sent|optional },
1372     { WM_ERASEBKGND, sent|optional },
1373     { WM_CTLCOLORDLG, sent|optional },
1374     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1375     { WM_GETTEXT, sent|optional },
1376     { WM_NCCALCSIZE, sent|optional },
1377     { WM_NCPAINT, sent|optional },
1378     { WM_GETTEXT, sent|optional },
1379     { WM_ERASEBKGND, sent|optional },
1380     { WM_CTLCOLORDLG, sent|optional },
1381     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1382     { WM_PAINT, sent|optional },
1383     { WM_CTLCOLORBTN, sent|optional },
1384     { WM_GETTITLEBARINFOEX, sent|optional },
1385     { WM_ENTERIDLE, sent|parent|optional },
1386     { WM_ENTERIDLE, sent|parent|optional },
1387     { WM_ENTERIDLE, sent|parent|optional },
1388     { WM_ENTERIDLE, sent|parent|optional },
1389     { WM_ENTERIDLE, sent|parent|optional },
1390     { WM_ENTERIDLE, sent|parent|optional },
1391     { WM_ENTERIDLE, sent|parent|optional },
1392     { WM_ENTERIDLE, sent|parent|optional },
1393     { WM_ENTERIDLE, sent|parent|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_TIMER, sent },
1406     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1407     { WM_ENABLE, sent|parent|wparam, 1 },
1408     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1409     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1410     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1411     { WM_GETTEXT, sent|optional },
1412     { HCBT_ACTIVATE, hook },
1413     { WM_NCACTIVATE, sent|wparam, 0 },
1414     { WM_GETTEXT, sent|optional },
1415     { WM_ACTIVATE, sent|wparam, 0 },
1416     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1417     { WM_WINDOWPOSCHANGING, sent|optional },
1418     { WM_WINDOWPOSCHANGED, sent|optional },
1419     { HCBT_SETFOCUS, hook },
1420     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1421     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1422     { WM_SETFOCUS, sent|parent|defwinproc },
1423     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1424     { HCBT_DESTROYWND, hook },
1425     { 0x0090, sent|optional },
1426     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1427     { WM_DESTROY, sent },
1428     { WM_NCDESTROY, sent },
1429     { 0 }
1430 };
1431 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1432 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1433     /* (inside dialog proc, handling WM_INITDIALOG) */
1434     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1435     { WM_NCCALCSIZE, sent },
1436     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1437     { WM_GETTEXT, sent|defwinproc },
1438     { WM_ACTIVATE, sent|parent|wparam, 0 },
1439     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1440     { WM_WINDOWPOSCHANGING, sent|parent },
1441     { WM_NCACTIVATE, sent|wparam, 1 },
1442     { WM_ACTIVATE, sent|wparam, 1 },
1443     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1444     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1445     /* (setting focus) */
1446     { WM_SHOWWINDOW, sent|wparam, 1 },
1447     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1448     { WM_NCPAINT, sent },
1449     { WM_GETTEXT, sent|defwinproc },
1450     { WM_ERASEBKGND, sent },
1451     { WM_CTLCOLORDLG, sent|defwinproc },
1452     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1453     { WM_PAINT, sent },
1454     /* (bunch of WM_CTLCOLOR* for each control) */
1455     { WM_PAINT, sent|parent },
1456     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1457     { WM_SETCURSOR, sent|parent },
1458     { 0 }
1459 };
1460 /* SetMenu for NonVisible windows with size change*/
1461 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1462     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1463     { WM_NCCALCSIZE, sent|wparam, 1 },
1464     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1465     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1466     { WM_MOVE, sent|defwinproc },
1467     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1468     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1469     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1470     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1471     { WM_GETTEXT, sent|optional },
1472     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1473     { 0 }
1474 };
1475 /* SetMenu for NonVisible windows with no size change */
1476 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1477     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1478     { WM_NCCALCSIZE, sent|wparam, 1 },
1479     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1480     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1481     { 0 }
1482 };
1483 /* SetMenu for Visible windows with size change */
1484 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1485     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1486     { WM_NCCALCSIZE, sent|wparam, 1 },
1487     { 0x0093, sent|defwinproc|optional },
1488     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1489     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1490     { 0x0093, sent|defwinproc|optional },
1491     { 0x0093, sent|defwinproc|optional },
1492     { 0x0091, sent|defwinproc|optional },
1493     { 0x0092, sent|defwinproc|optional },
1494     { WM_GETTEXT, sent|defwinproc|optional },
1495     { WM_ERASEBKGND, sent|optional },
1496     { WM_ACTIVATE, sent|optional },
1497     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1498     { WM_MOVE, sent|defwinproc },
1499     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1500     { 0x0093, sent|optional },
1501     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1502     { 0x0093, sent|defwinproc|optional },
1503     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1504     { 0x0093, sent|defwinproc|optional },
1505     { 0x0093, sent|defwinproc|optional },
1506     { 0x0091, sent|defwinproc|optional },
1507     { 0x0092, sent|defwinproc|optional },
1508     { WM_ERASEBKGND, sent|optional },
1509     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1510     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1511     { 0 }
1512 };
1513 /* SetMenu for Visible windows with no size change */
1514 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1515     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1516     { WM_NCCALCSIZE, sent|wparam, 1 },
1517     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1518     { WM_GETTEXT, sent|defwinproc|optional },
1519     { WM_ERASEBKGND, sent|optional },
1520     { WM_ACTIVATE, sent|optional },
1521     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1522     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1523     { 0 }
1524 };
1525 /* DrawMenuBar for a visible window */
1526 static const struct message WmDrawMenuBarSeq[] =
1527 {
1528     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1529     { WM_NCCALCSIZE, sent|wparam, 1 },
1530     { 0x0093, sent|defwinproc|optional },
1531     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1532     { 0x0093, sent|defwinproc|optional },
1533     { 0x0093, sent|defwinproc|optional },
1534     { 0x0091, sent|defwinproc|optional },
1535     { 0x0092, sent|defwinproc|optional },
1536     { WM_GETTEXT, sent|defwinproc|optional },
1537     { WM_ERASEBKGND, sent|optional },
1538     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1539     { 0x0093, sent|optional },
1540     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1541     { 0 }
1542 };
1543
1544 static const struct message WmSetRedrawFalseSeq[] =
1545 {
1546     { WM_SETREDRAW, sent|wparam, 0 },
1547     { 0 }
1548 };
1549
1550 static const struct message WmSetRedrawTrueSeq[] =
1551 {
1552     { WM_SETREDRAW, sent|wparam, 1 },
1553     { 0 }
1554 };
1555
1556 static const struct message WmEnableWindowSeq_1[] =
1557 {
1558     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1559     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1560     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1561     { 0 }
1562 };
1563
1564 static const struct message WmEnableWindowSeq_2[] =
1565 {
1566     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1567     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1568     { 0 }
1569 };
1570
1571 static const struct message WmGetScrollRangeSeq[] =
1572 {
1573     { SBM_GETRANGE, sent },
1574     { 0 }
1575 };
1576 static const struct message WmGetScrollInfoSeq[] =
1577 {
1578     { SBM_GETSCROLLINFO, sent },
1579     { 0 }
1580 };
1581 static const struct message WmSetScrollRangeSeq[] =
1582 {
1583     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1584        sends SBM_SETSCROLLINFO.
1585      */
1586     { SBM_SETSCROLLINFO, sent },
1587     { 0 }
1588 };
1589 /* SetScrollRange for a window without a non-client area */
1590 static const struct message WmSetScrollRangeHSeq_empty[] =
1591 {
1592     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1593     { 0 }
1594 };
1595 static const struct message WmSetScrollRangeVSeq_empty[] =
1596 {
1597     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1598     { 0 }
1599 };
1600 static const struct message WmSetScrollRangeHVSeq[] =
1601 {
1602     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1603     { WM_NCCALCSIZE, sent|wparam, 1 },
1604     { WM_GETTEXT, sent|defwinproc|optional },
1605     { WM_ERASEBKGND, sent|optional },
1606     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1607     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1608     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1609     { 0 }
1610 };
1611 /* SetScrollRange for a window with a non-client area */
1612 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1613 {
1614     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1615     { WM_NCCALCSIZE, sent|wparam, 1 },
1616     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1617     { WM_NCPAINT, sent|optional },
1618     { WM_STYLECHANGING, sent|defwinproc|optional },
1619     { WM_STYLECHANGED, sent|defwinproc|optional },
1620     { WM_STYLECHANGING, sent|defwinproc|optional },
1621     { WM_STYLECHANGED, sent|defwinproc|optional },
1622     { WM_STYLECHANGING, sent|defwinproc|optional },
1623     { WM_STYLECHANGED, sent|defwinproc|optional },
1624     { WM_STYLECHANGING, sent|defwinproc|optional },
1625     { WM_STYLECHANGED, sent|defwinproc|optional },
1626     { WM_GETTEXT, sent|defwinproc|optional },
1627     { WM_GETTEXT, sent|defwinproc|optional },
1628     { WM_ERASEBKGND, sent|optional },
1629     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1630     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1631     { WM_SIZE, sent|defwinproc|optional },
1632     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1633     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1634     { WM_GETTEXT, sent|optional },
1635     { WM_GETTEXT, sent|optional },
1636     { WM_GETTEXT, sent|optional },
1637     { WM_GETTEXT, sent|optional },
1638     { 0 }
1639 };
1640 /* test if we receive the right sequence of messages */
1641 /* after calling ShowWindow( SW_SHOWNA) */
1642 static const struct message WmSHOWNAChildInvisParInvis[] = {
1643     { WM_SHOWWINDOW, sent|wparam, 1 },
1644     { 0 }
1645 };
1646 static const struct message WmSHOWNAChildVisParInvis[] = {
1647     { WM_SHOWWINDOW, sent|wparam, 1 },
1648     { 0 }
1649 };
1650 static const struct message WmSHOWNAChildVisParVis[] = {
1651     { WM_SHOWWINDOW, sent|wparam, 1 },
1652     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1653     { 0 }
1654 };
1655 static const struct message WmSHOWNAChildInvisParVis[] = {
1656     { WM_SHOWWINDOW, sent|wparam, 1 },
1657     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1658     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1659     { WM_ERASEBKGND, sent|optional },
1660     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1661     { 0 }
1662 };
1663 static const struct message WmSHOWNATopVisible[] = {
1664     { WM_SHOWWINDOW, sent|wparam, 1 },
1665     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1666     { WM_NCPAINT, sent|wparam|optional, 1 },
1667     { WM_GETTEXT, sent|defwinproc|optional },
1668     { WM_ERASEBKGND, sent|optional },
1669     { WM_WINDOWPOSCHANGED, sent|optional },
1670     { 0 }
1671 };
1672 static const struct message WmSHOWNATopInvisible[] = {
1673     { WM_NOTIFYFORMAT, sent|optional },
1674     { WM_QUERYUISTATE, sent|optional },
1675     { WM_WINDOWPOSCHANGING, sent|optional },
1676     { WM_GETMINMAXINFO, sent|optional },
1677     { WM_NCCALCSIZE, sent|optional },
1678     { WM_WINDOWPOSCHANGED, sent|optional },
1679     { WM_SHOWWINDOW, sent|wparam, 1 },
1680     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1681     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1682     { WM_NCPAINT, sent|wparam|optional, 1 },
1683     { WM_GETTEXT, sent|defwinproc|optional },
1684     { WM_ERASEBKGND, sent|optional },
1685     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1686     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1687     { WM_NCPAINT, sent|wparam|optional, 1 },
1688     { WM_ERASEBKGND, sent|optional },
1689     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1690     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1691     { WM_MOVE, sent },
1692     { 0 }
1693 };
1694
1695 static int after_end_dialog, test_def_id;
1696 static int sequence_cnt, sequence_size;
1697 static struct recvd_message* sequence;
1698 static int log_all_parent_messages;
1699 static int paint_loop_done;
1700
1701 /* user32 functions */
1702 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1703 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1704 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1705 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1706 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1707 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1708 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1709 /* kernel32 functions */
1710 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1711
1712 static void init_procs(void)
1713 {
1714     HMODULE user32 = GetModuleHandleA("user32.dll");
1715     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1716
1717 #define GET_PROC(dll, func) \
1718     p ## func = (void*)GetProcAddress(dll, #func); \
1719     if(!p ## func) { \
1720       trace("GetProcAddress(%s) failed\n", #func); \
1721     }
1722
1723     GET_PROC(user32, GetAncestor)
1724     GET_PROC(user32, GetMenuInfo)
1725     GET_PROC(user32, NotifyWinEvent)
1726     GET_PROC(user32, SetMenuInfo)
1727     GET_PROC(user32, SetWinEventHook)
1728     GET_PROC(user32, TrackMouseEvent)
1729     GET_PROC(user32, UnhookWinEvent)
1730
1731     GET_PROC(kernel32, GetCPInfoExA)
1732
1733 #undef GET_PROC
1734 }
1735
1736 static const char *get_winpos_flags(UINT flags)
1737 {
1738     static char buffer[300];
1739
1740     buffer[0] = 0;
1741 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1742     DUMP( SWP_SHOWWINDOW );
1743     DUMP( SWP_HIDEWINDOW );
1744     DUMP( SWP_NOACTIVATE );
1745     DUMP( SWP_FRAMECHANGED );
1746     DUMP( SWP_NOCOPYBITS );
1747     DUMP( SWP_NOOWNERZORDER );
1748     DUMP( SWP_NOSENDCHANGING );
1749     DUMP( SWP_DEFERERASE );
1750     DUMP( SWP_ASYNCWINDOWPOS );
1751     DUMP( SWP_NOZORDER );
1752     DUMP( SWP_NOREDRAW );
1753     DUMP( SWP_NOSIZE );
1754     DUMP( SWP_NOMOVE );
1755     DUMP( SWP_NOCLIENTSIZE );
1756     DUMP( SWP_NOCLIENTMOVE );
1757     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1758     return buffer + 1;
1759 #undef DUMP
1760 }
1761
1762
1763 #define add_message(msg) add_message_(__LINE__,msg);
1764 static void add_message_(int line, const struct recvd_message *msg)
1765 {
1766     struct recvd_message *seq;
1767
1768     if (!sequence) 
1769     {
1770         sequence_size = 10;
1771         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1772     }
1773     if (sequence_cnt == sequence_size) 
1774     {
1775         sequence_size *= 2;
1776         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1777     }
1778     assert(sequence);
1779
1780     seq = &sequence[sequence_cnt];
1781     seq->hwnd = msg->hwnd;
1782     seq->message = msg->message;
1783     seq->flags = msg->flags;
1784     seq->wParam = msg->wParam;
1785     seq->lParam = msg->lParam;
1786     seq->line   = line;
1787     seq->descr  = msg->descr;
1788     seq->output[0] = 0;
1789
1790     if (msg->descr)
1791     {
1792         if (msg->flags & hook)
1793         {
1794             static const char * const CBT_code_name[10] =
1795             {
1796                 "HCBT_MOVESIZE",
1797                 "HCBT_MINMAX",
1798                 "HCBT_QS",
1799                 "HCBT_CREATEWND",
1800                 "HCBT_DESTROYWND",
1801                 "HCBT_ACTIVATE",
1802                 "HCBT_CLICKSKIPPED",
1803                 "HCBT_KEYSKIPPED",
1804                 "HCBT_SYSCOMMAND",
1805                 "HCBT_SETFOCUS"
1806             };
1807             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1808
1809             sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1810                      msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1811         }
1812         else if (msg->flags & winevent_hook)
1813         {
1814             sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1815                      msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1816         }
1817         else
1818         {
1819             switch (msg->message)
1820             {
1821             case WM_WINDOWPOSCHANGING:
1822             case WM_WINDOWPOSCHANGED:
1823             {
1824                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1825
1826                 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1827                           msg->descr, msg->hwnd,
1828                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1829                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1830                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1831                           get_winpos_flags(winpos->flags) );
1832
1833                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1834                  * in the high word for internal purposes
1835                  */
1836                 seq->wParam = winpos->flags & 0xffff;
1837                 /* We are not interested in the flags that don't match under XP and Win9x */
1838                 seq->wParam &= ~SWP_NOZORDER;
1839                 break;
1840             }
1841
1842             case WM_DRAWITEM:
1843             {
1844                 DRAW_ITEM_STRUCT di;
1845                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1846
1847                 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1848                          msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1849                          dis->itemID, dis->itemAction, dis->itemState);
1850
1851                 di.u.lp = 0;
1852                 di.u.item.type = dis->CtlType;
1853                 di.u.item.ctl_id = dis->CtlID;
1854                 di.u.item.item_id = dis->itemID;
1855                 di.u.item.action = dis->itemAction;
1856                 di.u.item.state = dis->itemState;
1857
1858                 seq->lParam = di.u.lp;
1859                 break;
1860             }
1861             default:
1862                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1863                 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1864                          msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1865             }
1866         }
1867     }
1868
1869     sequence_cnt++;
1870 }
1871
1872 /* try to make sure pending X events have been processed before continuing */
1873 static void flush_events(void)
1874 {
1875     MSG msg;
1876     int diff = 200;
1877     int min_timeout = 100;
1878     DWORD time = GetTickCount() + diff;
1879
1880     while (diff > 0)
1881     {
1882         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1883         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1884         diff = time - GetTickCount();
1885     }
1886 }
1887
1888 static void flush_sequence(void)
1889 {
1890     HeapFree(GetProcessHeap(), 0, sequence);
1891     sequence = 0;
1892     sequence_cnt = sequence_size = 0;
1893 }
1894
1895 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1896 {
1897     const struct recvd_message *actual = sequence;
1898     unsigned int count = 0;
1899
1900     trace_(file, line)("Failed sequence %s:\n", context );
1901     while (expected->message && actual->message)
1902     {
1903         if (actual->output[0])
1904         {
1905             if (expected->flags & hook)
1906             {
1907                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1908                                     count, expected->message, actual->output );
1909             }
1910             else if (expected->flags & winevent_hook)
1911             {
1912                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1913                                     count, expected->message, actual->output );
1914             }
1915             else
1916             {
1917                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1918                                     count, expected->message, actual->output );
1919             }
1920         }
1921
1922         if (expected->message == actual->message)
1923         {
1924             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1925                 (expected->flags & optional))
1926             {
1927                 /* don't match messages if their defwinproc status differs */
1928                 expected++;
1929             }
1930             else
1931             {
1932                 expected++;
1933                 actual++;
1934             }
1935         }
1936         /* silently drop winevent messages if there is no support for them */
1937         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1938             expected++;
1939         else
1940         {
1941             expected++;
1942             actual++;
1943         }
1944         count++;
1945     }
1946
1947     /* optional trailing messages */
1948     while (expected->message && ((expected->flags & optional) ||
1949             ((expected->flags & winevent_hook) && !hEvent_hook)))
1950     {
1951         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1952         expected++;
1953         count++;
1954     }
1955
1956     if (expected->message)
1957     {
1958         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1959         return;
1960     }
1961
1962     while (actual->message && actual->output[0])
1963     {
1964         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1965         actual++;
1966         count++;
1967     }
1968 }
1969
1970 #define ok_sequence( exp, contx, todo) \
1971         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1972
1973
1974 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1975                          const char *file, int line)
1976 {
1977     static const struct recvd_message end_of_sequence;
1978     const struct message *expected = expected_list;
1979     const struct recvd_message *actual;
1980     int failcount = 0, dump = 0;
1981     unsigned int count = 0;
1982
1983     add_message(&end_of_sequence);
1984
1985     actual = sequence;
1986
1987     while (expected->message && actual->message)
1988     {
1989         if (expected->message == actual->message)
1990         {
1991             if (expected->flags & wparam)
1992             {
1993                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1994                 {
1995                     todo_wine {
1996                         failcount ++;
1997                         if (strcmp(winetest_platform, "wine")) dump++;
1998                         ok_( file, line) (FALSE,
1999                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2000                             context, count, expected->message, expected->wParam, actual->wParam);
2001                     }
2002                 }
2003                 else
2004                 {
2005                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2006                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2007                                      context, count, expected->message, expected->wParam, actual->wParam);
2008                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2009                 }
2010
2011             }
2012             if (expected->flags & lparam)
2013             {
2014                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2015                 {
2016                     todo_wine {
2017                         failcount ++;
2018                         if (strcmp(winetest_platform, "wine")) dump++;
2019                         ok_( file, line) (FALSE,
2020                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2021                             context, count, expected->message, expected->lParam, actual->lParam);
2022                     }
2023                 }
2024                 else
2025                 {
2026                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2027                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2028                                      context, count, expected->message, expected->lParam, actual->lParam);
2029                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2030                 }
2031             }
2032             if ((expected->flags & optional) &&
2033                 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2034             {
2035                 /* don't match optional messages if their defwinproc or parent status differs */
2036                 expected++;
2037                 count++;
2038                 continue;
2039             }
2040             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2041             {
2042                     todo_wine {
2043                         failcount ++;
2044                         if (strcmp(winetest_platform, "wine")) dump++;
2045                         ok_( file, line) (FALSE,
2046                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2047                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2048                     }
2049             }
2050             else
2051             {
2052                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2053                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2054                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2055                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2056             }
2057
2058             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2059                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2060                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2061             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2062
2063             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2064                 "%s: %u: the msg 0x%04x should have been %s\n",
2065                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2066             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2067
2068             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2069                 "%s: %u: the msg 0x%04x was expected in %s\n",
2070                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2071             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2072
2073             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2074                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2075                 context, count, expected->message);
2076             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2077
2078             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2079                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2080                 context, count, expected->message);
2081             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2082
2083             expected++;
2084             actual++;
2085         }
2086         /* silently drop hook messages if there is no support for them */
2087         else if ((expected->flags & optional) ||
2088                  ((expected->flags & hook) && !hCBT_hook) ||
2089                  ((expected->flags & winevent_hook) && !hEvent_hook))
2090             expected++;
2091         else if (todo)
2092         {
2093             failcount++;
2094             todo_wine {
2095                 if (strcmp(winetest_platform, "wine")) dump++;
2096                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2097                                   context, count, expected->message, actual->message);
2098             }
2099             goto done;
2100         }
2101         else
2102         {
2103             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2104                               context, count, expected->message, actual->message);
2105             dump++;
2106             expected++;
2107             actual++;
2108         }
2109         count++;
2110     }
2111
2112     /* skip all optional trailing messages */
2113     while (expected->message && ((expected->flags & optional) ||
2114                                  ((expected->flags & hook) && !hCBT_hook) ||
2115                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2116         expected++;
2117
2118     if (todo)
2119     {
2120         todo_wine {
2121             if (expected->message || actual->message) {
2122                 failcount++;
2123                 if (strcmp(winetest_platform, "wine")) dump++;
2124                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2125                                   context, count, expected->message, actual->message);
2126             }
2127         }
2128     }
2129     else
2130     {
2131         if (expected->message || actual->message)
2132         {
2133             dump++;
2134             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2135                               context, count, expected->message, actual->message);
2136         }
2137     }
2138     if( todo && !failcount) /* succeeded yet marked todo */
2139         todo_wine {
2140             if (!strcmp(winetest_platform, "wine")) dump++;
2141             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2142         }
2143
2144 done:
2145     if (dump) dump_sequence(expected_list, context, file, line);
2146     flush_sequence();
2147 }
2148
2149 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2150
2151 /******************************** MDI test **********************************/
2152
2153 /* CreateWindow for MDI frame window, initially visible */
2154 static const struct message WmCreateMDIframeSeq[] = {
2155     { HCBT_CREATEWND, hook },
2156     { WM_GETMINMAXINFO, sent },
2157     { WM_NCCREATE, sent },
2158     { WM_NCCALCSIZE, sent|wparam, 0 },
2159     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2160     { WM_CREATE, sent },
2161     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2162     { WM_NOTIFYFORMAT, sent|optional },
2163     { WM_QUERYUISTATE, sent|optional },
2164     { WM_WINDOWPOSCHANGING, sent|optional },
2165     { WM_GETMINMAXINFO, sent|optional },
2166     { WM_NCCALCSIZE, sent|optional },
2167     { WM_WINDOWPOSCHANGED, sent|optional },
2168     { WM_SHOWWINDOW, sent|wparam, 1 },
2169     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2170     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2171     { HCBT_ACTIVATE, hook },
2172     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2173     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2174     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2175     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2176     { WM_NCACTIVATE, sent },
2177     { WM_GETTEXT, sent|defwinproc|optional },
2178     { WM_ACTIVATE, sent|wparam, 1 },
2179     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2180     { HCBT_SETFOCUS, hook },
2181     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2182     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2183     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2184     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2185     /* Win9x adds SWP_NOZORDER below */
2186     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2187     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2188     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2189     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2190     { WM_MOVE, sent },
2191     { 0 }
2192 };
2193 /* DestroyWindow for MDI frame window, initially visible */
2194 static const struct message WmDestroyMDIframeSeq[] = {
2195     { HCBT_DESTROYWND, hook },
2196     { 0x0090, sent|optional },
2197     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2198     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2199     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2200     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2201     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2202     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2203     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2204     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2205     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2206     { WM_DESTROY, sent },
2207     { WM_NCDESTROY, sent },
2208     { 0 }
2209 };
2210 /* CreateWindow for MDI client window, initially visible */
2211 static const struct message WmCreateMDIclientSeq[] = {
2212     { HCBT_CREATEWND, hook },
2213     { WM_NCCREATE, sent },
2214     { WM_NCCALCSIZE, sent|wparam, 0 },
2215     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2216     { WM_CREATE, sent },
2217     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2218     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2219     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2220     { WM_MOVE, sent },
2221     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2222     { WM_SHOWWINDOW, sent|wparam, 1 },
2223     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2224     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2225     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2226     { 0 }
2227 };
2228 /* ShowWindow(SW_SHOW) for MDI client window */
2229 static const struct message WmShowMDIclientSeq[] = {
2230     { WM_SHOWWINDOW, sent|wparam, 1 },
2231     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2232     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2233     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2234     { 0 }
2235 };
2236 /* ShowWindow(SW_HIDE) for MDI client window */
2237 static const struct message WmHideMDIclientSeq[] = {
2238     { WM_SHOWWINDOW, sent|wparam, 0 },
2239     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2240     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2241     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2242     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2243     { 0 }
2244 };
2245 /* DestroyWindow for MDI client window, initially visible */
2246 static const struct message WmDestroyMDIclientSeq[] = {
2247     { HCBT_DESTROYWND, hook },
2248     { 0x0090, sent|optional },
2249     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2250     { WM_SHOWWINDOW, sent|wparam, 0 },
2251     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2252     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2253     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2254     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2255     { WM_DESTROY, sent },
2256     { WM_NCDESTROY, sent },
2257     { 0 }
2258 };
2259 /* CreateWindow for MDI child window, initially visible */
2260 static const struct message WmCreateMDIchildVisibleSeq[] = {
2261     { HCBT_CREATEWND, hook },
2262     { WM_NCCREATE, sent }, 
2263     { WM_NCCALCSIZE, sent|wparam, 0 },
2264     { WM_CREATE, sent },
2265     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2266     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2267     { WM_MOVE, sent },
2268     /* Win2k sends wparam set to
2269      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2270      * while Win9x doesn't bother to set child window id according to
2271      * CLIENTCREATESTRUCT.idFirstChild
2272      */
2273     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2274     { WM_SHOWWINDOW, sent|wparam, 1 },
2275     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2277     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2278     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2279     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2280     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2281     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2282
2283     /* Win9x: message sequence terminates here. */
2284
2285     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2286     { HCBT_SETFOCUS, hook }, /* in MDI client */
2287     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2288     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2289     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2290     { WM_SETFOCUS, sent }, /* in MDI client */
2291     { HCBT_SETFOCUS, hook },
2292     { WM_KILLFOCUS, sent }, /* in MDI client */
2293     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2294     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2295     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2296     { WM_SETFOCUS, sent|defwinproc },
2297     { WM_MDIACTIVATE, sent|defwinproc },
2298     { 0 }
2299 };
2300 /* CreateWindow for MDI child window with invisible parent */
2301 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2302     { HCBT_CREATEWND, hook },
2303     { WM_GETMINMAXINFO, sent },
2304     { WM_NCCREATE, sent }, 
2305     { WM_NCCALCSIZE, sent|wparam, 0 },
2306     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2307     { WM_CREATE, sent },
2308     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2309     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2310     { WM_MOVE, sent },
2311     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2312     { WM_SHOWWINDOW, sent|wparam, 1 },
2313     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2314     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2315     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2316     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2317
2318     /* Win9x: message sequence terminates here. */
2319
2320     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2321     { HCBT_SETFOCUS, hook }, /* in MDI client */
2322     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2323     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2324     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2325     { WM_SETFOCUS, sent }, /* in MDI client */
2326     { HCBT_SETFOCUS, hook },
2327     { WM_KILLFOCUS, sent }, /* in MDI client */
2328     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2329     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2330     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2331     { WM_SETFOCUS, sent|defwinproc },
2332     { WM_MDIACTIVATE, sent|defwinproc },
2333     { 0 }
2334 };
2335 /* DestroyWindow for MDI child window, initially visible */
2336 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2337     { HCBT_DESTROYWND, hook },
2338     /* Win2k sends wparam set to
2339      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2340      * while Win9x doesn't bother to set child window id according to
2341      * CLIENTCREATESTRUCT.idFirstChild
2342      */
2343     { 0x0090, sent|optional },
2344     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2345     { WM_SHOWWINDOW, sent|wparam, 0 },
2346     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2347     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2348     { WM_ERASEBKGND, sent|parent|optional },
2349     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2350
2351     /* { WM_DESTROY, sent }
2352      * Win9x: message sequence terminates here.
2353      */
2354
2355     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2356     { WM_KILLFOCUS, sent },
2357     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2358     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2359     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2360     { WM_SETFOCUS, sent }, /* in MDI client */
2361
2362     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2363     { WM_KILLFOCUS, sent }, /* in MDI client */
2364     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2365     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2366     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2367     { WM_SETFOCUS, sent }, /* in MDI client */
2368
2369     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2370
2371     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2372     { WM_KILLFOCUS, sent },
2373     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2374     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2375     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2376     { WM_SETFOCUS, sent }, /* in MDI client */
2377
2378     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2379     { WM_KILLFOCUS, sent }, /* in MDI client */
2380     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2381     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2382     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2383     { WM_SETFOCUS, sent }, /* in MDI client */
2384
2385     { WM_DESTROY, sent },
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     { WM_NCDESTROY, sent },
2402     { 0 }
2403 };
2404 /* CreateWindow for MDI child window, initially invisible */
2405 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2406     { HCBT_CREATEWND, hook },
2407     { WM_NCCREATE, sent }, 
2408     { WM_NCCALCSIZE, sent|wparam, 0 },
2409     { WM_CREATE, sent },
2410     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2411     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2412     { WM_MOVE, sent },
2413     /* Win2k sends wparam set to
2414      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2415      * while Win9x doesn't bother to set child window id according to
2416      * CLIENTCREATESTRUCT.idFirstChild
2417      */
2418     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2419     { 0 }
2420 };
2421 /* DestroyWindow for MDI child window, initially invisible */
2422 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2423     { HCBT_DESTROYWND, hook },
2424     /* Win2k sends wparam set to
2425      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2426      * while Win9x doesn't bother to set child window id according to
2427      * CLIENTCREATESTRUCT.idFirstChild
2428      */
2429     { 0x0090, sent|optional },
2430     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2431     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2432     { WM_DESTROY, sent },
2433     { WM_NCDESTROY, sent },
2434     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2435     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2436     { 0 }
2437 };
2438 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2439 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2440     { HCBT_CREATEWND, hook },
2441     { WM_NCCREATE, sent }, 
2442     { WM_NCCALCSIZE, sent|wparam, 0 },
2443     { WM_CREATE, sent },
2444     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2445     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2446     { WM_MOVE, sent },
2447     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2448     { WM_GETMINMAXINFO, sent },
2449     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2450     { WM_NCCALCSIZE, sent|wparam, 1 },
2451     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2452     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2453      /* in MDI frame */
2454     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2455     { WM_NCCALCSIZE, sent|wparam, 1 },
2456     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2457     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2459     /* Win2k sends wparam set to
2460      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2461      * while Win9x doesn't bother to set child window id according to
2462      * CLIENTCREATESTRUCT.idFirstChild
2463      */
2464     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2465     { WM_SHOWWINDOW, sent|wparam, 1 },
2466     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2467     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2468     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2469     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2471     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2472     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2473
2474     /* Win9x: message sequence terminates here. */
2475
2476     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2477     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2478     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2479     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2480     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2481     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2482     { HCBT_SETFOCUS, hook|optional },
2483     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2484     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2485     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2486     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2487     { WM_SETFOCUS, sent|defwinproc|optional },
2488     { WM_MDIACTIVATE, sent|defwinproc|optional },
2489      /* in MDI frame */
2490     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2491     { WM_NCCALCSIZE, sent|wparam, 1 },
2492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2493     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2494     { 0 }
2495 };
2496 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2497 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2498     /* restore the 1st MDI child */
2499     { WM_SETREDRAW, sent|wparam, 0 },
2500     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2501     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2502     { WM_NCCALCSIZE, sent|wparam, 1 },
2503     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2504     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2505     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2506      /* in MDI frame */
2507     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2508     { WM_NCCALCSIZE, sent|wparam, 1 },
2509     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2510     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2511     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2512     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2513     /* create the 2nd MDI child */
2514     { HCBT_CREATEWND, hook },
2515     { WM_NCCREATE, sent }, 
2516     { WM_NCCALCSIZE, sent|wparam, 0 },
2517     { WM_CREATE, sent },
2518     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2519     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2520     { WM_MOVE, sent },
2521     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2522     { WM_GETMINMAXINFO, sent },
2523     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2524     { WM_NCCALCSIZE, sent|wparam, 1 },
2525     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2526     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2527     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2528      /* in MDI frame */
2529     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2530     { WM_NCCALCSIZE, sent|wparam, 1 },
2531     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2532     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2533     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2534     /* Win2k sends wparam set to
2535      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2536      * while Win9x doesn't bother to set child window id according to
2537      * CLIENTCREATESTRUCT.idFirstChild
2538      */
2539     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2540     { WM_SHOWWINDOW, sent|wparam, 1 },
2541     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2542     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2543     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2544     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2545     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2546     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2547
2548     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2549     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2550
2551     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2552
2553     /* Win9x: message sequence terminates here. */
2554
2555     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2556     { HCBT_SETFOCUS, hook },
2557     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2558     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2559     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2560     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2561     { WM_SETFOCUS, sent }, /* in MDI client */
2562     { HCBT_SETFOCUS, hook },
2563     { WM_KILLFOCUS, sent }, /* in MDI client */
2564     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2565     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2566     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2567     { WM_SETFOCUS, sent|defwinproc },
2568
2569     { WM_MDIACTIVATE, sent|defwinproc },
2570      /* in MDI frame */
2571     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2572     { WM_NCCALCSIZE, sent|wparam, 1 },
2573     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2574     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2575     { 0 }
2576 };
2577 /* WM_MDICREATE MDI child window, initially visible and maximized */
2578 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2579     { WM_MDICREATE, sent },
2580     { HCBT_CREATEWND, hook },
2581     { WM_NCCREATE, sent }, 
2582     { WM_NCCALCSIZE, sent|wparam, 0 },
2583     { WM_CREATE, sent },
2584     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2585     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2586     { WM_MOVE, sent },
2587     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2588     { WM_GETMINMAXINFO, sent },
2589     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2590     { WM_NCCALCSIZE, sent|wparam, 1 },
2591     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2592     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2593
2594      /* in MDI frame */
2595     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2596     { WM_NCCALCSIZE, sent|wparam, 1 },
2597     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2598     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2599     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2600
2601     /* Win2k sends wparam set to
2602      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2603      * while Win9x doesn't bother to set child window id according to
2604      * CLIENTCREATESTRUCT.idFirstChild
2605      */
2606     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2607     { WM_SHOWWINDOW, sent|wparam, 1 },
2608     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2609
2610     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2611
2612     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2613     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2614     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2615
2616     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2617     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2618
2619     /* Win9x: message sequence terminates here. */
2620
2621     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2622     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2623     { HCBT_SETFOCUS, hook }, /* in MDI client */
2624     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2625     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2626     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2627     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2628     { HCBT_SETFOCUS, hook|optional },
2629     { WM_KILLFOCUS, sent }, /* in MDI client */
2630     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2631     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2632     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2633     { WM_SETFOCUS, sent|defwinproc },
2634
2635     { WM_MDIACTIVATE, sent|defwinproc },
2636
2637      /* in MDI child */
2638     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2639     { WM_NCCALCSIZE, sent|wparam, 1 },
2640     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2641     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2642
2643      /* in MDI frame */
2644     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2645     { WM_NCCALCSIZE, sent|wparam, 1 },
2646     { 0x0093, sent|defwinproc|optional },
2647     { 0x0093, sent|defwinproc|optional },
2648     { 0x0093, sent|defwinproc|optional },
2649     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2650     { WM_MOVE, sent|defwinproc },
2651     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2652
2653      /* in MDI client */
2654     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2655     { WM_NCCALCSIZE, sent|wparam, 1 },
2656     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2657     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2658
2659      /* in MDI child */
2660     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2661     { WM_NCCALCSIZE, sent|wparam, 1 },
2662     { 0x0093, sent|optional },
2663     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2664     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2665
2666     { 0x0093, sent|optional },
2667     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2668     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2669     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2670     { 0x0093, sent|defwinproc|optional },
2671     { 0x0093, sent|defwinproc|optional },
2672     { 0x0093, sent|defwinproc|optional },
2673     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2674     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2675
2676     { 0 }
2677 };
2678 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2679 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2680     { HCBT_CREATEWND, hook },
2681     { WM_GETMINMAXINFO, sent },
2682     { WM_NCCREATE, sent }, 
2683     { WM_NCCALCSIZE, sent|wparam, 0 },
2684     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2685     { WM_CREATE, sent },
2686     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2687     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2688     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2689     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2690     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2691     { WM_MOVE, sent },
2692     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2693     { WM_GETMINMAXINFO, sent },
2694     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2695     { WM_GETMINMAXINFO, sent|defwinproc },
2696     { WM_NCCALCSIZE, sent|wparam, 1 },
2697     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2698     { WM_MOVE, sent|defwinproc },
2699     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2700      /* in MDI frame */
2701     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2702     { WM_NCCALCSIZE, sent|wparam, 1 },
2703     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2704     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2705     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2706     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2707     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2708     /* Win2k sends wparam set to
2709      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2710      * while Win9x doesn't bother to set child window id according to
2711      * CLIENTCREATESTRUCT.idFirstChild
2712      */
2713     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2714     { 0 }
2715 };
2716 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2717 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2718     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2719     { HCBT_SYSCOMMAND, hook },
2720     { WM_CLOSE, sent|defwinproc },
2721     { WM_MDIDESTROY, sent }, /* in MDI client */
2722
2723     /* bring the 1st MDI child to top */
2724     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2725     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2726
2727     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2728
2729     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2730     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2731     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2732
2733     /* maximize the 1st MDI child */
2734     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2735     { WM_GETMINMAXINFO, sent|defwinproc },
2736     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2737     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2738     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2739     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2740     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2741
2742     /* restore the 2nd MDI child */
2743     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2744     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2745     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2746     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2747
2748     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2749
2750     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2751     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2752
2753     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2754
2755     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2756      /* in MDI frame */
2757     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2758     { WM_NCCALCSIZE, sent|wparam, 1 },
2759     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2760     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2761     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2762
2763     /* bring the 1st MDI child to top */
2764     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2765     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2766     { HCBT_SETFOCUS, hook },
2767     { WM_KILLFOCUS, sent|defwinproc },
2768     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2769     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2770     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2771     { WM_SETFOCUS, sent }, /* in MDI client */
2772     { HCBT_SETFOCUS, hook },
2773     { WM_KILLFOCUS, sent }, /* in MDI client */
2774     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2775     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2776     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2777     { WM_SETFOCUS, sent|defwinproc },
2778     { WM_MDIACTIVATE, sent|defwinproc },
2779     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2780
2781     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2782     { WM_SHOWWINDOW, sent|wparam, 1 },
2783     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2784     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2785     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2786     { WM_MDIREFRESHMENU, sent },
2787
2788     { HCBT_DESTROYWND, hook },
2789     /* Win2k sends wparam set to
2790      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2791      * while Win9x doesn't bother to set child window id according to
2792      * CLIENTCREATESTRUCT.idFirstChild
2793      */
2794     { 0x0090, sent|defwinproc|optional },
2795     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2796     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2797     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2798     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2799     { WM_ERASEBKGND, sent|parent|optional },
2800     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2801
2802     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2803     { WM_DESTROY, sent|defwinproc },
2804     { WM_NCDESTROY, sent|defwinproc },
2805     { 0 }
2806 };
2807 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2808 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2809     { WM_MDIDESTROY, sent }, /* in MDI client */
2810     { WM_SHOWWINDOW, sent|wparam, 0 },
2811     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2812     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2813     { WM_ERASEBKGND, sent|parent|optional },
2814     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2815
2816     { HCBT_SETFOCUS, hook },
2817     { WM_KILLFOCUS, sent },
2818     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2819     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2820     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2821     { WM_SETFOCUS, sent }, /* in MDI client */
2822     { HCBT_SETFOCUS, hook },
2823     { WM_KILLFOCUS, sent }, /* in MDI client */
2824     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2825     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2826     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2827     { WM_SETFOCUS, sent },
2828
2829      /* in MDI child */
2830     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2831     { WM_NCCALCSIZE, sent|wparam, 1 },
2832     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2833     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2834
2835      /* in MDI frame */
2836     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2837     { WM_NCCALCSIZE, sent|wparam, 1 },
2838     { 0x0093, sent|defwinproc|optional },
2839     { 0x0093, sent|defwinproc|optional },
2840     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2841     { WM_MOVE, sent|defwinproc },
2842     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2843
2844      /* in MDI client */
2845     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2846     { WM_NCCALCSIZE, sent|wparam, 1 },
2847     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2848     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2849
2850      /* in MDI child */
2851     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2852     { WM_NCCALCSIZE, sent|wparam, 1 },
2853     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2854     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2855
2856      /* in MDI child */
2857     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2858     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2859     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2860     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2861
2862      /* in MDI frame */
2863     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2864     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2865     { 0x0093, sent|defwinproc|optional },
2866     { 0x0093, sent|defwinproc|optional },
2867     { 0x0093, sent|defwinproc|optional },
2868     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2869     { WM_MOVE, sent|defwinproc },
2870     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2871
2872      /* in MDI client */
2873     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2874     { WM_NCCALCSIZE, sent|wparam, 1 },
2875     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2876     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2877
2878      /* in MDI child */
2879     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2880     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2881     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2882     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2883     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2884     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2885
2886     { 0x0093, sent|defwinproc|optional },
2887     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2888     { 0x0093, sent|defwinproc|optional },
2889     { 0x0093, sent|defwinproc|optional },
2890     { 0x0093, sent|defwinproc|optional },
2891     { 0x0093, sent|optional },
2892
2893     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2894     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2895     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2896     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2897     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2898
2899      /* in MDI frame */
2900     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2901     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2902     { 0x0093, sent|defwinproc|optional },
2903     { 0x0093, sent|defwinproc|optional },
2904     { 0x0093, sent|defwinproc|optional },
2905     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2906     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2907     { 0x0093, sent|optional },
2908
2909     { WM_NCACTIVATE, sent|wparam, 0 },
2910     { WM_MDIACTIVATE, sent },
2911
2912     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2913     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2914     { WM_NCCALCSIZE, sent|wparam, 1 },
2915
2916     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2917
2918     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2919     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2920     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2921
2922      /* in MDI child */
2923     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2924     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2925     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2926     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2927
2928      /* in MDI frame */
2929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2930     { WM_NCCALCSIZE, sent|wparam, 1 },
2931     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2932     { WM_MOVE, sent|defwinproc },
2933     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2934
2935      /* in MDI client */
2936     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2937     { WM_NCCALCSIZE, sent|wparam, 1 },
2938     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2939     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2940     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2941     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2942     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2943     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2944     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2945
2946     { HCBT_SETFOCUS, hook },
2947     { WM_KILLFOCUS, sent },
2948     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2949     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2950     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2951     { WM_SETFOCUS, sent }, /* in MDI client */
2952
2953     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2954
2955     { HCBT_DESTROYWND, hook },
2956     /* Win2k sends wparam set to
2957      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2958      * while Win9x doesn't bother to set child window id according to
2959      * CLIENTCREATESTRUCT.idFirstChild
2960      */
2961     { 0x0090, sent|optional },
2962     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2963
2964     { WM_SHOWWINDOW, sent|wparam, 0 },
2965     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2966     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2967     { WM_ERASEBKGND, sent|parent|optional },
2968     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2969
2970     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2971     { WM_DESTROY, sent },
2972     { WM_NCDESTROY, sent },
2973     { 0 }
2974 };
2975 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2976 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2977     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2978     { WM_GETMINMAXINFO, sent },
2979     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2980     { WM_NCCALCSIZE, sent|wparam, 1 },
2981     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2982     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2983
2984     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2985     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2986     { HCBT_SETFOCUS, hook|optional },
2987     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2988     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2989     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2990     { HCBT_SETFOCUS, hook|optional },
2991     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2992     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2993     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2994     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2995     { WM_SETFOCUS, sent|optional|defwinproc },
2996     { WM_MDIACTIVATE, sent|optional|defwinproc },
2997     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2998     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2999      /* in MDI frame */
3000     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3001     { WM_NCCALCSIZE, sent|wparam, 1 },
3002     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3003     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3004     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3005     { 0 }
3006 };
3007 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3008 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3009     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3010     { WM_GETMINMAXINFO, sent },
3011     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3012     { WM_GETMINMAXINFO, sent|defwinproc },
3013     { WM_NCCALCSIZE, sent|wparam, 1 },
3014     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3015     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3016
3017     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3018     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3019     { HCBT_SETFOCUS, hook|optional },
3020     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3021     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3022     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3023     { HCBT_SETFOCUS, hook|optional },
3024     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3025     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3026     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3027     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3028     { WM_SETFOCUS, sent|defwinproc|optional },
3029     { WM_MDIACTIVATE, sent|defwinproc|optional },
3030     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3032     { 0 }
3033 };
3034 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3035 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3036     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3037     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3038     { WM_GETMINMAXINFO, sent },
3039     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3040     { WM_GETMINMAXINFO, sent|defwinproc },
3041     { WM_NCCALCSIZE, sent|wparam, 1 },
3042     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3043     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3044     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3045     { WM_MOVE, sent|defwinproc },
3046     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3047
3048     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3049     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3050     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3051     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3052     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3053     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3054      /* in MDI frame */
3055     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3056     { WM_NCCALCSIZE, sent|wparam, 1 },
3057     { 0x0093, sent|defwinproc|optional },
3058     { 0x0094, sent|defwinproc|optional },
3059     { 0x0094, sent|defwinproc|optional },
3060     { 0x0094, sent|defwinproc|optional },
3061     { 0x0094, sent|defwinproc|optional },
3062     { 0x0093, sent|defwinproc|optional },
3063     { 0x0093, sent|defwinproc|optional },
3064     { 0x0091, sent|defwinproc|optional },
3065     { 0x0092, sent|defwinproc|optional },
3066     { 0x0092, sent|defwinproc|optional },
3067     { 0x0092, sent|defwinproc|optional },
3068     { 0x0092, sent|defwinproc|optional },
3069     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3070     { WM_MOVE, sent|defwinproc },
3071     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3072     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3073      /* in MDI client */
3074     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3075     { WM_NCCALCSIZE, sent|wparam, 1 },
3076     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3077     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3078      /* in MDI child */
3079     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3080     { WM_GETMINMAXINFO, sent|defwinproc },
3081     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3082     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3083     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3084     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3085     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3086     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3087     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3088     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3089      /* in MDI frame */
3090     { 0x0093, sent|optional },
3091     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3092     { 0x0093, sent|defwinproc|optional },
3093     { 0x0093, sent|defwinproc|optional },
3094     { 0x0093, sent|defwinproc|optional },
3095     { 0x0091, sent|defwinproc|optional },
3096     { 0x0092, sent|defwinproc|optional },
3097     { 0x0092, sent|defwinproc|optional },
3098     { 0x0092, sent|defwinproc|optional },
3099     { 0x0092, sent|defwinproc|optional },
3100     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3101     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3102     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3103     { 0 }
3104 };
3105 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3106 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3107     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3108     { WM_GETMINMAXINFO, sent },
3109     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3110     { WM_NCCALCSIZE, sent|wparam, 1 },
3111     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3112     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3113     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3114      /* in MDI frame */
3115     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3116     { WM_NCCALCSIZE, sent|wparam, 1 },
3117     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3118     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3119     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3120     { 0 }
3121 };
3122 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3123 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3124     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3125     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3126     { WM_NCCALCSIZE, sent|wparam, 1 },
3127     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3128     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3129     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3130      /* in MDI frame */
3131     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3132     { WM_NCCALCSIZE, sent|wparam, 1 },
3133     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3134     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3135     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3136     { 0 }
3137 };
3138 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3139 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3140     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3141     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3142     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3143     { WM_NCCALCSIZE, sent|wparam, 1 },
3144     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3145     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3146     { WM_MOVE, sent|defwinproc },
3147     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3148     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3149     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3150     { HCBT_SETFOCUS, hook },
3151     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3152     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3153     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3154     { WM_SETFOCUS, sent },
3155     { 0 }
3156 };
3157 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3158 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3159     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3160     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3161     { WM_NCCALCSIZE, sent|wparam, 1 },
3162     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3163     { WM_MOVE, sent|defwinproc },
3164     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3165     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3166     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3167     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3168     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3169     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3170     { 0 }
3171 };
3172 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3173 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3174     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3175     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3176     { WM_NCCALCSIZE, sent|wparam, 1 },
3177     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3178     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3179     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3180     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3181      /* in MDI frame */
3182     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3183     { WM_NCCALCSIZE, sent|wparam, 1 },
3184     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3185     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3186     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3187     { 0 }
3188 };
3189
3190 static HWND mdi_client;
3191 static WNDPROC old_mdi_client_proc;
3192
3193 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3194 {
3195     struct recvd_message msg;
3196
3197     /* do not log painting messages */
3198     if (message != WM_PAINT &&
3199         message != WM_NCPAINT &&
3200         message != WM_SYNCPAINT &&
3201         message != WM_ERASEBKGND &&
3202         message != WM_NCHITTEST &&
3203         message != WM_GETTEXT &&
3204         message != WM_MDIGETACTIVE &&
3205         message != WM_GETICON &&
3206         message != WM_GETOBJECT &&
3207         message != WM_DEVICECHANGE)
3208     {
3209         msg.hwnd = hwnd;
3210         msg.message = message;
3211         msg.flags = sent|wparam|lparam;
3212         msg.wParam = wParam;
3213         msg.lParam = lParam;
3214         msg.descr = "mdi client";
3215         add_message(&msg);
3216     }
3217
3218     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3219 }
3220
3221 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3222 {
3223     static long defwndproc_counter = 0;
3224     LRESULT ret;
3225     struct recvd_message msg;
3226
3227     /* do not log painting messages */
3228     if (message != WM_PAINT &&
3229         message != WM_NCPAINT &&
3230         message != WM_SYNCPAINT &&
3231         message != WM_ERASEBKGND &&
3232         message != WM_NCHITTEST &&
3233         message != WM_GETTEXT &&
3234         message != WM_GETICON &&
3235         message != WM_GETOBJECT &&
3236         message != WM_DEVICECHANGE)
3237     {
3238         switch (message)
3239         {
3240             case WM_MDIACTIVATE:
3241             {
3242                 HWND active, client = GetParent(hwnd);
3243
3244                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3245
3246                 if (hwnd == (HWND)lParam) /* if we are being activated */
3247                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3248                 else
3249                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3250                 break;
3251             }
3252         }
3253
3254         msg.hwnd = hwnd;
3255         msg.message = message;
3256         msg.flags = sent|wparam|lparam;
3257         if (defwndproc_counter) msg.flags |= defwinproc;
3258         msg.wParam = wParam;
3259         msg.lParam = lParam;
3260         msg.descr = "mdi child";
3261         add_message(&msg);
3262     }
3263
3264     defwndproc_counter++;
3265     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3266     defwndproc_counter--;
3267
3268     return ret;
3269 }
3270
3271 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3272 {
3273     static long defwndproc_counter = 0;
3274     LRESULT ret;
3275     struct recvd_message msg;
3276
3277     /* do not log painting messages */
3278     if (message != WM_PAINT &&
3279         message != WM_NCPAINT &&
3280         message != WM_SYNCPAINT &&
3281         message != WM_ERASEBKGND &&
3282         message != WM_NCHITTEST &&
3283         message != WM_GETTEXT &&
3284         message != WM_GETICON &&
3285         message != WM_GETOBJECT &&
3286         message != WM_DEVICECHANGE)
3287     {
3288         msg.hwnd = hwnd;
3289         msg.message = message;
3290         msg.flags = sent|wparam|lparam;
3291         if (defwndproc_counter) msg.flags |= defwinproc;
3292         msg.wParam = wParam;
3293         msg.lParam = lParam;
3294         msg.descr = "mdi frame";
3295         add_message(&msg);
3296     }
3297
3298     defwndproc_counter++;
3299     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3300     defwndproc_counter--;
3301
3302     return ret;
3303 }
3304
3305 static BOOL mdi_RegisterWindowClasses(void)
3306 {
3307     WNDCLASSA cls;
3308
3309     cls.style = 0;
3310     cls.lpfnWndProc = mdi_frame_wnd_proc;
3311     cls.cbClsExtra = 0;
3312     cls.cbWndExtra = 0;
3313     cls.hInstance = GetModuleHandleA(0);
3314     cls.hIcon = 0;
3315     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3316     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3317     cls.lpszMenuName = NULL;
3318     cls.lpszClassName = "MDI_frame_class";
3319     if (!RegisterClassA(&cls)) return FALSE;
3320
3321     cls.lpfnWndProc = mdi_child_wnd_proc;
3322     cls.lpszClassName = "MDI_child_class";
3323     if (!RegisterClassA(&cls)) return FALSE;
3324
3325     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3326     old_mdi_client_proc = cls.lpfnWndProc;
3327     cls.hInstance = GetModuleHandleA(0);
3328     cls.lpfnWndProc = mdi_client_hook_proc;
3329     cls.lpszClassName = "MDI_client_class";
3330     if (!RegisterClassA(&cls)) assert(0);
3331
3332     return TRUE;
3333 }
3334
3335 static void test_mdi_messages(void)
3336 {
3337     MDICREATESTRUCTA mdi_cs;
3338     CLIENTCREATESTRUCT client_cs;
3339     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3340     BOOL zoomed;
3341     HMENU hMenu = CreateMenu();
3342
3343     assert(mdi_RegisterWindowClasses());
3344
3345     flush_sequence();
3346
3347     trace("creating MDI frame window\n");
3348     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3349                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3350                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3351                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3352                                 GetDesktopWindow(), hMenu,
3353                                 GetModuleHandleA(0), NULL);
3354     assert(mdi_frame);
3355     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3356
3357     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3358     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3359
3360     trace("creating MDI client window\n");
3361     client_cs.hWindowMenu = 0;
3362     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3363     mdi_client = CreateWindowExA(0, "MDI_client_class",
3364                                  NULL,
3365                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3366                                  0, 0, 0, 0,
3367                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3368     assert(mdi_client);
3369     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3370
3371     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3372     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3373
3374     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3375     ok(!active_child, "wrong active MDI child %p\n", active_child);
3376     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3377
3378     SetFocus(0);
3379     flush_sequence();
3380
3381     trace("creating invisible MDI child window\n");
3382     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3383                                 WS_CHILD,
3384                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3385                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3386     assert(mdi_child);
3387
3388     flush_sequence();
3389     ShowWindow(mdi_child, SW_SHOWNORMAL);
3390     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3391
3392     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3393     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3394
3395     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3396     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3397
3398     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3399     ok(!active_child, "wrong active MDI child %p\n", active_child);
3400     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3401
3402     ShowWindow(mdi_child, SW_HIDE);
3403     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3404     flush_sequence();
3405
3406     ShowWindow(mdi_child, SW_SHOW);
3407     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3408
3409     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3410     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3411
3412     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3413     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3414
3415     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3416     ok(!active_child, "wrong active MDI child %p\n", active_child);
3417     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3418
3419     DestroyWindow(mdi_child);
3420     flush_sequence();
3421
3422     trace("creating visible MDI child window\n");
3423     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3424                                 WS_CHILD | WS_VISIBLE,
3425                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3426                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3427     assert(mdi_child);
3428     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3429
3430     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3431     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3432
3433     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3434     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3435
3436     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3437     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3438     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3439     flush_sequence();
3440
3441     DestroyWindow(mdi_child);
3442     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3443
3444     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3445     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3446
3447     /* Win2k: MDI client still returns a just destroyed child as active
3448      * Win9x: MDI client returns 0
3449      */
3450     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3451     ok(active_child == mdi_child || /* win2k */
3452        !active_child, /* win9x */
3453        "wrong active MDI child %p\n", active_child);
3454     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3455
3456     flush_sequence();
3457
3458     trace("creating invisible MDI child window\n");
3459     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3460                                 WS_CHILD,
3461                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3462                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3463     assert(mdi_child2);
3464     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3465
3466     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3467     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3468
3469     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3470     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3471
3472     /* Win2k: MDI client still returns a just destroyed child as active
3473      * Win9x: MDI client returns mdi_child2
3474      */
3475     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3476     ok(active_child == mdi_child || /* win2k */
3477        active_child == mdi_child2, /* win9x */
3478        "wrong active MDI child %p\n", active_child);
3479     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3480     flush_sequence();
3481
3482     ShowWindow(mdi_child2, SW_MAXIMIZE);
3483     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3484
3485     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3486     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3487
3488     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3489     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3490     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3491     flush_sequence();
3492
3493     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3494     ok(GetFocus() == mdi_child2 || /* win2k */
3495        GetFocus() == 0, /* win9x */
3496        "wrong focus window %p\n", GetFocus());
3497
3498     SetFocus(0);
3499     flush_sequence();
3500
3501     ShowWindow(mdi_child2, SW_HIDE);
3502     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3503
3504     ShowWindow(mdi_child2, SW_RESTORE);
3505     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3506     flush_sequence();
3507
3508     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3509     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3510
3511     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3512     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3513     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3514     flush_sequence();
3515
3516     SetFocus(0);
3517     flush_sequence();
3518
3519     ShowWindow(mdi_child2, SW_HIDE);
3520     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3521
3522     ShowWindow(mdi_child2, SW_SHOW);
3523     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3524
3525     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3526     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3527
3528     ShowWindow(mdi_child2, SW_MAXIMIZE);
3529     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3530
3531     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3532     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3533
3534     ShowWindow(mdi_child2, SW_RESTORE);
3535     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3536
3537     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3538     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3539
3540     ShowWindow(mdi_child2, SW_MINIMIZE);
3541     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3542
3543     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3544     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3545
3546     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3547     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3548     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3549     flush_sequence();
3550
3551     ShowWindow(mdi_child2, SW_RESTORE);
3552     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3553
3554     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3555     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3556
3557     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3558     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3559     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3560     flush_sequence();
3561
3562     SetFocus(0);
3563     flush_sequence();
3564
3565     ShowWindow(mdi_child2, SW_HIDE);
3566     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3567
3568     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3569     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3570
3571     DestroyWindow(mdi_child2);
3572     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3573
3574     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3575     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3576
3577     /* test for maximized MDI children */
3578     trace("creating maximized visible MDI child window 1\n");
3579     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3580                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3581                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3582                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3583     assert(mdi_child);
3584     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3585     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3586
3587     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3588     ok(GetFocus() == mdi_child || /* win2k */
3589        GetFocus() == 0, /* win9x */
3590        "wrong focus window %p\n", GetFocus());
3591
3592     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3593     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3594     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3595     flush_sequence();
3596
3597     trace("creating maximized visible MDI child window 2\n");
3598     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3599                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3600                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3601                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3602     assert(mdi_child2);
3603     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3604     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3605     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3606
3607     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3608     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3609
3610     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3611     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3612     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3613     flush_sequence();
3614
3615     trace("destroying maximized visible MDI child window 2\n");
3616     DestroyWindow(mdi_child2);
3617     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3618
3619     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3620
3621     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3622     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3623
3624     /* Win2k: MDI client still returns a just destroyed child as active
3625      * Win9x: MDI client returns 0
3626      */
3627     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3628     ok(active_child == mdi_child2 || /* win2k */
3629        !active_child, /* win9x */
3630        "wrong active MDI child %p\n", active_child);
3631     flush_sequence();
3632
3633     ShowWindow(mdi_child, SW_MAXIMIZE);
3634     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3635     flush_sequence();
3636
3637     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3638     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3639
3640     trace("re-creating maximized visible MDI child window 2\n");
3641     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3642                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3643                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3644                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3645     assert(mdi_child2);
3646     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3647     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3648     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3649
3650     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3651     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3652
3653     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3654     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3655     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3656     flush_sequence();
3657
3658     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3659     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3660     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3661
3662     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3663     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3664     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3665
3666     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3667     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3668     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3669     flush_sequence();
3670
3671     DestroyWindow(mdi_child);
3672     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3673
3674     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3675     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3676
3677     /* Win2k: MDI client still returns a just destroyed child as active
3678      * Win9x: MDI client returns 0
3679      */
3680     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3681     ok(active_child == mdi_child || /* win2k */
3682        !active_child, /* win9x */
3683        "wrong active MDI child %p\n", active_child);
3684     flush_sequence();
3685
3686     trace("creating maximized invisible MDI child window\n");
3687     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3688                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3689                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3690                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3691     assert(mdi_child2);
3692     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3693     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3694     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3695     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3696
3697     /* Win2k: MDI client still returns a just destroyed child as active
3698      * Win9x: MDI client returns 0
3699      */
3700     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3701     ok(active_child == mdi_child || /* win2k */
3702        !active_child || active_child == mdi_child2, /* win9x */
3703        "wrong active MDI child %p\n", active_child);
3704     flush_sequence();
3705
3706     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3707     ShowWindow(mdi_child2, SW_MAXIMIZE);
3708     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3709     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3710     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3711     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3712
3713     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3714     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3715     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3716     flush_sequence();
3717
3718     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3719     flush_sequence();
3720
3721     /* end of test for maximized MDI children */
3722     SetFocus(0);
3723     flush_sequence();
3724     trace("creating maximized visible MDI child window 1(Switch test)\n");
3725     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3726                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3727                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3728                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3729     assert(mdi_child);
3730     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3731     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3732
3733     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3734     ok(GetFocus() == mdi_child || /* win2k */
3735        GetFocus() == 0, /* win9x */
3736        "wrong focus window %p(Switch test)\n", GetFocus());
3737
3738     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3739     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3740     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3741     flush_sequence();
3742
3743     trace("creating maximized visible MDI child window 2(Switch test)\n");
3744     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3745                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3746                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3747                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3748     assert(mdi_child2);
3749     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3750
3751     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3752     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3753
3754     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3755     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3756
3757     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3758     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3759     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3760     flush_sequence();
3761
3762     trace("Switch child window.\n");
3763     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3764     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3765     trace("end of test for switch maximized MDI children\n");
3766     flush_sequence();
3767
3768     /* Prepare for switching test of not maximized MDI children  */
3769     ShowWindow( mdi_child, SW_NORMAL );
3770     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3771     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3772     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3773     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3774     flush_sequence();
3775
3776     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3777     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3778     trace("end of test for switch not maximized MDI children\n");
3779     flush_sequence();
3780
3781     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3782     flush_sequence();
3783
3784     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3785     flush_sequence();
3786
3787     SetFocus(0);
3788     flush_sequence();
3789     /* end of tests for switch maximized/not maximized MDI children */
3790
3791     mdi_cs.szClass = "MDI_child_Class";
3792     mdi_cs.szTitle = "MDI child";
3793     mdi_cs.hOwner = GetModuleHandleA(0);
3794     mdi_cs.x = 0;
3795     mdi_cs.y = 0;
3796     mdi_cs.cx = CW_USEDEFAULT;
3797     mdi_cs.cy = CW_USEDEFAULT;
3798     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3799     mdi_cs.lParam = 0;
3800     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3801     ok(mdi_child != 0, "MDI child creation failed\n");
3802     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3803
3804     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3805
3806     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3807     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3808
3809     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3810     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3811     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3812
3813     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3814     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3815     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3816     flush_sequence();
3817
3818     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3819     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3820
3821     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3822     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3823     ok(!active_child, "wrong active MDI child %p\n", active_child);
3824
3825     SetFocus(0);
3826     flush_sequence();
3827
3828     DestroyWindow(mdi_client);
3829     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3830
3831     /* test maximization of MDI child with invisible parent */
3832     client_cs.hWindowMenu = 0;
3833     mdi_client = CreateWindow("MDI_client_class",
3834                                  NULL,
3835                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3836                                  0, 0, 660, 430,
3837                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3838     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3839
3840     ShowWindow(mdi_client, SW_HIDE);
3841     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3842
3843     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3844                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3845                                 0, 0, 650, 440,
3846                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3847     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3848
3849     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3850     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3851     zoomed = IsZoomed(mdi_child);
3852     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3853     
3854     ShowWindow(mdi_client, SW_SHOW);
3855     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3856
3857     DestroyWindow(mdi_child);
3858     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3859
3860     /* end of test for maximization of MDI child with invisible parent */
3861
3862     DestroyWindow(mdi_client);
3863     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3864
3865     DestroyWindow(mdi_frame);
3866     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3867 }
3868 /************************* End of MDI test **********************************/
3869
3870 static void test_WM_SETREDRAW(HWND hwnd)
3871 {
3872     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3873
3874     flush_events();
3875     flush_sequence();
3876
3877     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3878     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3879
3880     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3881     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3882
3883     flush_sequence();
3884     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3885     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3886
3887     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3888     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3889
3890     /* restore original WS_VISIBLE state */
3891     SetWindowLongA(hwnd, GWL_STYLE, style);
3892
3893     flush_events();
3894     flush_sequence();
3895 }
3896
3897 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3898 {
3899     struct recvd_message msg;
3900
3901     switch (message)
3902     {
3903         /* ignore */
3904         case WM_GETICON:
3905         case WM_GETOBJECT:
3906         case WM_MOUSEMOVE:
3907         case WM_NCMOUSEMOVE:
3908         case WM_NCMOUSELEAVE:
3909         case WM_SETCURSOR:
3910         case WM_DEVICECHANGE:
3911             return 0;
3912         case WM_NCHITTEST:
3913             return HTCLIENT;
3914     }
3915
3916     msg.hwnd = hwnd;
3917     msg.message = message;
3918     msg.flags = sent|wparam|lparam;
3919     msg.wParam = wParam;
3920     msg.lParam = lParam;
3921     msg.descr = "dialog";
3922     add_message(&msg);
3923
3924     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3925     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3926     return 0;
3927 }
3928
3929 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3930 {
3931     DWORD style, exstyle;
3932     INT xmin, xmax;
3933     BOOL ret;
3934
3935     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3936     style = GetWindowLongA(hwnd, GWL_STYLE);
3937     /* do not be confused by WS_DLGFRAME set */
3938     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3939
3940     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3941     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3942
3943     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3944     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3945     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3946         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3947     else
3948         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3949
3950     style = GetWindowLongA(hwnd, GWL_STYLE);
3951     if (set) ok(style & set, "style %08x should be set\n", set);
3952     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3953
3954     /* a subsequent call should do nothing */
3955     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3956     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3957     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3958
3959     xmin = 0xdeadbeef;
3960     xmax = 0xdeadbeef;
3961     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3962     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3963     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3964     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3965     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3966     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3967 }
3968
3969 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3970 {
3971     DWORD style, exstyle;
3972     SCROLLINFO si;
3973     BOOL ret;
3974
3975     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3976     style = GetWindowLongA(hwnd, GWL_STYLE);
3977     /* do not be confused by WS_DLGFRAME set */
3978     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3979
3980     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3981     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3982
3983     si.cbSize = sizeof(si);
3984     si.fMask = SIF_RANGE;
3985     si.nMin = min;
3986     si.nMax = max;
3987     SetScrollInfo(hwnd, ctl, &si, TRUE);
3988     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3989         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3990     else
3991         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3992
3993     style = GetWindowLongA(hwnd, GWL_STYLE);
3994     if (set) ok(style & set, "style %08x should be set\n", set);
3995     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3996
3997     /* a subsequent call should do nothing */
3998     SetScrollInfo(hwnd, ctl, &si, TRUE);
3999     if (style & WS_HSCROLL)
4000         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4001     else if (style & WS_VSCROLL)
4002         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4003     else
4004         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4005
4006     si.fMask = SIF_PAGE;
4007     si.nPage = 5;
4008     SetScrollInfo(hwnd, ctl, &si, FALSE);
4009     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4010
4011     si.fMask = SIF_POS;
4012     si.nPos = max - 1;
4013     SetScrollInfo(hwnd, ctl, &si, FALSE);
4014     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4015
4016     si.fMask = SIF_RANGE;
4017     si.nMin = 0xdeadbeef;
4018     si.nMax = 0xdeadbeef;
4019     ret = GetScrollInfo(hwnd, ctl, &si);
4020     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4021     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4022     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4023     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4024 }
4025
4026 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4027 static void test_scroll_messages(HWND hwnd)
4028 {
4029     SCROLLINFO si;
4030     INT min, max;
4031     BOOL ret;
4032
4033     flush_events();
4034     flush_sequence();
4035
4036     min = 0xdeadbeef;
4037     max = 0xdeadbeef;
4038     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4039     ok( ret, "GetScrollRange error %d\n", GetLastError());
4040     if (sequence->message != WmGetScrollRangeSeq[0].message)
4041         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4042     /* values of min and max are undefined */
4043     flush_sequence();
4044
4045     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4046     ok( ret, "SetScrollRange error %d\n", GetLastError());
4047     if (sequence->message != WmSetScrollRangeSeq[0].message)
4048         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4049     flush_sequence();
4050
4051     min = 0xdeadbeef;
4052     max = 0xdeadbeef;
4053     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4054     ok( ret, "GetScrollRange error %d\n", GetLastError());
4055     if (sequence->message != WmGetScrollRangeSeq[0].message)
4056         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4057     /* values of min and max are undefined */
4058     flush_sequence();
4059
4060     si.cbSize = sizeof(si);
4061     si.fMask = SIF_RANGE;
4062     si.nMin = 20;
4063     si.nMax = 160;
4064     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4065     if (sequence->message != WmSetScrollRangeSeq[0].message)
4066         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4067     flush_sequence();
4068
4069     si.fMask = SIF_PAGE;
4070     si.nPage = 10;
4071     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4072     if (sequence->message != WmSetScrollRangeSeq[0].message)
4073         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4074     flush_sequence();
4075
4076     si.fMask = SIF_POS;
4077     si.nPos = 20;
4078     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4079     if (sequence->message != WmSetScrollRangeSeq[0].message)
4080         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4081     flush_sequence();
4082
4083     si.fMask = SIF_RANGE;
4084     si.nMin = 0xdeadbeef;
4085     si.nMax = 0xdeadbeef;
4086     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4087     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4088     if (sequence->message != WmGetScrollInfoSeq[0].message)
4089         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4090     /* values of min and max are undefined */
4091     flush_sequence();
4092
4093     /* set WS_HSCROLL */
4094     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4095     /* clear WS_HSCROLL */
4096     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4097
4098     /* set WS_HSCROLL */
4099     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4100     /* clear WS_HSCROLL */
4101     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4102
4103     /* set WS_VSCROLL */
4104     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4105     /* clear WS_VSCROLL */
4106     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4107
4108     /* set WS_VSCROLL */
4109     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4110     /* clear WS_VSCROLL */
4111     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4112 }
4113
4114 static void test_showwindow(void)
4115 {
4116     HWND hwnd, hchild;
4117     RECT rc;
4118
4119     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4120                            100, 100, 200, 200, 0, 0, 0, NULL);
4121     ok (hwnd != 0, "Failed to create overlapped window\n");
4122     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4123                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4124     ok (hchild != 0, "Failed to create child\n");
4125     flush_sequence();
4126
4127     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4128     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4129     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4130     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4131
4132     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4133     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4134     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4135     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4136     /* back to invisible */
4137     ShowWindow(hchild, SW_HIDE);
4138     ShowWindow(hwnd, SW_HIDE);
4139     flush_sequence();
4140     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4141     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4142     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4143     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4144     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4145     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4146     flush_sequence();
4147     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4148     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4149     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4150     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4151     ShowWindow( hwnd, SW_SHOW);
4152     flush_sequence();
4153     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4154     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4155     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4156
4157     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4158     ShowWindow( hchild, SW_HIDE);
4159     flush_sequence();
4160     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4161     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4162     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4163
4164     SetCapture(hchild);
4165     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4166     DestroyWindow(hchild);
4167     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4168
4169     DestroyWindow(hwnd);
4170     flush_sequence();
4171
4172     /* Popup windows */
4173     /* Test 1:
4174      * 1. Create invisible maximized popup window.
4175      * 2. Move and resize it.
4176      * 3. Show it maximized.
4177      */
4178     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4179     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4180                            100, 100, 200, 200, 0, 0, 0, NULL);
4181     ok (hwnd != 0, "Failed to create popup window\n");
4182     ok(IsZoomed(hwnd), "window should be maximized\n");
4183     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4184
4185     GetWindowRect(hwnd, &rc);
4186     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4187         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4188         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4189         rc.left, rc.top, rc.right, rc.bottom);
4190     /* Reset window's size & position */
4191     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4192     ok(IsZoomed(hwnd), "window should be maximized\n");
4193     flush_sequence();
4194
4195     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4196     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4197     ok(IsZoomed(hwnd), "window should be maximized\n");
4198     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4199
4200     GetWindowRect(hwnd, &rc);
4201     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4202         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4203         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4204         rc.left, rc.top, rc.right, rc.bottom);
4205     DestroyWindow(hwnd);
4206     flush_sequence();
4207
4208     /* Test 2:
4209      * 1. Create invisible maximized popup window.
4210      * 2. Show it maximized.
4211      */
4212     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4213     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4214                            100, 100, 200, 200, 0, 0, 0, NULL);
4215     ok (hwnd != 0, "Failed to create popup window\n");
4216     ok(IsZoomed(hwnd), "window should be maximized\n");
4217     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4218
4219     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4220     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4221     ok(IsZoomed(hwnd), "window should be maximized\n");
4222     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4223     DestroyWindow(hwnd);
4224     flush_sequence();
4225
4226     /* Test 3:
4227      * 1. Create visible maximized popup window.
4228      */
4229     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4230     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4231                            100, 100, 200, 200, 0, 0, 0, NULL);
4232     ok (hwnd != 0, "Failed to create popup window\n");
4233     ok(IsZoomed(hwnd), "window should be maximized\n");
4234     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4235     DestroyWindow(hwnd);
4236     flush_sequence();
4237
4238     /* Test 4:
4239      * 1. Create visible popup window.
4240      * 2. Maximize it.
4241      */
4242     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4243     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4244                            100, 100, 200, 200, 0, 0, 0, NULL);
4245     ok (hwnd != 0, "Failed to create popup window\n");
4246     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4247     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4248
4249     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4250     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4251     ok(IsZoomed(hwnd), "window should be maximized\n");
4252     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4253     DestroyWindow(hwnd);
4254     flush_sequence();
4255 }
4256
4257 static void test_sys_menu(void)
4258 {
4259     HWND hwnd;
4260     HMENU hmenu;
4261     UINT state;
4262
4263     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4264                            100, 100, 200, 200, 0, 0, 0, NULL);
4265     ok (hwnd != 0, "Failed to create overlapped window\n");
4266
4267     flush_sequence();
4268
4269     /* test existing window without CS_NOCLOSE style */
4270     hmenu = GetSystemMenu(hwnd, FALSE);
4271     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4272
4273     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4274     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4275     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4276
4277     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4278     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4279
4280     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4281     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4282     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4283
4284     EnableMenuItem(hmenu, SC_CLOSE, 0);
4285     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4286
4287     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4288     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4289     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4290
4291     /* test whether removing WS_SYSMENU destroys a system menu */
4292     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4293     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4294     flush_sequence();
4295     hmenu = GetSystemMenu(hwnd, FALSE);
4296     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4297
4298     DestroyWindow(hwnd);
4299
4300     /* test new window with CS_NOCLOSE style */
4301     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4302                            100, 100, 200, 200, 0, 0, 0, NULL);
4303     ok (hwnd != 0, "Failed to create overlapped window\n");
4304
4305     hmenu = GetSystemMenu(hwnd, FALSE);
4306     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4307
4308     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4309     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4310
4311     DestroyWindow(hwnd);
4312
4313     /* test new window without WS_SYSMENU style */
4314     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4315                            100, 100, 200, 200, 0, 0, 0, NULL);
4316     ok(hwnd != 0, "Failed to create overlapped window\n");
4317
4318     hmenu = GetSystemMenu(hwnd, FALSE);
4319     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4320
4321     DestroyWindow(hwnd);
4322 }
4323
4324 /* For shown WS_OVERLAPPEDWINDOW */
4325 static const struct message WmSetIcon_1[] = {
4326     { WM_SETICON, sent },
4327     { 0x00AE, sent|defwinproc|optional }, /* XP */
4328     { WM_GETTEXT, sent|defwinproc|optional },
4329     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4330     { 0 }
4331 };
4332
4333 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4334 static const struct message WmSetIcon_2[] = {
4335     { WM_SETICON, sent },
4336     { 0 }
4337 };
4338
4339 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4340 static const struct message WmInitEndSession[] = {
4341     { 0x003B, sent },
4342     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4343     { 0 }
4344 };
4345
4346 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4347 static const struct message WmInitEndSession_2[] = {
4348     { 0x003B, sent },
4349     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4350     { 0 }
4351 };
4352
4353 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4354 static const struct message WmInitEndSession_3[] = {
4355     { 0x003B, sent },
4356     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4357     { 0 }
4358 };
4359
4360 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4361 static const struct message WmInitEndSession_4[] = {
4362     { 0x003B, sent },
4363     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4364     { 0 }
4365 };
4366
4367 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4368 static const struct message WmInitEndSession_5[] = {
4369     { 0x003B, sent },
4370     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4371     { 0 }
4372 };
4373
4374 static const struct message WmOptionalPaint[] = {
4375     { WM_PAINT, sent|optional },
4376     { WM_NCPAINT, sent|beginpaint|optional },
4377     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4378     { WM_ERASEBKGND, sent|beginpaint|optional },
4379     { 0 }
4380 };
4381
4382 static const struct message WmZOrder[] = {
4383     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4384     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4385     { HCBT_ACTIVATE, hook },
4386     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4387     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4388     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4389     { WM_GETTEXT, sent|optional },
4390     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4391     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4392     { WM_NCACTIVATE, sent|lparam, 1, 0 },
4393     { WM_GETTEXT, sent|defwinproc|optional },
4394     { WM_GETTEXT, sent|defwinproc|optional },
4395     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4396     { HCBT_SETFOCUS, hook },
4397     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4398     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4399     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4400     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4401     { WM_GETTEXT, sent|optional },
4402     { WM_NCCALCSIZE, sent|optional },
4403     { 0 }
4404 };
4405
4406 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4407 {
4408     DWORD ret;
4409     MSG msg;
4410
4411     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4412     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4413
4414     PostMessageA(hwnd, WM_USER, 0, 0);
4415
4416     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4417     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4418
4419     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4420     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4421
4422     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4423     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4424
4425     PostMessageA(hwnd, WM_USER, 0, 0);
4426
4427     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4428     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4429
4430     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4431     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4432
4433     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4434     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4435     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4436
4437     PostMessageA(hwnd, WM_USER, 0, 0);
4438
4439     /* new incoming message causes it to become signaled again */
4440     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4441     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4442
4443     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4444     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
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
4449 /* test if we receive the right sequence of messages */
4450 static void test_messages(void)
4451 {
4452     HWND hwnd, hparent, hchild;
4453     HWND hchild2, hbutton;
4454     HMENU hmenu;
4455     MSG msg;
4456     LRESULT res;
4457
4458     flush_sequence();
4459
4460     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4461                            100, 100, 200, 200, 0, 0, 0, NULL);
4462     ok (hwnd != 0, "Failed to create overlapped window\n");
4463     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4464
4465     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4466     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4467     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4468
4469     /* test WM_SETREDRAW on a not visible top level window */
4470     test_WM_SETREDRAW(hwnd);
4471
4472     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4473     flush_events();
4474     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4475     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4476
4477     ok(GetActiveWindow() == hwnd, "window should be active\n");
4478     ok(GetFocus() == hwnd, "window should have input focus\n");
4479     ShowWindow(hwnd, SW_HIDE);
4480     flush_events();
4481     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4482
4483     ShowWindow(hwnd, SW_SHOW);
4484     flush_events();
4485     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4486
4487     ShowWindow(hwnd, SW_HIDE);
4488     flush_events();
4489     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4490
4491     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4492     flush_events();
4493     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4494     flush_sequence();
4495
4496     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4497     {
4498         ShowWindow(hwnd, SW_RESTORE);
4499         flush_events();
4500         ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4501         flush_sequence();
4502     }
4503
4504     ShowWindow(hwnd, SW_MINIMIZE);
4505     flush_events();
4506     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4507     flush_sequence();
4508
4509     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4510     {
4511         ShowWindow(hwnd, SW_RESTORE);
4512         flush_events();
4513         ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4514         flush_sequence();
4515     }
4516
4517     ShowWindow(hwnd, SW_SHOW);
4518     flush_events();
4519     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4520
4521     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4522     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4523     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4524     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4525
4526     /* test WM_SETREDRAW on a visible top level window */
4527     ShowWindow(hwnd, SW_SHOW);
4528     flush_events();
4529     test_WM_SETREDRAW(hwnd);
4530
4531     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4532     test_scroll_messages(hwnd);
4533
4534     /* test resizing and moving */
4535     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4536     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4537     flush_events();
4538     flush_sequence();
4539     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4540     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4541     flush_events();
4542     flush_sequence();
4543     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4544     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4545     flush_events();
4546     flush_sequence();
4547
4548     /* popups don't get WM_GETMINMAXINFO */
4549     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4550     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4551     flush_sequence();
4552     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4553     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4554
4555     DestroyWindow(hwnd);
4556     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4557
4558     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4559                               100, 100, 200, 200, 0, 0, 0, NULL);
4560     ok (hparent != 0, "Failed to create parent window\n");
4561     flush_sequence();
4562
4563     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4564                              0, 0, 10, 10, hparent, 0, 0, NULL);
4565     ok (hchild != 0, "Failed to create child window\n");
4566     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4567     DestroyWindow(hchild);
4568     flush_sequence();
4569
4570     /* visible child window with a caption */
4571     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4572                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4573                              0, 0, 10, 10, hparent, 0, 0, NULL);
4574     ok (hchild != 0, "Failed to create child window\n");
4575     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4576
4577     trace("testing scroll APIs on a visible child window %p\n", hchild);
4578     test_scroll_messages(hchild);
4579
4580     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4581     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4582
4583     DestroyWindow(hchild);
4584     flush_sequence();
4585
4586     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4587                              0, 0, 10, 10, hparent, 0, 0, NULL);
4588     ok (hchild != 0, "Failed to create child window\n");
4589     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4590     
4591     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4592                                100, 100, 50, 50, hparent, 0, 0, NULL);
4593     ok (hchild2 != 0, "Failed to create child2 window\n");
4594     flush_sequence();
4595
4596     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4597                               0, 100, 50, 50, hchild, 0, 0, NULL);
4598     ok (hbutton != 0, "Failed to create button window\n");
4599
4600     /* test WM_SETREDRAW on a not visible child window */
4601     test_WM_SETREDRAW(hchild);
4602
4603     ShowWindow(hchild, SW_SHOW);
4604     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4605
4606     /* check parent messages too */
4607     log_all_parent_messages++;
4608     ShowWindow(hchild, SW_HIDE);
4609     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4610     log_all_parent_messages--;
4611
4612     ShowWindow(hchild, SW_SHOW);
4613     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4614
4615     ShowWindow(hchild, SW_HIDE);
4616     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4617
4618     ShowWindow(hchild, SW_SHOW);
4619     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4620
4621     /* test WM_SETREDRAW on a visible child window */
4622     test_WM_SETREDRAW(hchild);
4623
4624     log_all_parent_messages++;
4625     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4626     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4627     log_all_parent_messages--;
4628
4629     ShowWindow(hchild, SW_HIDE);
4630     flush_sequence();
4631     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4632     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4633
4634     ShowWindow(hchild, SW_HIDE);
4635     flush_sequence();
4636     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4637     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4638
4639     /* DestroyWindow sequence below expects that a child has focus */
4640     SetFocus(hchild);
4641     flush_sequence();
4642
4643     DestroyWindow(hchild);
4644     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4645     DestroyWindow(hchild2);
4646     DestroyWindow(hbutton);
4647
4648     flush_sequence();
4649     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4650                              0, 0, 100, 100, hparent, 0, 0, NULL);
4651     ok (hchild != 0, "Failed to create child popup window\n");
4652     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4653     DestroyWindow(hchild);
4654
4655     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4656     flush_sequence();
4657     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4658                              0, 0, 100, 100, hparent, 0, 0, NULL);
4659     ok (hchild != 0, "Failed to create popup window\n");
4660     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4661     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4662     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4663     flush_sequence();
4664     ShowWindow(hchild, SW_SHOW);
4665     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4666     flush_sequence();
4667     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4668     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4669     flush_sequence();
4670     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4671     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4672     DestroyWindow(hchild);
4673
4674     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4675      * changes nothing in message sequences.
4676      */
4677     flush_sequence();
4678     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4679                              0, 0, 100, 100, hparent, 0, 0, NULL);
4680     ok (hchild != 0, "Failed to create popup window\n");
4681     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4682     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4683     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4684     flush_sequence();
4685     ShowWindow(hchild, SW_SHOW);
4686     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4687     flush_sequence();
4688     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4689     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4690     DestroyWindow(hchild);
4691
4692     flush_sequence();
4693     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4694                            0, 0, 100, 100, hparent, 0, 0, NULL);
4695     ok(hwnd != 0, "Failed to create custom dialog window\n");
4696     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4697
4698     /*
4699     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4700     test_scroll_messages(hwnd);
4701     */
4702
4703     flush_sequence();
4704
4705     test_def_id = 1;
4706     SendMessage(hwnd, WM_NULL, 0, 0);
4707
4708     flush_sequence();
4709     after_end_dialog = 1;
4710     EndDialog( hwnd, 0 );
4711     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4712
4713     DestroyWindow(hwnd);
4714     after_end_dialog = 0;
4715     test_def_id = 0;
4716
4717     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4718                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4719     ok(hwnd != 0, "Failed to create custom dialog window\n");
4720     flush_sequence();
4721     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4722     ShowWindow(hwnd, SW_SHOW);
4723     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4724     DestroyWindow(hwnd);
4725
4726     flush_sequence();
4727     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4728     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4729
4730     DestroyWindow(hparent);
4731     flush_sequence();
4732
4733     /* Message sequence for SetMenu */
4734     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4735     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4736
4737     hmenu = CreateMenu();
4738     ok (hmenu != 0, "Failed to create menu\n");
4739     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4740     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4741                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4742     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4743     ok (SetMenu(hwnd, 0), "SetMenu\n");
4744     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4745     ok (SetMenu(hwnd, 0), "SetMenu\n");
4746     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4747     ShowWindow(hwnd, SW_SHOW);
4748     UpdateWindow( hwnd );
4749     flush_events();
4750     flush_sequence();
4751     ok (SetMenu(hwnd, 0), "SetMenu\n");
4752     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4753     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4754     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4755
4756     UpdateWindow( hwnd );
4757     flush_events();
4758     flush_sequence();
4759     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4760     flush_events();
4761     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4762
4763     DestroyWindow(hwnd);
4764     flush_sequence();
4765
4766     /* Message sequence for EnableWindow */
4767     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4768                               100, 100, 200, 200, 0, 0, 0, NULL);
4769     ok (hparent != 0, "Failed to create parent window\n");
4770     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4771                              0, 0, 10, 10, hparent, 0, 0, NULL);
4772     ok (hchild != 0, "Failed to create child window\n");
4773
4774     SetFocus(hchild);
4775     flush_events();
4776     flush_sequence();
4777
4778     EnableWindow(hparent, FALSE);
4779     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4780
4781     EnableWindow(hparent, TRUE);
4782     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4783
4784     flush_events();
4785     flush_sequence();
4786
4787     test_MsgWaitForMultipleObjects(hparent);
4788
4789     /* the following test causes an exception in user.exe under win9x */
4790     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4791     {
4792         DestroyWindow(hparent);
4793         flush_sequence();
4794         return;
4795     }
4796     PostMessageW( hparent, WM_USER+1, 0, 0 );
4797     /* PeekMessage(NULL) fails, but still removes the message */
4798     SetLastError(0xdeadbeef);
4799     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4800     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4801         GetLastError() == 0xdeadbeef, /* NT4 */
4802         "last error is %d\n", GetLastError() );
4803     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4804     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4805
4806     DestroyWindow(hchild);
4807     DestroyWindow(hparent);
4808     flush_sequence();
4809
4810     /* Message sequences for WM_SETICON */
4811     trace("testing WM_SETICON\n");
4812     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4813                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4814                            NULL, NULL, 0);
4815     ShowWindow(hwnd, SW_SHOW);
4816     UpdateWindow(hwnd);
4817     flush_events();
4818     flush_sequence();
4819     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4820     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4821
4822     ShowWindow(hwnd, SW_HIDE);
4823     flush_events();
4824     flush_sequence();
4825     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4826     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4827     DestroyWindow(hwnd);
4828     flush_sequence();
4829
4830     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4831                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4832                            NULL, NULL, 0);
4833     ShowWindow(hwnd, SW_SHOW);
4834     UpdateWindow(hwnd);
4835     flush_events();
4836     flush_sequence();
4837     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4838     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4839
4840     ShowWindow(hwnd, SW_HIDE);
4841     flush_events();
4842     flush_sequence();
4843     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4844     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4845
4846     flush_sequence();
4847     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4848     if (!res)
4849     {
4850         todo_wine win_skip( "Message 0x3b not supported\n" );
4851         goto done;
4852     }
4853     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4854     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4855     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4856     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4857     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4858     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4859     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4860     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4861
4862     flush_sequence();
4863     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4864     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4865     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4866     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4867     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4868     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4869
4870     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4871     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4872     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4873
4874     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4875     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4876     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4877
4878 done:
4879     DestroyWindow(hwnd);
4880     flush_sequence();
4881 }
4882
4883 static void test_setwindowpos(void)
4884 {
4885     HWND hwnd;
4886     RECT rc;
4887     LRESULT res;
4888     const INT winX = 100;
4889     const INT winY = 100;
4890     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4891
4892     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4893                            0, 0, winX, winY, 0,
4894                            NULL, NULL, 0);
4895
4896     GetWindowRect(hwnd, &rc);
4897     expect(sysX, rc.right);
4898     expect(winY, rc.bottom);
4899
4900     flush_events();
4901     flush_sequence();
4902     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4903     ok_sequence(WmZOrder, "Z-Order", TRUE);
4904     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4905
4906     GetWindowRect(hwnd, &rc);
4907     expect(sysX, rc.right);
4908     expect(winY, rc.bottom);
4909     DestroyWindow(hwnd);
4910 }
4911
4912 static void invisible_parent_tests(void)
4913 {
4914     HWND hparent, hchild;
4915
4916     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4917                               100, 100, 200, 200, 0, 0, 0, NULL);
4918     ok (hparent != 0, "Failed to create parent window\n");
4919     flush_sequence();
4920
4921     /* test showing child with hidden parent */
4922
4923     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4924                              0, 0, 10, 10, hparent, 0, 0, NULL);
4925     ok (hchild != 0, "Failed to create child window\n");
4926     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4927
4928     ShowWindow( hchild, SW_MINIMIZE );
4929     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4930     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4931     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4932
4933     /* repeat */
4934     flush_events();
4935     flush_sequence();
4936     ShowWindow( hchild, SW_MINIMIZE );
4937     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4938
4939     DestroyWindow(hchild);
4940     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4941                              0, 0, 10, 10, hparent, 0, 0, NULL);
4942     flush_sequence();
4943
4944     ShowWindow( hchild, SW_MAXIMIZE );
4945     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4946     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4947     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4948
4949     /* repeat */
4950     flush_events();
4951     flush_sequence();
4952     ShowWindow( hchild, SW_MAXIMIZE );
4953     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4954
4955     DestroyWindow(hchild);
4956     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4957                              0, 0, 10, 10, hparent, 0, 0, NULL);
4958     flush_sequence();
4959
4960     ShowWindow( hchild, SW_RESTORE );
4961     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4962     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4963     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
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_SHOWMINIMIZED );
4971     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) 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_SHOWMINIMIZED );
4979     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) 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     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4987     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4988     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4989     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4990     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4991
4992     DestroyWindow(hchild);
4993     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4994                              0, 0, 10, 10, hparent, 0, 0, NULL);
4995     flush_sequence();
4996
4997     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4998     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4999     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5000     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5001
5002     /* repeat */
5003     flush_events();
5004     flush_sequence();
5005     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5006     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5007
5008     DestroyWindow(hchild);
5009     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5010                              0, 0, 10, 10, hparent, 0, 0, NULL);
5011     flush_sequence();
5012
5013     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5014     ShowWindow( hchild, SW_FORCEMINIMIZE );
5015     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5016 todo_wine {
5017     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5018 }
5019     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5020
5021     DestroyWindow(hchild);
5022     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5023                              0, 0, 10, 10, hparent, 0, 0, NULL);
5024     flush_sequence();
5025
5026     ShowWindow( hchild, SW_SHOWNA );
5027     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5028     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5029     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5030
5031     /* repeat */
5032     flush_events();
5033     flush_sequence();
5034     ShowWindow( hchild, SW_SHOWNA );
5035     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5036
5037     DestroyWindow(hchild);
5038     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5039                              0, 0, 10, 10, hparent, 0, 0, NULL);
5040     flush_sequence();
5041
5042     ShowWindow( hchild, SW_SHOW );
5043     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5044     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5045     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5046
5047     /* repeat */
5048     flush_events();
5049     flush_sequence();
5050     ShowWindow( hchild, SW_SHOW );
5051     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5052
5053     ShowWindow( hchild, SW_HIDE );
5054     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5055     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5056     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5057
5058     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5059     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5060     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5061     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5062
5063     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5064     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5065     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5066     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5067
5068     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5069     flush_sequence();
5070     DestroyWindow(hchild);
5071     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5072
5073     DestroyWindow(hparent);
5074     flush_sequence();
5075 }
5076
5077 /****************** button message test *************************/
5078 static const struct message WmSetFocusButtonSeq[] =
5079 {
5080     { HCBT_SETFOCUS, hook },
5081     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5082     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5083     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5084     { WM_SETFOCUS, sent|wparam, 0 },
5085     { WM_CTLCOLORBTN, sent|defwinproc },
5086     { 0 }
5087 };
5088 static const struct message WmKillFocusButtonSeq[] =
5089 {
5090     { HCBT_SETFOCUS, hook },
5091     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5092     { WM_KILLFOCUS, sent|wparam, 0 },
5093     { WM_CTLCOLORBTN, sent|defwinproc },
5094     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5095     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5096     { 0 }
5097 };
5098 static const struct message WmSetFocusStaticSeq[] =
5099 {
5100     { HCBT_SETFOCUS, hook },
5101     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5102     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5103     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5104     { WM_SETFOCUS, sent|wparam, 0 },
5105     { WM_CTLCOLORSTATIC, sent|defwinproc },
5106     { 0 }
5107 };
5108 static const struct message WmKillFocusStaticSeq[] =
5109 {
5110     { HCBT_SETFOCUS, hook },
5111     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5112     { WM_KILLFOCUS, sent|wparam, 0 },
5113     { WM_CTLCOLORSTATIC, sent|defwinproc },
5114     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5115     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5116     { 0 }
5117 };
5118 static const struct message WmLButtonDownSeq[] =
5119 {
5120     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5121     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5122     { HCBT_SETFOCUS, hook },
5123     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5124     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5125     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5126     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5127     { WM_CTLCOLORBTN, sent|defwinproc },
5128     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5129     { WM_CTLCOLORBTN, sent|defwinproc },
5130     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5131     { 0 }
5132 };
5133 static const struct message WmLButtonUpSeq[] =
5134 {
5135     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5136     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5137     { WM_CTLCOLORBTN, sent|defwinproc },
5138     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5139     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5140     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5141     { 0 }
5142 };
5143 static const struct message WmSetFontButtonSeq[] =
5144 {
5145     { WM_SETFONT, sent },
5146     { WM_PAINT, sent },
5147     { WM_ERASEBKGND, sent|defwinproc|optional },
5148     { WM_CTLCOLORBTN, sent|defwinproc },
5149     { 0 }
5150 };
5151
5152 static WNDPROC old_button_proc;
5153
5154 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5155 {
5156     static long defwndproc_counter = 0;
5157     LRESULT ret;
5158     struct recvd_message msg;
5159
5160     switch (message)
5161     {
5162     case WM_GETICON:
5163     case WM_GETOBJECT:
5164         return 0;  /* ignore them */
5165     case WM_SYNCPAINT:
5166         break;
5167     case BM_SETSTATE:
5168         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5169         /* fall through */
5170     default:
5171         msg.hwnd = hwnd;
5172         msg.message = message;
5173         msg.flags = sent|wparam|lparam;
5174         if (defwndproc_counter) msg.flags |= defwinproc;
5175         msg.wParam = wParam;
5176         msg.lParam = lParam;
5177         msg.descr = "button";
5178         add_message(&msg);
5179     }
5180
5181     defwndproc_counter++;
5182     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5183     defwndproc_counter--;
5184
5185     return ret;
5186 }
5187
5188 static void subclass_button(void)
5189 {
5190     WNDCLASSA cls;
5191
5192     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5193
5194     old_button_proc = cls.lpfnWndProc;
5195
5196     cls.hInstance = GetModuleHandle(0);
5197     cls.lpfnWndProc = button_hook_proc;
5198     cls.lpszClassName = "my_button_class";
5199     UnregisterClass(cls.lpszClassName, cls.hInstance);
5200     if (!RegisterClassA(&cls)) assert(0);
5201 }
5202
5203 static void test_button_messages(void)
5204 {
5205     static const struct
5206     {
5207         DWORD style;
5208         DWORD dlg_code;
5209         const struct message *setfocus;
5210         const struct message *killfocus;
5211     } button[] = {
5212         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5213           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5214         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5215           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5216         { BS_CHECKBOX, DLGC_BUTTON,
5217           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5218         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5219           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5220         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5221           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5222         { BS_3STATE, DLGC_BUTTON,
5223           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5224         { BS_AUTO3STATE, DLGC_BUTTON,
5225           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5226         { BS_GROUPBOX, DLGC_STATIC,
5227           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5228         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5229           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5230         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5231           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5232         { BS_OWNERDRAW, DLGC_BUTTON,
5233           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5234     };
5235     unsigned int i;
5236     HWND hwnd;
5237     DWORD dlg_code;
5238     HFONT zfont;
5239
5240     /* selection with VK_SPACE should capture button window */
5241     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5242                            0, 0, 50, 14, 0, 0, 0, NULL);
5243     ok(hwnd != 0, "Failed to create button window\n");
5244     ReleaseCapture();
5245     SetFocus(hwnd);
5246     SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5247     ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5248     SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5249     DestroyWindow(hwnd);
5250
5251     subclass_button();
5252
5253     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5254     {
5255         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5256                                0, 0, 50, 14, 0, 0, 0, NULL);
5257         ok(hwnd != 0, "Failed to create button window\n");
5258
5259         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5260         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5261
5262         ShowWindow(hwnd, SW_SHOW);
5263         UpdateWindow(hwnd);
5264         SetFocus(0);
5265         flush_sequence();
5266
5267         trace("button style %08x\n", button[i].style);
5268         SetFocus(hwnd);
5269         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5270
5271         SetFocus(0);
5272         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5273
5274         DestroyWindow(hwnd);
5275     }
5276
5277     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5278                            0, 0, 50, 14, 0, 0, 0, NULL);
5279     ok(hwnd != 0, "Failed to create button window\n");
5280
5281     SetForegroundWindow(hwnd);
5282     flush_events();
5283
5284     SetActiveWindow(hwnd);
5285     SetFocus(0);
5286     flush_sequence();
5287
5288     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5289     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5290
5291     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5292     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5293
5294     flush_sequence();
5295     zfont = GetStockObject(SYSTEM_FONT);
5296     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5297     UpdateWindow(hwnd);
5298     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5299
5300     DestroyWindow(hwnd);
5301 }
5302
5303 /****************** static message test *************************/
5304 static const struct message WmSetFontStaticSeq[] =
5305 {
5306     { WM_SETFONT, sent },
5307     { WM_PAINT, sent|defwinproc|optional },
5308     { WM_ERASEBKGND, sent|defwinproc|optional },
5309     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5310     { 0 }
5311 };
5312
5313 static WNDPROC old_static_proc;
5314
5315 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5316 {
5317     static long defwndproc_counter = 0;
5318     LRESULT ret;
5319     struct recvd_message msg;
5320
5321     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5322
5323     msg.hwnd = hwnd;
5324     msg.message = message;
5325     msg.flags = sent|wparam|lparam;
5326     if (defwndproc_counter) msg.flags |= defwinproc;
5327     msg.wParam = wParam;
5328     msg.lParam = lParam;
5329     msg.descr = "static";
5330     add_message(&msg);
5331
5332     defwndproc_counter++;
5333     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5334     defwndproc_counter--;
5335
5336     return ret;
5337 }
5338
5339 static void subclass_static(void)
5340 {
5341     WNDCLASSA cls;
5342
5343     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5344
5345     old_static_proc = cls.lpfnWndProc;
5346
5347     cls.hInstance = GetModuleHandle(0);
5348     cls.lpfnWndProc = static_hook_proc;
5349     cls.lpszClassName = "my_static_class";
5350     UnregisterClass(cls.lpszClassName, cls.hInstance);
5351     if (!RegisterClassA(&cls)) assert(0);
5352 }
5353
5354 static void test_static_messages(void)
5355 {
5356     /* FIXME: make as comprehensive as the button message test */
5357     static const struct
5358     {
5359         DWORD style;
5360         DWORD dlg_code;
5361         const struct message *setfont;
5362     } static_ctrl[] = {
5363         { SS_LEFT, DLGC_STATIC,
5364           WmSetFontStaticSeq }
5365     };
5366     unsigned int i;
5367     HWND hwnd;
5368     DWORD dlg_code;
5369
5370     subclass_static();
5371
5372     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5373     {
5374         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5375                                0, 0, 50, 14, 0, 0, 0, NULL);
5376         ok(hwnd != 0, "Failed to create static window\n");
5377
5378         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5379         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5380
5381         ShowWindow(hwnd, SW_SHOW);
5382         UpdateWindow(hwnd);
5383         SetFocus(0);
5384         flush_sequence();
5385
5386         trace("static style %08x\n", static_ctrl[i].style);
5387         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5388         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5389
5390         DestroyWindow(hwnd);
5391     }
5392 }
5393
5394 /****************** ComboBox message test *************************/
5395 #define ID_COMBOBOX 0x000f
5396
5397 static const struct message WmKeyDownComboSeq[] =
5398 {
5399     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5400     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5401     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5402     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5403     { WM_CTLCOLOREDIT, sent|parent },
5404     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5405     { 0 }
5406 };
5407
5408 static WNDPROC old_combobox_proc;
5409
5410 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5411 {
5412     static long defwndproc_counter = 0;
5413     LRESULT ret;
5414     struct recvd_message msg;
5415
5416     /* do not log painting messages */
5417     if (message != WM_PAINT &&
5418         message != WM_NCPAINT &&
5419         message != WM_SYNCPAINT &&
5420         message != WM_ERASEBKGND &&
5421         message != WM_NCHITTEST &&
5422         message != WM_GETTEXT &&
5423         message != WM_GETICON &&
5424         message != WM_GETOBJECT &&
5425         message != WM_DEVICECHANGE)
5426     {
5427         msg.hwnd = hwnd;
5428         msg.message = message;
5429         msg.flags = sent|wparam|lparam;
5430         if (defwndproc_counter) msg.flags |= defwinproc;
5431         msg.wParam = wParam;
5432         msg.lParam = lParam;
5433         msg.descr = "combo";
5434         add_message(&msg);
5435     }
5436
5437     defwndproc_counter++;
5438     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5439     defwndproc_counter--;
5440
5441     return ret;
5442 }
5443
5444 static void subclass_combobox(void)
5445 {
5446     WNDCLASSA cls;
5447
5448     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5449
5450     old_combobox_proc = cls.lpfnWndProc;
5451
5452     cls.hInstance = GetModuleHandle(0);
5453     cls.lpfnWndProc = combobox_hook_proc;
5454     cls.lpszClassName = "my_combobox_class";
5455     UnregisterClass(cls.lpszClassName, cls.hInstance);
5456     if (!RegisterClassA(&cls)) assert(0);
5457 }
5458
5459 static void test_combobox_messages(void)
5460 {
5461     HWND parent, combo;
5462     LRESULT ret;
5463
5464     subclass_combobox();
5465
5466     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5467                              100, 100, 200, 200, 0, 0, 0, NULL);
5468     ok(parent != 0, "Failed to create parent window\n");
5469     flush_sequence();
5470
5471     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5472                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5473     ok(combo != 0, "Failed to create combobox window\n");
5474
5475     UpdateWindow(combo);
5476
5477     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5478     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5479
5480     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5481     ok(ret == 0, "expected 0, got %ld\n", ret);
5482     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5483     ok(ret == 1, "expected 1, got %ld\n", ret);
5484     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5485     ok(ret == 2, "expected 2, got %ld\n", ret);
5486
5487     SendMessage(combo, CB_SETCURSEL, 0, 0);
5488     SetFocus(combo);
5489     flush_sequence();
5490
5491     log_all_parent_messages++;
5492     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5493     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5494     log_all_parent_messages--;
5495     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5496
5497     DestroyWindow(combo);
5498     DestroyWindow(parent);
5499 }
5500
5501 /****************** WM_IME_KEYDOWN message test *******************/
5502
5503 static const struct message WmImeKeydownMsgSeq_0[] =
5504 {
5505     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5506     { WM_CHAR, wparam, 'A' },
5507     { 0 }
5508 };
5509
5510 static const struct message WmImeKeydownMsgSeq_1[] =
5511 {
5512     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5513     { WM_CHAR,    optional|wparam, VK_RETURN },
5514     { 0 }
5515 };
5516
5517 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5518 {
5519     struct recvd_message msg;
5520
5521     msg.hwnd = hwnd;
5522     msg.message = message;
5523     msg.flags = wparam|lparam;
5524     msg.wParam = wParam;
5525     msg.lParam = lParam;
5526     msg.descr = "wmime_keydown";
5527     add_message(&msg);
5528
5529     return DefWindowProcA(hwnd, message, wParam, lParam);
5530 }
5531
5532 static void register_wmime_keydown_class(void)
5533 {
5534     WNDCLASSA cls;
5535
5536     ZeroMemory(&cls, sizeof(WNDCLASSA));
5537     cls.lpfnWndProc = wmime_keydown_procA;
5538     cls.hInstance = GetModuleHandleA(0);
5539     cls.lpszClassName = "wmime_keydown_class";
5540     if (!RegisterClassA(&cls)) assert(0);
5541 }
5542
5543 static void test_wmime_keydown_message(void)
5544 {
5545     HWND hwnd;
5546     MSG msg;
5547
5548     trace("Message sequences by WM_IME_KEYDOWN\n");
5549
5550     register_wmime_keydown_class();
5551     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5552                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5553                            NULL, NULL, 0);
5554     flush_events();
5555     flush_sequence();
5556
5557     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5558     SendMessage(hwnd, WM_CHAR, 'A', 1);
5559     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5560
5561     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5562     {
5563         TranslateMessage(&msg);
5564         DispatchMessage(&msg);
5565     }
5566     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5567
5568     DestroyWindow(hwnd);
5569 }
5570
5571 /************* painting message test ********************/
5572
5573 void dump_region(HRGN hrgn)
5574 {
5575     DWORD i, size;
5576     RGNDATA *data = NULL;
5577     RECT *rect;
5578
5579     if (!hrgn)
5580     {
5581         printf( "null region\n" );
5582         return;
5583     }
5584     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5585     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5586     GetRegionData( hrgn, size, data );
5587     printf("%d rects:", data->rdh.nCount );
5588     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5589         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5590     printf("\n");
5591     HeapFree( GetProcessHeap(), 0, data );
5592 }
5593
5594 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5595 {
5596     INT ret;
5597     RECT r1, r2;
5598     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5599     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5600
5601     ret = GetUpdateRgn( hwnd, update, FALSE );
5602     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5603     if (ret == NULLREGION)
5604     {
5605         ok( !hrgn, "Update region shouldn't be empty\n" );
5606     }
5607     else
5608     {
5609         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5610         {
5611             ok( 0, "Regions are different\n" );
5612             if (winetest_debug > 0)
5613             {
5614                 printf( "Update region: " );
5615                 dump_region( update );
5616                 printf( "Wanted region: " );
5617                 dump_region( hrgn );
5618             }
5619         }
5620     }
5621     GetRgnBox( update, &r1 );
5622     GetUpdateRect( hwnd, &r2, FALSE );
5623     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5624         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5625         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5626
5627     DeleteObject( tmp );
5628     DeleteObject( update );
5629 }
5630
5631 static const struct message WmInvalidateRgn[] = {
5632     { WM_NCPAINT, sent },
5633     { WM_GETTEXT, sent|defwinproc|optional },
5634     { 0 }
5635 };
5636
5637 static const struct message WmGetUpdateRect[] = {
5638     { WM_NCPAINT, sent },
5639     { WM_GETTEXT, sent|defwinproc|optional },
5640     { WM_PAINT, sent },
5641     { 0 }
5642 };
5643
5644 static const struct message WmInvalidateFull[] = {
5645     { WM_NCPAINT, sent|wparam, 1 },
5646     { WM_GETTEXT, sent|defwinproc|optional },
5647     { 0 }
5648 };
5649
5650 static const struct message WmInvalidateErase[] = {
5651     { WM_NCPAINT, sent|wparam, 1 },
5652     { WM_GETTEXT, sent|defwinproc|optional },
5653     { WM_ERASEBKGND, sent },
5654     { 0 }
5655 };
5656
5657 static const struct message WmInvalidatePaint[] = {
5658     { WM_PAINT, sent },
5659     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5660     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5661     { 0 }
5662 };
5663
5664 static const struct message WmInvalidateErasePaint[] = {
5665     { WM_PAINT, sent },
5666     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5667     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5668     { WM_ERASEBKGND, sent|beginpaint|optional },
5669     { 0 }
5670 };
5671
5672 static const struct message WmInvalidateErasePaint2[] = {
5673     { WM_PAINT, sent },
5674     { WM_NCPAINT, sent|beginpaint },
5675     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5676     { WM_ERASEBKGND, sent|beginpaint|optional },
5677     { 0 }
5678 };
5679
5680 static const struct message WmErase[] = {
5681     { WM_ERASEBKGND, sent },
5682     { 0 }
5683 };
5684
5685 static const struct message WmPaint[] = {
5686     { WM_PAINT, sent },
5687     { 0 }
5688 };
5689
5690 static const struct message WmParentOnlyPaint[] = {
5691     { WM_PAINT, sent|parent },
5692     { 0 }
5693 };
5694
5695 static const struct message WmInvalidateParent[] = {
5696     { WM_NCPAINT, sent|parent },
5697     { WM_GETTEXT, sent|defwinproc|parent|optional },
5698     { WM_ERASEBKGND, sent|parent },
5699     { 0 }
5700 };
5701
5702 static const struct message WmInvalidateParentChild[] = {
5703     { WM_NCPAINT, sent|parent },
5704     { WM_GETTEXT, sent|defwinproc|parent|optional },
5705     { WM_ERASEBKGND, sent|parent },
5706     { WM_NCPAINT, sent },
5707     { WM_GETTEXT, sent|defwinproc|optional },
5708     { WM_ERASEBKGND, sent },
5709     { 0 }
5710 };
5711
5712 static const struct message WmInvalidateParentChild2[] = {
5713     { WM_ERASEBKGND, sent|parent },
5714     { WM_NCPAINT, sent },
5715     { WM_GETTEXT, sent|defwinproc|optional },
5716     { WM_ERASEBKGND, sent },
5717     { 0 }
5718 };
5719
5720 static const struct message WmParentPaint[] = {
5721     { WM_PAINT, sent|parent },
5722     { WM_PAINT, sent },
5723     { 0 }
5724 };
5725
5726 static const struct message WmParentPaintNc[] = {
5727     { WM_PAINT, sent|parent },
5728     { WM_PAINT, sent },
5729     { WM_NCPAINT, sent|beginpaint },
5730     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5731     { WM_ERASEBKGND, sent|beginpaint|optional },
5732     { 0 }
5733 };
5734
5735 static const struct message WmChildPaintNc[] = {
5736     { WM_PAINT, sent },
5737     { WM_NCPAINT, sent|beginpaint },
5738     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5739     { WM_ERASEBKGND, sent|beginpaint|optional },
5740     { 0 }
5741 };
5742
5743 static const struct message WmParentErasePaint[] = {
5744     { WM_PAINT, sent|parent },
5745     { WM_NCPAINT, sent|parent|beginpaint },
5746     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5747     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5748     { WM_PAINT, sent },
5749     { WM_NCPAINT, sent|beginpaint },
5750     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5751     { WM_ERASEBKGND, sent|beginpaint|optional },
5752     { 0 }
5753 };
5754
5755 static const struct message WmParentOnlyNcPaint[] = {
5756     { WM_PAINT, sent|parent },
5757     { WM_NCPAINT, sent|parent|beginpaint },
5758     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5759     { 0 }
5760 };
5761
5762 static const struct message WmSetParentStyle[] = {
5763     { WM_STYLECHANGING, sent|parent },
5764     { WM_STYLECHANGED, sent|parent },
5765     { 0 }
5766 };
5767
5768 static void test_paint_messages(void)
5769 {
5770     BOOL ret;
5771     RECT rect;
5772     POINT pt;
5773     MSG msg;
5774     HWND hparent, hchild;
5775     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5776     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5777     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5778                                 100, 100, 200, 200, 0, 0, 0, NULL);
5779     ok (hwnd != 0, "Failed to create overlapped window\n");
5780
5781     ShowWindow( hwnd, SW_SHOW );
5782     UpdateWindow( hwnd );
5783     flush_events();
5784     flush_sequence();
5785
5786     check_update_rgn( hwnd, 0 );
5787     SetRectRgn( hrgn, 10, 10, 20, 20 );
5788     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5789     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5790     check_update_rgn( hwnd, hrgn );
5791     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5792     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5793     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5794     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5795     check_update_rgn( hwnd, hrgn );
5796     /* validate everything */
5797     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5798     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5799     check_update_rgn( hwnd, 0 );
5800
5801     /* test empty region */
5802     SetRectRgn( hrgn, 10, 10, 10, 15 );
5803     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5804     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5805     check_update_rgn( hwnd, 0 );
5806     /* test empty rect */
5807     SetRect( &rect, 10, 10, 10, 15 );
5808     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5809     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5810     check_update_rgn( hwnd, 0 );
5811
5812     /* flush pending messages */
5813     flush_events();
5814     flush_sequence();
5815
5816     GetClientRect( hwnd, &rect );
5817     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5818     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5819      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5820      */
5821     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5822     SetRectEmpty( &rect );
5823     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5824     check_update_rgn( hwnd, hrgn );
5825     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5826     flush_events();
5827     ok_sequence( WmPaint, "Paint", FALSE );
5828     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5829     check_update_rgn( hwnd, 0 );
5830
5831     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5832      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5833      */
5834     trace("testing ValidateRect(0, NULL)\n");
5835     SetRectEmpty( &rect );
5836     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5837     {
5838         check_update_rgn( hwnd, hrgn );
5839         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5840         flush_events();
5841         ok_sequence( WmPaint, "Paint", FALSE );
5842         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5843         check_update_rgn( hwnd, 0 );
5844     }
5845
5846     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5847     SetLastError(0xdeadbeef);
5848     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5849     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5850        "wrong error code %d\n", GetLastError());
5851     check_update_rgn( hwnd, 0 );
5852     flush_events();
5853     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5854
5855     trace("testing ValidateRgn(0, NULL)\n");
5856     SetLastError(0xdeadbeef);
5857     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5858     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5859        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5860        "wrong error code %d\n", GetLastError());
5861     check_update_rgn( hwnd, 0 );
5862     flush_events();
5863     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5864
5865     /* now with frame */
5866     SetRectRgn( hrgn, -5, -5, 20, 20 );
5867
5868     /* flush pending messages */
5869     flush_events();
5870     flush_sequence();
5871     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5872     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5873
5874     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5875     check_update_rgn( hwnd, hrgn );
5876
5877     flush_sequence();
5878     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5879     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5880
5881     flush_sequence();
5882     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5883     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5884
5885     GetClientRect( hwnd, &rect );
5886     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5887     check_update_rgn( hwnd, hrgn );
5888
5889     flush_sequence();
5890     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5891     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5892
5893     flush_sequence();
5894     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5895     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5896     check_update_rgn( hwnd, 0 );
5897
5898     flush_sequence();
5899     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5900     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5901     check_update_rgn( hwnd, 0 );
5902
5903     flush_sequence();
5904     SetRectRgn( hrgn, 0, 0, 100, 100 );
5905     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5906     SetRectRgn( hrgn, 0, 0, 50, 100 );
5907     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5908     SetRectRgn( hrgn, 50, 0, 100, 100 );
5909     check_update_rgn( hwnd, hrgn );
5910     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5911     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5912     check_update_rgn( hwnd, 0 );
5913
5914     flush_sequence();
5915     SetRectRgn( hrgn, 0, 0, 100, 100 );
5916     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5917     SetRectRgn( hrgn, 0, 0, 100, 50 );
5918     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5919     ok_sequence( WmErase, "Erase", FALSE );
5920     SetRectRgn( hrgn, 0, 50, 100, 100 );
5921     check_update_rgn( hwnd, hrgn );
5922
5923     flush_sequence();
5924     SetRectRgn( hrgn, 0, 0, 100, 100 );
5925     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5926     SetRectRgn( hrgn, 0, 0, 50, 50 );
5927     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5928     ok_sequence( WmPaint, "Paint", FALSE );
5929
5930     flush_sequence();
5931     SetRectRgn( hrgn, -4, -4, -2, -2 );
5932     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5933     SetRectRgn( hrgn, -200, -200, -198, -198 );
5934     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5935     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5936
5937     flush_sequence();
5938     SetRectRgn( hrgn, -4, -4, -2, -2 );
5939     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5940     SetRectRgn( hrgn, -4, -4, -3, -3 );
5941     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5942     SetRectRgn( hrgn, 0, 0, 1, 1 );
5943     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5944     ok_sequence( WmPaint, "Paint", FALSE );
5945
5946     flush_sequence();
5947     SetRectRgn( hrgn, -4, -4, -1, -1 );
5948     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5949     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5950     /* make sure no WM_PAINT was generated */
5951     flush_events();
5952     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5953
5954     flush_sequence();
5955     SetRectRgn( hrgn, -4, -4, -1, -1 );
5956     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5957     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5958     {
5959         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5960         {
5961             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5962             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5963             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5964             ret = GetUpdateRect( hwnd, &rect, FALSE );
5965             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5966             /* this will send WM_NCPAINT and validate the non client area */
5967             ret = GetUpdateRect( hwnd, &rect, TRUE );
5968             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5969         }
5970         DispatchMessage( &msg );
5971     }
5972     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5973
5974     DestroyWindow( hwnd );
5975
5976     /* now test with a child window */
5977
5978     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5979                               100, 100, 200, 200, 0, 0, 0, NULL);
5980     ok (hparent != 0, "Failed to create parent window\n");
5981
5982     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5983                            10, 10, 100, 100, hparent, 0, 0, NULL);
5984     ok (hchild != 0, "Failed to create child window\n");
5985
5986     ShowWindow( hparent, SW_SHOW );
5987     UpdateWindow( hparent );
5988     UpdateWindow( hchild );
5989     flush_events();
5990     flush_sequence();
5991     log_all_parent_messages++;
5992
5993     SetRect( &rect, 0, 0, 50, 50 );
5994     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5995     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5996     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5997
5998     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5999     pt.x = pt.y = 0;
6000     MapWindowPoints( hchild, hparent, &pt, 1 );
6001     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6002     check_update_rgn( hchild, hrgn );
6003     SetRectRgn( hrgn, 0, 0, 50, 50 );
6004     check_update_rgn( hparent, hrgn );
6005     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6006     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6007     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6008     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6009
6010     flush_events();
6011     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6012
6013     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6014     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6015     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6016     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6017     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6018
6019     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6020     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6021     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6022
6023     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6024     flush_sequence();
6025     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6026     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6027     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6028
6029     /* flush all paint messages */
6030     flush_events();
6031     flush_sequence();
6032
6033     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6034     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6035     SetRectRgn( hrgn, 0, 0, 50, 50 );
6036     check_update_rgn( hparent, hrgn );
6037     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6038     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6039     SetRectRgn( hrgn, 0, 0, 50, 50 );
6040     check_update_rgn( hparent, hrgn );
6041
6042     /* flush all paint messages */
6043     flush_events();
6044     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6045     flush_sequence();
6046
6047     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6048     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6049     SetRectRgn( hrgn, 0, 0, 50, 50 );
6050     check_update_rgn( hparent, hrgn );
6051     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6052     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6053     SetRectRgn( hrgn2, 10, 10, 50, 50 );
6054     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6055     check_update_rgn( hparent, hrgn );
6056     /* flush all paint messages */
6057     flush_events();
6058     flush_sequence();
6059
6060     /* same as above but parent gets completely validated */
6061     SetRect( &rect, 20, 20, 30, 30 );
6062     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6063     SetRectRgn( hrgn, 20, 20, 30, 30 );
6064     check_update_rgn( hparent, hrgn );
6065     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6066     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6067     check_update_rgn( hparent, 0 );  /* no update region */
6068     flush_events();
6069     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
6070
6071     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6072     flush_sequence();
6073     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6074     SetRectRgn( hrgn, 20, 20, 30, 30 );
6075     check_update_rgn( hparent, hrgn );
6076     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6077     SetRectRgn( hrgn, 20, 20, 30, 30 );
6078     check_update_rgn( hparent, hrgn );
6079
6080     /* same as above but normal WM_PAINT doesn't validate parent */
6081     flush_sequence();
6082     SetRect( &rect, 20, 20, 30, 30 );
6083     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6084     SetRectRgn( hrgn, 20, 20, 30, 30 );
6085     check_update_rgn( hparent, hrgn );
6086     /* no WM_PAINT in child while parent still pending */
6087     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6088     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6089     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6090     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6091
6092     flush_sequence();
6093     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6094     /* no WM_PAINT in child while parent still pending */
6095     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6096     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6097     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6098     /* now that parent is valid child should get WM_PAINT */
6099     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6100     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6101     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6102     ok_sequence( WmEmptySeq, "No other message", FALSE );
6103
6104     /* same thing with WS_CLIPCHILDREN in parent */
6105     flush_sequence();
6106     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6107     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6108     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6109     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6110     ok_sequence( WmEmptySeq, "No message", FALSE );
6111     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6112     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6113
6114     flush_sequence();
6115     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6116     SetRectRgn( hrgn, 20, 20, 30, 30 );
6117     check_update_rgn( hparent, hrgn );
6118     /* no WM_PAINT in child while parent still pending */
6119     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6120     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6121     /* WM_PAINT in parent first */
6122     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6123     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6124
6125     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6126     flush_sequence();
6127     SetRect( &rect, 0, 0, 30, 30 );
6128     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6129     SetRectRgn( hrgn, 0, 0, 30, 30 );
6130     check_update_rgn( hparent, hrgn );
6131     flush_events();
6132     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6133
6134     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6135     flush_sequence();
6136     SetRect( &rect, -10, 0, 30, 30 );
6137     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6138     SetRect( &rect, 0, 0, 20, 20 );
6139     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6140     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6141     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6142
6143     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6144     flush_sequence();
6145     SetRect( &rect, -10, 0, 30, 30 );
6146     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6147     SetRect( &rect, 0, 0, 100, 100 );
6148     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6149     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6150     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6151     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6152     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6153
6154     /* test RDW_INTERNALPAINT behavior */
6155
6156     flush_sequence();
6157     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6158     flush_events();
6159     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6160
6161     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6162     flush_events();
6163     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6164
6165     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6166     flush_events();
6167     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6168
6169     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6170     UpdateWindow( hparent );
6171     flush_events();
6172     flush_sequence();
6173     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6174     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6175     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6176                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6177     flush_events();
6178     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6179
6180     UpdateWindow( hparent );
6181     flush_events();
6182     flush_sequence();
6183     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6184     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6185     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6186                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6187     flush_events();
6188     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6189
6190     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6191     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6192     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6193     flush_events();
6194     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6195
6196     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6197     UpdateWindow( hparent );
6198     flush_events();
6199     flush_sequence();
6200     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6201     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6202     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6203                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6204     flush_events();
6205     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6206
6207     UpdateWindow( hparent );
6208     flush_events();
6209     flush_sequence();
6210     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6211     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6212     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6213                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6214     flush_events();
6215     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6216
6217     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6218     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6219
6220     UpdateWindow( hparent );
6221     flush_events();
6222     flush_sequence();
6223     trace("testing SetWindowPos(-10000, -10000) on child\n");
6224     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6225     check_update_rgn( hchild, 0 );
6226     flush_events();
6227
6228 #if 0 /* this one doesn't pass under Wine yet */
6229     UpdateWindow( hparent );
6230     flush_events();
6231     flush_sequence();
6232     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6233     ShowWindow( hchild, SW_MINIMIZE );
6234     check_update_rgn( hchild, 0 );
6235     flush_events();
6236 #endif
6237
6238     UpdateWindow( hparent );
6239     flush_events();
6240     flush_sequence();
6241     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6242     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6243     check_update_rgn( hparent, 0 );
6244     flush_events();
6245
6246     log_all_parent_messages--;
6247     DestroyWindow( hparent );
6248     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6249
6250     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6251
6252     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6253                               100, 100, 200, 200, 0, 0, 0, NULL);
6254     ok (hparent != 0, "Failed to create parent window\n");
6255
6256     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6257                            10, 10, 100, 100, hparent, 0, 0, NULL);
6258     ok (hchild != 0, "Failed to create child window\n");
6259
6260     ShowWindow( hparent, SW_SHOW );
6261     UpdateWindow( hparent );
6262     UpdateWindow( hchild );
6263     flush_events();
6264     flush_sequence();
6265
6266     /* moving child outside of parent boundaries changes update region */
6267     SetRect( &rect, 0, 0, 40, 40 );
6268     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6269     SetRectRgn( hrgn, 0, 0, 40, 40 );
6270     check_update_rgn( hchild, hrgn );
6271     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6272     SetRectRgn( hrgn, 10, 0, 40, 40 );
6273     check_update_rgn( hchild, hrgn );
6274     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6275     SetRectRgn( hrgn, 10, 10, 40, 40 );
6276     check_update_rgn( hchild, hrgn );
6277
6278     /* moving parent off-screen does too */
6279     SetRect( &rect, 0, 0, 100, 100 );
6280     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6281     SetRectRgn( hrgn, 0, 0, 100, 100 );
6282     check_update_rgn( hparent, hrgn );
6283     SetRectRgn( hrgn, 10, 10, 40, 40 );
6284     check_update_rgn( hchild, hrgn );
6285     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6286     SetRectRgn( hrgn, 20, 20, 100, 100 );
6287     check_update_rgn( hparent, hrgn );
6288     SetRectRgn( hrgn, 30, 30, 40, 40 );
6289     check_update_rgn( hchild, hrgn );
6290
6291     /* invalidated region is cropped by the parent rects */
6292     SetRect( &rect, 0, 0, 50, 50 );
6293     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6294     SetRectRgn( hrgn, 30, 30, 50, 50 );
6295     check_update_rgn( hchild, hrgn );
6296
6297     DestroyWindow( hparent );
6298     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6299     flush_sequence();
6300
6301     DeleteObject( hrgn );
6302     DeleteObject( hrgn2 );
6303 }
6304
6305 struct wnd_event
6306 {
6307     HWND hwnd;
6308     HANDLE event;
6309 };
6310
6311 static DWORD WINAPI thread_proc(void *param)
6312 {
6313     MSG msg;
6314     struct wnd_event *wnd_event = param;
6315
6316     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6317                                       100, 100, 200, 200, 0, 0, 0, NULL);
6318     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6319
6320     SetEvent(wnd_event->event);
6321
6322     while (GetMessage(&msg, 0, 0, 0))
6323     {
6324         TranslateMessage(&msg);
6325         DispatchMessage(&msg);
6326     }
6327
6328     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6329
6330     return 0;
6331 }
6332
6333 static void test_interthread_messages(void)
6334 {
6335     HANDLE hThread;
6336     DWORD tid;
6337     WNDPROC proc;
6338     MSG msg;
6339     char buf[256];
6340     int len, expected_len;
6341     struct wnd_event wnd_event;
6342     BOOL ret;
6343
6344     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6345     if (!wnd_event.event)
6346     {
6347         win_skip("skipping interthread message test under win9x\n");
6348         return;
6349     }
6350
6351     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6352     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6353
6354     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6355
6356     CloseHandle(wnd_event.event);
6357
6358     SetLastError(0xdeadbeef);
6359     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6360     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6361        "wrong error code %d\n", GetLastError());
6362
6363     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6364     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6365
6366     expected_len = lstrlenA("window caption text");
6367     memset(buf, 0, sizeof(buf));
6368     SetLastError(0xdeadbeef);
6369     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6370     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6371     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6372
6373     msg.hwnd = wnd_event.hwnd;
6374     msg.message = WM_GETTEXT;
6375     msg.wParam = sizeof(buf);
6376     msg.lParam = (LPARAM)buf;
6377     memset(buf, 0, sizeof(buf));
6378     SetLastError(0xdeadbeef);
6379     len = DispatchMessageA(&msg);
6380     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6381        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6382
6383     /* the following test causes an exception in user.exe under win9x */
6384     msg.hwnd = wnd_event.hwnd;
6385     msg.message = WM_TIMER;
6386     msg.wParam = 0;
6387     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6388     SetLastError(0xdeadbeef);
6389     len = DispatchMessageA(&msg);
6390     ok(!len && GetLastError() == 0xdeadbeef,
6391        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6392
6393     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6394     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6395
6396     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6397     CloseHandle(hThread);
6398
6399     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6400 }
6401
6402
6403 static const struct message WmVkN[] = {
6404     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6405     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6406     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6407     { WM_CHAR, wparam|lparam, 'n', 1 },
6408     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6409     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6410     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6411     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6412     { 0 }
6413 };
6414 static const struct message WmShiftVkN[] = {
6415     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6416     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6417     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6418     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6419     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6420     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6421     { WM_CHAR, wparam|lparam, 'N', 1 },
6422     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6423     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6424     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6425     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6426     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6427     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6428     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6429     { 0 }
6430 };
6431 static const struct message WmCtrlVkN[] = {
6432     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6433     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6434     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6435     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6436     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6437     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6438     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6439     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6440     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6441     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6442     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6443     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6444     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6445     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6446     { 0 }
6447 };
6448 static const struct message WmCtrlVkN_2[] = {
6449     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6450     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6451     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6452     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6453     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6454     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6455     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6456     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6457     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6458     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6459     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6460     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6461     { 0 }
6462 };
6463 static const struct message WmAltVkN[] = {
6464     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6465     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6466     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6467     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6468     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6469     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6470     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6471     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6472     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6473     { HCBT_SYSCOMMAND, hook },
6474     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6475     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6476     { 0x00AE, sent|defwinproc|optional }, /* XP */
6477     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6478     { WM_INITMENU, sent|defwinproc },
6479     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6480     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6481     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6482     { WM_CAPTURECHANGED, sent|defwinproc },
6483     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6484     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6485     { WM_EXITMENULOOP, sent|defwinproc },
6486     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6487     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6488     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6489     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6490     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6491     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6492     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6493     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6494     { 0 }
6495 };
6496 static const struct message WmAltVkN_2[] = {
6497     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6498     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6499     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6500     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6501     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6502     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6503     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6504     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6505     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6506     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6507     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6508     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6509     { 0 }
6510 };
6511 static const struct message WmCtrlAltVkN[] = {
6512     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6513     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6514     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6515     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6516     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6517     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6518     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6519     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6520     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6521     { WM_CHAR, optional },
6522     { WM_CHAR, sent|optional },
6523     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6524     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6525     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6526     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6527     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6528     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6529     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6530     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6531     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6532     { 0 }
6533 };
6534 static const struct message WmCtrlShiftVkN[] = {
6535     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6536     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6537     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6538     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6539     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6540     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6541     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6542     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6543     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6544     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6545     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6546     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6547     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6548     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6549     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6550     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6551     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6552     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6553     { 0 }
6554 };
6555 static const struct message WmCtrlAltShiftVkN[] = {
6556     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6557     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6558     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6559     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6560     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6561     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6562     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6563     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6564     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6565     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6566     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6567     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6568     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6569     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6570     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6571     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6572     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6573     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6574     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6575     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6576     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6577     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6578     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6579     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6580     { 0 }
6581 };
6582 static const struct message WmAltPressRelease[] = {
6583     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6584     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6585     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6586     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6587     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6588     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6589     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6590     { HCBT_SYSCOMMAND, hook },
6591     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6592     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6593     { WM_INITMENU, sent|defwinproc },
6594     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6595     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6596     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6597
6598     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6599
6600     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6601     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6602     { WM_CAPTURECHANGED, sent|defwinproc },
6603     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6604     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6605     { WM_EXITMENULOOP, sent|defwinproc },
6606     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6607     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6608     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6609     { 0 }
6610 };
6611 static const struct message WmShiftMouseButton[] = {
6612     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6613     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6614     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6615     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6616     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6617     { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6618     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6619     { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6620     { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6621     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6622     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6623     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6624     { 0 }
6625 };
6626 static const struct message WmF1Seq[] = {
6627     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6628     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6629     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6630     { WM_KEYF1, wparam|lparam, 0, 0 },
6631     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6632     { WM_HELP, sent|defwinproc },
6633     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6634     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6635     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6636     { 0 }
6637 };
6638 static const struct message WmVkAppsSeq[] = {
6639     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6640     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6641     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6642     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6643     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6644     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6645     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6646     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6647     { 0 }
6648 };
6649
6650 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6651 {
6652     MSG msg;
6653
6654     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6655     {
6656         struct recvd_message log_msg;
6657
6658         /* ignore some unwanted messages */
6659         if (msg.message == WM_MOUSEMOVE ||
6660             msg.message == WM_GETICON ||
6661             msg.message == WM_GETOBJECT ||
6662             msg.message == WM_TIMER ||
6663             msg.message == WM_DEVICECHANGE)
6664             continue;
6665
6666         log_msg.hwnd = msg.hwnd;
6667         log_msg.message = msg.message;
6668         log_msg.flags = wparam|lparam;
6669         log_msg.wParam = msg.wParam;
6670         log_msg.lParam = msg.lParam;
6671         log_msg.descr = "accel";
6672         add_message(&log_msg);
6673
6674         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6675         {
6676             TranslateMessage(&msg);
6677             DispatchMessage(&msg);
6678         }
6679     }
6680 }
6681
6682 static void test_accelerators(void)
6683 {
6684     RECT rc;
6685     POINT pt;
6686     SHORT state;
6687     HACCEL hAccel;
6688     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6689                                 100, 100, 200, 200, 0, 0, 0, NULL);
6690     BOOL ret;
6691
6692     assert(hwnd != 0);
6693     UpdateWindow(hwnd);
6694     flush_events();
6695     flush_sequence();
6696
6697     SetFocus(hwnd);
6698     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6699
6700     state = GetKeyState(VK_SHIFT);
6701     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6702     state = GetKeyState(VK_CAPITAL);
6703     ok(state == 0, "wrong CapsLock state %04x\n", state);
6704
6705     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6706     assert(hAccel != 0);
6707
6708     flush_events();
6709     pump_msg_loop(hwnd, 0);
6710     flush_sequence();
6711
6712     trace("testing VK_N press/release\n");
6713     flush_sequence();
6714     keybd_event('N', 0, 0, 0);
6715     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6716     pump_msg_loop(hwnd, hAccel);
6717     if (!sequence_cnt)  /* we didn't get any message */
6718     {
6719         skip( "queuing key events not supported\n" );
6720         goto done;
6721     }
6722     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6723
6724     trace("testing Shift+VK_N press/release\n");
6725     flush_sequence();
6726     keybd_event(VK_SHIFT, 0, 0, 0);
6727     keybd_event('N', 0, 0, 0);
6728     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6729     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6730     pump_msg_loop(hwnd, hAccel);
6731     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6732
6733     trace("testing Ctrl+VK_N press/release\n");
6734     flush_sequence();
6735     keybd_event(VK_CONTROL, 0, 0, 0);
6736     keybd_event('N', 0, 0, 0);
6737     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6738     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6739     pump_msg_loop(hwnd, hAccel);
6740     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6741
6742     trace("testing Alt+VK_N press/release\n");
6743     flush_sequence();
6744     keybd_event(VK_MENU, 0, 0, 0);
6745     keybd_event('N', 0, 0, 0);
6746     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6747     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6748     pump_msg_loop(hwnd, hAccel);
6749     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6750
6751     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6752     flush_sequence();
6753     keybd_event(VK_CONTROL, 0, 0, 0);
6754     keybd_event(VK_MENU, 0, 0, 0);
6755     keybd_event('N', 0, 0, 0);
6756     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6757     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6758     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6759     pump_msg_loop(hwnd, hAccel);
6760     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6761
6762     ret = DestroyAcceleratorTable(hAccel);
6763     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6764
6765     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6766     assert(hAccel != 0);
6767
6768     trace("testing VK_N press/release\n");
6769     flush_sequence();
6770     keybd_event('N', 0, 0, 0);
6771     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6772     pump_msg_loop(hwnd, hAccel);
6773     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6774
6775     trace("testing Shift+VK_N press/release\n");
6776     flush_sequence();
6777     keybd_event(VK_SHIFT, 0, 0, 0);
6778     keybd_event('N', 0, 0, 0);
6779     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6780     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6781     pump_msg_loop(hwnd, hAccel);
6782     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6783
6784     trace("testing Ctrl+VK_N press/release 2\n");
6785     flush_sequence();
6786     keybd_event(VK_CONTROL, 0, 0, 0);
6787     keybd_event('N', 0, 0, 0);
6788     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6789     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6790     pump_msg_loop(hwnd, hAccel);
6791     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6792
6793     trace("testing Alt+VK_N press/release 2\n");
6794     flush_sequence();
6795     keybd_event(VK_MENU, 0, 0, 0);
6796     keybd_event('N', 0, 0, 0);
6797     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6798     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6799     pump_msg_loop(hwnd, hAccel);
6800     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6801
6802     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6803     flush_sequence();
6804     keybd_event(VK_CONTROL, 0, 0, 0);
6805     keybd_event(VK_MENU, 0, 0, 0);
6806     keybd_event('N', 0, 0, 0);
6807     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6808     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6809     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6810     pump_msg_loop(hwnd, hAccel);
6811     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6812
6813     trace("testing Ctrl+Shift+VK_N press/release\n");
6814     flush_sequence();
6815     keybd_event(VK_CONTROL, 0, 0, 0);
6816     keybd_event(VK_SHIFT, 0, 0, 0);
6817     keybd_event('N', 0, 0, 0);
6818     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6819     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6820     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6821     pump_msg_loop(hwnd, hAccel);
6822     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6823
6824     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6825     flush_sequence();
6826     keybd_event(VK_CONTROL, 0, 0, 0);
6827     keybd_event(VK_MENU, 0, 0, 0);
6828     keybd_event(VK_SHIFT, 0, 0, 0);
6829     keybd_event('N', 0, 0, 0);
6830     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6831     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6832     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6833     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6834     pump_msg_loop(hwnd, hAccel);
6835     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6836
6837     ret = DestroyAcceleratorTable(hAccel);
6838     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6839     hAccel = 0;
6840
6841     trace("testing Alt press/release\n");
6842     flush_sequence();
6843     keybd_event(VK_MENU, 0, 0, 0);
6844     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6845     keybd_event(VK_MENU, 0, 0, 0);
6846     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6847     pump_msg_loop(hwnd, 0);
6848     /* this test doesn't pass in Wine for managed windows */
6849     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6850
6851     trace("testing VK_F1 press/release\n");
6852     keybd_event(VK_F1, 0, 0, 0);
6853     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6854     pump_msg_loop(hwnd, 0);
6855     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6856
6857     trace("testing VK_APPS press/release\n");
6858     keybd_event(VK_APPS, 0, 0, 0);
6859     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6860     pump_msg_loop(hwnd, 0);
6861     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6862
6863     trace("testing Shift+MouseButton press/release\n");
6864     /* first, move mouse pointer inside of the window client area */
6865     GetClientRect(hwnd, &rc);
6866     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6867     rc.left += (rc.right - rc.left)/2;
6868     rc.top += (rc.bottom - rc.top)/2;
6869     SetCursorPos(rc.left, rc.top);
6870     SetActiveWindow(hwnd);
6871
6872     flush_events();
6873     flush_sequence();
6874     GetCursorPos(&pt);
6875     if (pt.x == rc.left && pt.y == rc.top)
6876     {
6877         int i;
6878         keybd_event(VK_SHIFT, 0, 0, 0);
6879         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6880         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6881         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6882         pump_msg_loop(hwnd, 0);
6883         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
6884         if (i < sequence_cnt)
6885             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
6886         else
6887             skip( "Shift+MouseButton event didn't get to the window\n" );
6888     }
6889
6890 done:
6891     if (hAccel) DestroyAcceleratorTable(hAccel);
6892     DestroyWindow(hwnd);
6893 }
6894
6895 /************* window procedures ********************/
6896
6897 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6898                              WPARAM wParam, LPARAM lParam)
6899 {
6900     static long defwndproc_counter = 0;
6901     static long beginpaint_counter = 0;
6902     LRESULT ret;
6903     struct recvd_message msg;
6904
6905     /* ignore registered messages */
6906     if (message >= 0xc000) return 0;
6907
6908     switch (message)
6909     {
6910         case WM_ENABLE:
6911         {
6912             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6913             ok((BOOL)wParam == !(style & WS_DISABLED),
6914                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6915             break;
6916         }
6917
6918         case WM_CAPTURECHANGED:
6919             if (test_DestroyWindow_flag)
6920             {
6921                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6922                 if (style & WS_CHILD)
6923                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6924                 else if (style & WS_POPUP)
6925                     lParam = WND_POPUP_ID;
6926                 else
6927                     lParam = WND_PARENT_ID;
6928             }
6929             break;
6930
6931         case WM_NCDESTROY:
6932         {
6933             HWND capture;
6934
6935             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6936             capture = GetCapture();
6937             if (capture)
6938             {
6939                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6940                 trace("current capture %p, releasing...\n", capture);
6941                 ReleaseCapture();
6942             }
6943         }
6944         /* fall through */
6945         case WM_DESTROY:
6946             if (pGetAncestor)
6947                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6948             if (test_DestroyWindow_flag)
6949             {
6950                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6951                 if (style & WS_CHILD)
6952                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6953                 else if (style & WS_POPUP)
6954                     lParam = WND_POPUP_ID;
6955                 else
6956                     lParam = WND_PARENT_ID;
6957             }
6958             break;
6959
6960         /* test_accelerators() depends on this */
6961         case WM_NCHITTEST:
6962             return HTCLIENT;
6963
6964         /* ignore */
6965         case WM_MOUSEMOVE:
6966         case WM_MOUSEACTIVATE:
6967         case WM_NCMOUSEMOVE:
6968         case WM_SETCURSOR:
6969         case WM_GETICON:
6970         case WM_GETOBJECT:
6971         case WM_DEVICECHANGE:
6972         case WM_IME_SELECT:
6973             return 0;
6974     }
6975
6976     msg.hwnd = hwnd;
6977     msg.message = message;
6978     msg.flags = sent|wparam|lparam;
6979     if (defwndproc_counter) msg.flags |= defwinproc;
6980     if (beginpaint_counter) msg.flags |= beginpaint;
6981     msg.wParam = wParam;
6982     msg.lParam = lParam;
6983     msg.descr = "MsgCheckProc";
6984     add_message(&msg);
6985
6986     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6987     {
6988         HWND parent = GetParent(hwnd);
6989         RECT rc;
6990         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6991
6992         GetClientRect(parent, &rc);
6993         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6994         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6995               minmax->ptReserved.x, minmax->ptReserved.y,
6996               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6997               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6998               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6999               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7000
7001         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7002            minmax->ptMaxSize.x, rc.right);
7003         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7004            minmax->ptMaxSize.y, rc.bottom);
7005     }
7006
7007     if (message == WM_PAINT)
7008     {
7009         PAINTSTRUCT ps;
7010         beginpaint_counter++;
7011         BeginPaint( hwnd, &ps );
7012         beginpaint_counter--;
7013         EndPaint( hwnd, &ps );
7014         return 0;
7015     }
7016
7017     defwndproc_counter++;
7018     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
7019                   : DefWindowProcA(hwnd, message, wParam, lParam);
7020     defwndproc_counter--;
7021
7022     return ret;
7023 }
7024
7025 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7026 {
7027     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7028 }
7029
7030 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7031 {
7032     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7033 }
7034
7035 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7036 {
7037     static long defwndproc_counter = 0;
7038     LRESULT ret;
7039     struct recvd_message msg;
7040
7041     switch (message)
7042     {
7043     case WM_GETICON:
7044     case WM_GETOBJECT:
7045         return 0;  /* ignore them */
7046     case WM_QUERYENDSESSION:
7047     case WM_ENDSESSION:
7048         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7049         break;
7050     }
7051
7052     msg.hwnd = hwnd;
7053     msg.message = message;
7054     msg.flags = sent|wparam|lparam;
7055     if (defwndproc_counter) msg.flags |= defwinproc;
7056     msg.wParam = wParam;
7057     msg.lParam = lParam;
7058     msg.descr = "popup";
7059     add_message(&msg);
7060
7061     if (message == WM_CREATE)
7062     {
7063         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7064         SetWindowLongA(hwnd, GWL_STYLE, style);
7065     }
7066
7067     defwndproc_counter++;
7068     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7069     defwndproc_counter--;
7070
7071     return ret;
7072 }
7073
7074 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7075 {
7076     static long defwndproc_counter = 0;
7077     static long beginpaint_counter = 0;
7078     LRESULT ret;
7079     struct recvd_message msg;
7080
7081     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7082
7083     /* ignore registered messages */
7084     if (message >= 0xc000) return 0;
7085
7086     if (log_all_parent_messages ||
7087         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7088         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7089         message == WM_ENABLE || message == WM_ENTERIDLE ||
7090         message == WM_DRAWITEM ||
7091         message == WM_IME_SETCONTEXT)
7092     {
7093         switch (message)
7094         {
7095             /* ignore */
7096             case WM_NCHITTEST:
7097                 return HTCLIENT;
7098             case WM_SETCURSOR:
7099             case WM_MOUSEMOVE:
7100             case WM_NCMOUSEMOVE:
7101                 return 0;
7102
7103             case WM_ERASEBKGND:
7104             {
7105                 RECT rc;
7106                 INT ret = GetClipBox((HDC)wParam, &rc);
7107
7108                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7109                        ret, rc.left, rc.top, rc.right, rc.bottom);
7110                 break;
7111             }
7112         }
7113
7114         msg.hwnd = hwnd;
7115         msg.message = message;
7116         msg.flags = sent|parent|wparam|lparam;
7117         if (defwndproc_counter) msg.flags |= defwinproc;
7118         if (beginpaint_counter) msg.flags |= beginpaint;
7119         msg.wParam = wParam;
7120         msg.lParam = lParam;
7121         msg.descr = "parent";
7122         add_message(&msg);
7123     }
7124
7125     if (message == WM_PAINT)
7126     {
7127         PAINTSTRUCT ps;
7128         beginpaint_counter++;
7129         BeginPaint( hwnd, &ps );
7130         beginpaint_counter--;
7131         EndPaint( hwnd, &ps );
7132         return 0;
7133     }
7134
7135     defwndproc_counter++;
7136     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7137     defwndproc_counter--;
7138
7139     return ret;
7140 }
7141
7142 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7143 {
7144     static long defwndproc_counter = 0;
7145     LRESULT ret;
7146     struct recvd_message msg;
7147
7148     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7149
7150     if (test_def_id)
7151     {
7152         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7153         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7154         if (after_end_dialog)
7155             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7156         else
7157             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7158     }
7159
7160     msg.hwnd = hwnd;
7161     msg.message = message;
7162     msg.flags = sent|wparam|lparam;
7163     if (defwndproc_counter) msg.flags |= defwinproc;
7164     msg.wParam = wParam;
7165     msg.lParam = lParam;
7166     msg.descr = "dialog";
7167     add_message(&msg);
7168
7169     defwndproc_counter++;
7170     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7171     defwndproc_counter--;
7172
7173     return ret;
7174 }
7175
7176 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7177 {
7178     static long defwndproc_counter = 0;
7179     LRESULT ret;
7180     struct recvd_message msg;
7181
7182     /* log only specific messages we are interested in */
7183     switch (message)
7184     {
7185 #if 0 /* probably log these as well */
7186     case WM_ACTIVATE:
7187     case WM_SETFOCUS:
7188     case WM_KILLFOCUS:
7189 #endif
7190     case WM_SHOWWINDOW:
7191     case WM_SIZE:
7192     case WM_MOVE:
7193     case WM_GETMINMAXINFO:
7194     case WM_WINDOWPOSCHANGING:
7195     case WM_WINDOWPOSCHANGED:
7196         break;
7197
7198     default: /* ignore */
7199         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7200         return DefWindowProcA(hwnd, message, wParam, lParam);
7201     }
7202
7203     msg.hwnd = hwnd;
7204     msg.message = message;
7205     msg.flags = sent|wparam|lparam;
7206     if (defwndproc_counter) msg.flags |= defwinproc;
7207     msg.wParam = wParam;
7208     msg.lParam = lParam;
7209     msg.descr = "show";
7210     add_message(&msg);
7211
7212     defwndproc_counter++;
7213     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7214     defwndproc_counter--;
7215
7216     return ret;
7217 }
7218
7219 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7220 {
7221     switch (msg)
7222     {
7223         case WM_CREATE: return 0;
7224         case WM_PAINT:
7225         {
7226             MSG msg2;
7227             static int i = 0;
7228
7229             if (i < 256)
7230             {
7231                 i++;
7232                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7233                 {
7234                     TranslateMessage(&msg2);
7235                     DispatchMessage(&msg2);
7236                 }
7237                 i--;
7238             }
7239             else ok(broken(1), "infinite loop\n");
7240             if ( i == 0)
7241                 paint_loop_done = 1;
7242             return DefWindowProcA(hWnd,msg,wParam,lParam);
7243         }
7244     }
7245     return DefWindowProcA(hWnd,msg,wParam,lParam);
7246 }
7247
7248 static BOOL RegisterWindowClasses(void)
7249 {
7250     WNDCLASSA cls;
7251     WNDCLASSW clsW;
7252
7253     cls.style = 0;
7254     cls.lpfnWndProc = MsgCheckProcA;
7255     cls.cbClsExtra = 0;
7256     cls.cbWndExtra = 0;
7257     cls.hInstance = GetModuleHandleA(0);
7258     cls.hIcon = 0;
7259     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7260     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7261     cls.lpszMenuName = NULL;
7262     cls.lpszClassName = "TestWindowClass";
7263     if(!RegisterClassA(&cls)) return FALSE;
7264
7265     cls.lpfnWndProc = ShowWindowProcA;
7266     cls.lpszClassName = "ShowWindowClass";
7267     if(!RegisterClassA(&cls)) return FALSE;
7268
7269     cls.lpfnWndProc = PopupMsgCheckProcA;
7270     cls.lpszClassName = "TestPopupClass";
7271     if(!RegisterClassA(&cls)) return FALSE;
7272
7273     cls.lpfnWndProc = ParentMsgCheckProcA;
7274     cls.lpszClassName = "TestParentClass";
7275     if(!RegisterClassA(&cls)) return FALSE;
7276
7277     cls.lpfnWndProc = DefWindowProcA;
7278     cls.lpszClassName = "SimpleWindowClass";
7279     if(!RegisterClassA(&cls)) return FALSE;
7280
7281     cls.lpfnWndProc = PaintLoopProcA;
7282     cls.lpszClassName = "PaintLoopWindowClass";
7283     if(!RegisterClassA(&cls)) return FALSE;
7284
7285     cls.style = CS_NOCLOSE;
7286     cls.lpszClassName = "NoCloseWindowClass";
7287     if(!RegisterClassA(&cls)) return FALSE;
7288
7289     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7290     cls.style = 0;
7291     cls.hInstance = GetModuleHandleA(0);
7292     cls.hbrBackground = 0;
7293     cls.lpfnWndProc = TestDlgProcA;
7294     cls.lpszClassName = "TestDialogClass";
7295     if(!RegisterClassA(&cls)) return FALSE;
7296
7297     clsW.style = 0;
7298     clsW.lpfnWndProc = MsgCheckProcW;
7299     clsW.cbClsExtra = 0;
7300     clsW.cbWndExtra = 0;
7301     clsW.hInstance = GetModuleHandleW(0);
7302     clsW.hIcon = 0;
7303     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7304     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7305     clsW.lpszMenuName = NULL;
7306     clsW.lpszClassName = testWindowClassW;
7307     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7308
7309     return TRUE;
7310 }
7311
7312 static BOOL is_our_logged_class(HWND hwnd)
7313 {
7314     char buf[256];
7315
7316     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7317     {
7318         if (!lstrcmpiA(buf, "TestWindowClass") ||
7319             !lstrcmpiA(buf, "ShowWindowClass") ||
7320             !lstrcmpiA(buf, "TestParentClass") ||
7321             !lstrcmpiA(buf, "TestPopupClass") ||
7322             !lstrcmpiA(buf, "SimpleWindowClass") ||
7323             !lstrcmpiA(buf, "TestDialogClass") ||
7324             !lstrcmpiA(buf, "MDI_frame_class") ||
7325             !lstrcmpiA(buf, "MDI_client_class") ||
7326             !lstrcmpiA(buf, "MDI_child_class") ||
7327             !lstrcmpiA(buf, "my_button_class") ||
7328             !lstrcmpiA(buf, "my_edit_class") ||
7329             !lstrcmpiA(buf, "static") ||
7330             !lstrcmpiA(buf, "ListBox") ||
7331             !lstrcmpiA(buf, "ComboBox") ||
7332             !lstrcmpiA(buf, "MyDialogClass") ||
7333             !lstrcmpiA(buf, "#32770") ||
7334             !lstrcmpiA(buf, "#32768"))
7335         return TRUE;
7336     }
7337     return FALSE;
7338 }
7339
7340 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7341
7342     HWND hwnd;
7343
7344     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7345
7346     if (nCode == HCBT_CLICKSKIPPED)
7347     {
7348         /* ignore this event, XP sends it a lot when switching focus between windows */
7349         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7350     }
7351
7352     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7353     {
7354         struct recvd_message msg;
7355
7356         msg.hwnd = 0;
7357         msg.message = nCode;
7358         msg.flags = hook|wparam|lparam;
7359         msg.wParam = wParam;
7360         msg.lParam = lParam;
7361         msg.descr = "CBT";
7362         add_message(&msg);
7363
7364         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7365     }
7366
7367     if (nCode == HCBT_DESTROYWND)
7368     {
7369         if (test_DestroyWindow_flag)
7370         {
7371             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7372             if (style & WS_CHILD)
7373                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7374             else if (style & WS_POPUP)
7375                 lParam = WND_POPUP_ID;
7376             else
7377                 lParam = WND_PARENT_ID;
7378         }
7379     }
7380
7381     /* Log also SetFocus(0) calls */
7382     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7383
7384     if (is_our_logged_class(hwnd))
7385     {
7386         struct recvd_message msg;
7387
7388         msg.hwnd = hwnd;
7389         msg.message = nCode;
7390         msg.flags = hook|wparam|lparam;
7391         msg.wParam = wParam;
7392         msg.lParam = lParam;
7393         msg.descr = "CBT";
7394         add_message(&msg);
7395     }
7396     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7397 }
7398
7399 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7400                                     DWORD event,
7401                                     HWND hwnd,
7402                                     LONG object_id,
7403                                     LONG child_id,
7404                                     DWORD thread_id,
7405                                     DWORD event_time)
7406 {
7407     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7408
7409     /* ignore mouse cursor events */
7410     if (object_id == OBJID_CURSOR) return;
7411
7412     if (!hwnd || is_our_logged_class(hwnd))
7413     {
7414         struct recvd_message msg;
7415
7416         msg.hwnd = hwnd;
7417         msg.message = event;
7418         msg.flags = winevent_hook|wparam|lparam;
7419         msg.wParam = object_id;
7420         msg.lParam = child_id;
7421         msg.descr = "WEH";
7422         add_message(&msg);
7423     }
7424 }
7425
7426 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7427 static const WCHAR wszAnsi[] = {'U',0};
7428
7429 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7430 {
7431     switch (uMsg)
7432     {
7433     case CB_FINDSTRINGEXACT:
7434         trace("String: %p\n", (LPCWSTR)lParam);
7435         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7436             return 1;
7437         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7438             return 0;
7439         return -1;
7440     }
7441     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7442 }
7443
7444 static const struct message WmGetTextLengthAfromW[] = {
7445     { WM_GETTEXTLENGTH, sent },
7446     { WM_GETTEXT, sent|optional },
7447     { 0 }
7448 };
7449
7450 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7451
7452 /* dummy window proc for WM_GETTEXTLENGTH test */
7453 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7454 {
7455     switch(msg)
7456     {
7457     case WM_GETTEXTLENGTH:
7458         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7459     case WM_GETTEXT:
7460         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7461         return lstrlenW( (LPWSTR)lp );
7462     default:
7463         return DefWindowProcW( hwnd, msg, wp, lp );
7464     }
7465 }
7466
7467 static void test_message_conversion(void)
7468 {
7469     static const WCHAR wszMsgConversionClass[] =
7470         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7471     WNDCLASSW cls;
7472     LRESULT lRes;
7473     HWND hwnd;
7474     WNDPROC wndproc, newproc;
7475     BOOL ret;
7476
7477     cls.style = 0;
7478     cls.lpfnWndProc = MsgConversionProcW;
7479     cls.cbClsExtra = 0;
7480     cls.cbWndExtra = 0;
7481     cls.hInstance = GetModuleHandleW(NULL);
7482     cls.hIcon = NULL;
7483     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7484     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7485     cls.lpszMenuName = NULL;
7486     cls.lpszClassName = wszMsgConversionClass;
7487     /* this call will fail on Win9x, but that doesn't matter as this test is
7488      * meaningless on those platforms */
7489     if(!RegisterClassW(&cls)) return;
7490
7491     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7492                            100, 100, 200, 200, 0, 0, 0, NULL);
7493     ok(hwnd != NULL, "Window creation failed\n");
7494
7495     /* {W, A} -> A */
7496
7497     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7498     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7499     ok(lRes == 0, "String should have been converted\n");
7500     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7501     ok(lRes == 1, "String shouldn't have been converted\n");
7502
7503     /* {W, A} -> W */
7504
7505     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7506     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7507     ok(lRes == 1, "String shouldn't have been converted\n");
7508     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7509     ok(lRes == 1, "String shouldn't have been converted\n");
7510
7511     /* Synchronous messages */
7512
7513     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7514     ok(lRes == 0, "String should have been converted\n");
7515     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7516     ok(lRes == 1, "String shouldn't have been converted\n");
7517
7518     /* Asynchronous messages */
7519
7520     SetLastError(0);
7521     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7522     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7523         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7524     SetLastError(0);
7525     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7526     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7527         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7528     SetLastError(0);
7529     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7530     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7531         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7532     SetLastError(0);
7533     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7534     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7535         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7536     SetLastError(0);
7537     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7538     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7539         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7540     SetLastError(0);
7541     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7542     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7543         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7544     SetLastError(0);
7545     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7546     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7547         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7548     SetLastError(0);
7549     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7550     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7551         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7552
7553     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7554
7555     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7556                           WS_OVERLAPPEDWINDOW,
7557                           100, 100, 200, 200, 0, 0, 0, NULL);
7558     assert(hwnd);
7559     flush_sequence();
7560     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7561     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7562     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7563         "got bad length %ld\n", lRes );
7564
7565     flush_sequence();
7566     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7567                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7568     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7569     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7570         "got bad length %ld\n", lRes );
7571
7572     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7573     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7574     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7575     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7576                                      NULL, 0, NULL, NULL ) ||
7577         broken(lRes == lstrlenW(dummy_window_text) + 37),
7578         "got bad length %ld\n", lRes );
7579
7580     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7581     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7582     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7583                                      NULL, 0, NULL, NULL ) ||
7584         broken(lRes == lstrlenW(dummy_window_text) + 37),
7585         "got bad length %ld\n", lRes );
7586
7587     ret = DestroyWindow(hwnd);
7588     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7589 }
7590
7591 struct timer_info
7592 {
7593     HWND hWnd;
7594     HANDLE handles[2];
7595     DWORD id;
7596 };
7597
7598 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7599 {
7600 }
7601
7602 #define TIMER_ID  0x19
7603
7604 static DWORD WINAPI timer_thread_proc(LPVOID x)
7605 {
7606     struct timer_info *info = x;
7607     DWORD r;
7608
7609     r = KillTimer(info->hWnd, 0x19);
7610     ok(r,"KillTimer failed in thread\n");
7611     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7612     ok(r,"SetTimer failed in thread\n");
7613     ok(r==TIMER_ID,"SetTimer id different\n");
7614     r = SetEvent(info->handles[0]);
7615     ok(r,"SetEvent failed in thread\n");
7616     return 0;
7617 }
7618
7619 static void test_timers(void)
7620 {
7621     struct timer_info info;
7622     DWORD id;
7623
7624     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7625        WS_OVERLAPPEDWINDOW ,
7626        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7627        NULL, NULL, 0);
7628
7629     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7630     ok(info.id, "SetTimer failed\n");
7631     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7632     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7633     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7634
7635     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7636
7637     WaitForSingleObject(info.handles[1], INFINITE);
7638
7639     CloseHandle(info.handles[0]);
7640     CloseHandle(info.handles[1]);
7641
7642     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7643
7644     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7645 }
7646
7647 static int count = 0;
7648 static VOID CALLBACK callback_count(
7649     HWND hwnd,
7650     UINT uMsg,
7651     UINT_PTR idEvent,
7652     DWORD dwTime
7653 )
7654 {
7655     count++;
7656 }
7657
7658 static void test_timers_no_wnd(void)
7659 {
7660     UINT_PTR id, id2;
7661     MSG msg;
7662
7663     count = 0;
7664     id = SetTimer(NULL, 0, 100, callback_count);
7665     ok(id != 0, "did not get id from SetTimer.\n");
7666     id2 = SetTimer(NULL, id, 200, callback_count);
7667     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7668     Sleep(150);
7669     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7670     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7671     Sleep(150);
7672     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7673     ok(count == 1, "did not get one count as expected (%i).\n", count);
7674     KillTimer(NULL, id);
7675     Sleep(250);
7676     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7677     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7678 }
7679
7680 /* Various win events with arbitrary parameters */
7681 static const struct message WmWinEventsSeq[] = {
7682     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7683     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7684     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7685     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7686     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7687     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7688     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7689     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7690     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7691     /* our win event hook ignores OBJID_CURSOR events */
7692     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7693     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7694     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7695     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7696     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7697     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7698     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7699     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7700     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7701     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7702     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7703     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7704     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7705     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7706     { 0 }
7707 };
7708 static const struct message WmWinEventCaretSeq[] = {
7709     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7710     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7711     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7712     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7713     { 0 }
7714 };
7715 static const struct message WmWinEventCaretSeq_2[] = {
7716     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7717     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7718     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7719     { 0 }
7720 };
7721 static const struct message WmWinEventAlertSeq[] = {
7722     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7723     { 0 }
7724 };
7725 static const struct message WmWinEventAlertSeq_2[] = {
7726     /* create window in the thread proc */
7727     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7728     /* our test event */
7729     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7730     { 0 }
7731 };
7732 static const struct message WmGlobalHookSeq_1[] = {
7733     /* create window in the thread proc */
7734     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7735     /* our test events */
7736     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7737     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7738     { 0 }
7739 };
7740 static const struct message WmGlobalHookSeq_2[] = {
7741     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7742     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7743     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7744     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7745     { 0 }
7746 };
7747
7748 static const struct message WmMouseLLHookSeq[] = {
7749     { WM_MOUSEMOVE, hook },
7750     { WM_LBUTTONUP, hook },
7751     { WM_MOUSEMOVE, hook },
7752     { 0 }
7753 };
7754
7755 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7756                                          DWORD event,
7757                                          HWND hwnd,
7758                                          LONG object_id,
7759                                          LONG child_id,
7760                                          DWORD thread_id,
7761                                          DWORD event_time)
7762 {
7763     char buf[256];
7764
7765     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7766     {
7767         if (!lstrcmpiA(buf, "TestWindowClass") ||
7768             !lstrcmpiA(buf, "static"))
7769         {
7770             struct recvd_message msg;
7771
7772             msg.hwnd = hwnd;
7773             msg.message = event;
7774             msg.flags = winevent_hook|wparam|lparam;
7775             msg.wParam = object_id;
7776             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7777             msg.descr = "WEH_2";
7778             add_message(&msg);
7779         }
7780     }
7781 }
7782
7783 static HHOOK hCBT_global_hook;
7784 static DWORD cbt_global_hook_thread_id;
7785
7786 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7787
7788     HWND hwnd;
7789     char buf[256];
7790
7791     if (nCode == HCBT_SYSCOMMAND)
7792     {
7793         struct recvd_message msg;
7794
7795         msg.hwnd = 0;
7796         msg.message = nCode;
7797         msg.flags = hook|wparam|lparam;
7798         msg.wParam = wParam;
7799         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7800         msg.descr = "CBT_2";
7801         add_message(&msg);
7802
7803         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7804     }
7805     /* WH_MOUSE_LL hook */
7806     if (nCode == HC_ACTION)
7807     {
7808         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7809
7810         /* we can't test for real mouse events */
7811         if (mhll->flags & LLMHF_INJECTED)
7812         {
7813             struct recvd_message msg;
7814
7815             memset (&msg, 0, sizeof (msg));
7816             msg.message = wParam;
7817             msg.flags = hook;
7818             msg.descr = "CBT_2";
7819             add_message(&msg);
7820         }
7821         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7822     }
7823
7824     /* Log also SetFocus(0) calls */
7825     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7826
7827     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7828     {
7829         if (!lstrcmpiA(buf, "TestWindowClass") ||
7830             !lstrcmpiA(buf, "static"))
7831         {
7832             struct recvd_message msg;
7833
7834             msg.hwnd = hwnd;
7835             msg.message = nCode;
7836             msg.flags = hook|wparam|lparam;
7837             msg.wParam = wParam;
7838             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7839             msg.descr = "CBT_2";
7840             add_message(&msg);
7841         }
7842     }
7843     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7844 }
7845
7846 static DWORD WINAPI win_event_global_thread_proc(void *param)
7847 {
7848     HWND hwnd;
7849     MSG msg;
7850     HANDLE hevent = *(HANDLE *)param;
7851
7852     assert(pNotifyWinEvent);
7853
7854     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7855     assert(hwnd);
7856     trace("created thread window %p\n", hwnd);
7857
7858     *(HWND *)param = hwnd;
7859
7860     flush_sequence();
7861     /* this event should be received only by our new hook proc,
7862      * an old one does not expect an event from another thread.
7863      */
7864     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7865     SetEvent(hevent);
7866
7867     while (GetMessage(&msg, 0, 0, 0))
7868     {
7869         TranslateMessage(&msg);
7870         DispatchMessage(&msg);
7871     }
7872     return 0;
7873 }
7874
7875 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7876 {
7877     HWND hwnd;
7878     MSG msg;
7879     HANDLE hevent = *(HANDLE *)param;
7880
7881     flush_sequence();
7882     /* these events should be received only by our new hook proc,
7883      * an old one does not expect an event from another thread.
7884      */
7885
7886     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7887     assert(hwnd);
7888     trace("created thread window %p\n", hwnd);
7889
7890     *(HWND *)param = hwnd;
7891
7892     /* Windows doesn't like when a thread plays games with the focus,
7893        that leads to all kinds of misbehaviours and failures to activate
7894        a window. So, better keep next lines commented out.
7895     SetFocus(0);
7896     SetFocus(hwnd);*/
7897
7898     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7899     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7900
7901     SetEvent(hevent);
7902
7903     while (GetMessage(&msg, 0, 0, 0))
7904     {
7905         TranslateMessage(&msg);
7906         DispatchMessage(&msg);
7907     }
7908     return 0;
7909 }
7910
7911 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7912 {
7913     HWND hwnd;
7914     MSG msg;
7915     HANDLE hevent = *(HANDLE *)param;
7916
7917     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7918     assert(hwnd);
7919     trace("created thread window %p\n", hwnd);
7920
7921     *(HWND *)param = hwnd;
7922
7923     flush_sequence();
7924
7925     /* Windows doesn't like when a thread plays games with the focus,
7926      * that leads to all kinds of misbehaviours and failures to activate
7927      * a window. So, better don't generate a mouse click message below.
7928      */
7929     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7930     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7931     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7932
7933     SetEvent(hevent);
7934     while (GetMessage(&msg, 0, 0, 0))
7935     {
7936         TranslateMessage(&msg);
7937         DispatchMessage(&msg);
7938     }
7939     return 0;
7940 }
7941
7942 static void test_winevents(void)
7943 {
7944     BOOL ret;
7945     MSG msg;
7946     HWND hwnd, hwnd2;
7947     UINT i;
7948     HANDLE hthread, hevent;
7949     DWORD tid;
7950     HWINEVENTHOOK hhook;
7951     const struct message *events = WmWinEventsSeq;
7952
7953     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7954                            WS_OVERLAPPEDWINDOW,
7955                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7956                            NULL, NULL, 0);
7957     assert(hwnd);
7958
7959     /****** start of global hook test *************/
7960     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7961     if (!hCBT_global_hook)
7962     {
7963         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7964         skip( "cannot set global hook\n" );
7965         return;
7966     }
7967
7968     hevent = CreateEventA(NULL, 0, 0, NULL);
7969     assert(hevent);
7970     hwnd2 = hevent;
7971
7972     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7973     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7974
7975     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7976
7977     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7978
7979     flush_sequence();
7980     /* this one should be received only by old hook proc */
7981     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7982     /* this one should be received only by old hook proc */
7983     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7984
7985     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7986
7987     ret = UnhookWindowsHookEx(hCBT_global_hook);
7988     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7989
7990     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7991     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7992     CloseHandle(hthread);
7993     CloseHandle(hevent);
7994     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7995     /****** end of global hook test *************/
7996
7997     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7998     {
7999         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8000         return;
8001     }
8002
8003     flush_sequence();
8004
8005     if (0)
8006     {
8007     /* this test doesn't pass under Win9x */
8008     /* win2k ignores events with hwnd == 0 */
8009     SetLastError(0xdeadbeef);
8010     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8011     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8012        GetLastError() == 0xdeadbeef, /* Win9x */
8013        "unexpected error %d\n", GetLastError());
8014     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8015     }
8016
8017     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8018         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8019
8020     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8021
8022     /****** start of event filtering test *************/
8023     hhook = pSetWinEventHook(
8024         EVENT_OBJECT_SHOW, /* 0x8002 */
8025         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8026         GetModuleHandleA(0), win_event_global_hook_proc,
8027         GetCurrentProcessId(), 0,
8028         WINEVENT_INCONTEXT);
8029     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8030
8031     hevent = CreateEventA(NULL, 0, 0, NULL);
8032     assert(hevent);
8033     hwnd2 = hevent;
8034
8035     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8036     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8037
8038     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8039
8040     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8041
8042     flush_sequence();
8043     /* this one should be received only by old hook proc */
8044     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8045     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8046     /* this one should be received only by old hook proc */
8047     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8048
8049     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8050
8051     ret = pUnhookWinEvent(hhook);
8052     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8053
8054     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8055     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8056     CloseHandle(hthread);
8057     CloseHandle(hevent);
8058     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8059     /****** end of event filtering test *************/
8060
8061     /****** start of out of context event test *************/
8062     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8063         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8064         WINEVENT_OUTOFCONTEXT);
8065     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8066
8067     hevent = CreateEventA(NULL, 0, 0, NULL);
8068     assert(hevent);
8069     hwnd2 = hevent;
8070
8071     flush_sequence();
8072
8073     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8074     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8075
8076     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8077
8078     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8079     /* process pending winevent messages */
8080     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8081     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8082
8083     flush_sequence();
8084     /* this one should be received only by old hook proc */
8085     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8086     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8087     /* this one should be received only by old hook proc */
8088     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8089
8090     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8091     /* process pending winevent messages */
8092     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8093     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8094
8095     ret = pUnhookWinEvent(hhook);
8096     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8097
8098     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8099     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8100     CloseHandle(hthread);
8101     CloseHandle(hevent);
8102     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8103     /****** end of out of context event test *************/
8104
8105     /****** start of MOUSE_LL hook test *************/
8106     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8107     /* WH_MOUSE_LL is not supported on Win9x platforms */
8108     if (!hCBT_global_hook)
8109     {
8110         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8111         goto skip_mouse_ll_hook_test;
8112     }
8113
8114     hevent = CreateEventA(NULL, 0, 0, NULL);
8115     assert(hevent);
8116     hwnd2 = hevent;
8117
8118     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8119     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8120
8121     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8122         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8123
8124     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8125     flush_sequence();
8126
8127     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8128     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8129     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8130
8131     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8132
8133     ret = UnhookWindowsHookEx(hCBT_global_hook);
8134     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8135
8136     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8137     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8138     CloseHandle(hthread);
8139     CloseHandle(hevent);
8140     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8141     /****** end of MOUSE_LL hook test *************/
8142 skip_mouse_ll_hook_test:
8143
8144     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8145 }
8146
8147 static void test_set_hook(void)
8148 {
8149     BOOL ret;
8150     HHOOK hhook;
8151     HWINEVENTHOOK hwinevent_hook;
8152
8153     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8154     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8155     UnhookWindowsHookEx(hhook);
8156
8157     if (0)
8158     {
8159     /* this test doesn't pass under Win9x: BUG! */
8160     SetLastError(0xdeadbeef);
8161     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8162     ok(!hhook, "global hook requires hModule != 0\n");
8163     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8164     }
8165
8166     SetLastError(0xdeadbeef);
8167     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8168     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8169     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8170        GetLastError() == 0xdeadbeef, /* Win9x */
8171        "unexpected error %d\n", GetLastError());
8172
8173     SetLastError(0xdeadbeef);
8174     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8175     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8176        GetLastError() == 0xdeadbeef, /* Win9x */
8177        "unexpected error %d\n", GetLastError());
8178
8179     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8180
8181     /* even process local incontext hooks require hmodule */
8182     SetLastError(0xdeadbeef);
8183     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8184         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8185     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8186     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8187        GetLastError() == 0xdeadbeef, /* Win9x */
8188        "unexpected error %d\n", GetLastError());
8189
8190     /* even thread local incontext hooks require hmodule */
8191     SetLastError(0xdeadbeef);
8192     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8193         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8194     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8195     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8196        GetLastError() == 0xdeadbeef, /* Win9x */
8197        "unexpected error %d\n", GetLastError());
8198
8199     if (0)
8200     {
8201     /* these 3 tests don't pass under Win9x */
8202     SetLastError(0xdeadbeef);
8203     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8204         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8205     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8206     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8207
8208     SetLastError(0xdeadbeef);
8209     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8210         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8211     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8212     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8213
8214     SetLastError(0xdeadbeef);
8215     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8216         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8217     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8218     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8219     }
8220
8221     SetLastError(0xdeadbeef);
8222     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8223         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8224     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8225     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8226     ret = pUnhookWinEvent(hwinevent_hook);
8227     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8228
8229 todo_wine {
8230     /* This call succeeds under win2k SP4, but fails under Wine.
8231        Does win2k test/use passed process id? */
8232     SetLastError(0xdeadbeef);
8233     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8234         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8235     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8236     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8237     ret = pUnhookWinEvent(hwinevent_hook);
8238     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8239 }
8240
8241     SetLastError(0xdeadbeef);
8242     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8243     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8244         GetLastError() == 0xdeadbeef, /* Win9x */
8245         "unexpected error %d\n", GetLastError());
8246 }
8247
8248 static const struct message ScrollWindowPaint1[] = {
8249     { WM_PAINT, sent },
8250     { WM_ERASEBKGND, sent|beginpaint },
8251     { WM_GETTEXTLENGTH, sent|optional },
8252     { WM_PAINT, sent|optional },
8253     { WM_NCPAINT, sent|beginpaint|optional },
8254     { WM_GETTEXT, sent|beginpaint|optional },
8255     { WM_GETTEXT, sent|beginpaint|optional },
8256     { WM_GETTEXT, sent|beginpaint|optional },
8257     { WM_ERASEBKGND, sent|beginpaint|optional },
8258     { 0 }
8259 };
8260
8261 static const struct message ScrollWindowPaint2[] = {
8262     { WM_PAINT, sent },
8263     { 0 }
8264 };
8265
8266 static void test_scrollwindowex(void)
8267 {
8268     HWND hwnd, hchild;
8269     RECT rect={0,0,130,130};
8270
8271     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8272             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8273             100, 100, 200, 200, 0, 0, 0, NULL);
8274     ok (hwnd != 0, "Failed to create overlapped window\n");
8275     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8276             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8277             10, 10, 150, 150, hwnd, 0, 0, NULL);
8278     ok (hchild != 0, "Failed to create child\n");
8279     UpdateWindow(hwnd);
8280     flush_events();
8281     flush_sequence();
8282
8283     /* scroll without the child window */
8284     trace("start scroll\n");
8285     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8286             SW_ERASE|SW_INVALIDATE);
8287     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8288     trace("end scroll\n");
8289     flush_sequence();
8290     flush_events();
8291     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8292     flush_events();
8293     flush_sequence();
8294
8295     /* Now without the SW_ERASE flag */
8296     trace("start scroll\n");
8297     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8298     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8299     trace("end scroll\n");
8300     flush_sequence();
8301     flush_events();
8302     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8303     flush_events();
8304     flush_sequence();
8305
8306     /* now scroll the child window as well */
8307     trace("start scroll\n");
8308     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8309             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8310     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8311     /* windows sometimes a WM_MOVE */
8312     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8313     trace("end scroll\n");
8314     flush_sequence();
8315     flush_events();
8316     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8317     flush_events();
8318     flush_sequence();
8319
8320     /* now scroll with ScrollWindow() */
8321     trace("start scroll with ScrollWindow\n");
8322     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8323     trace("end scroll\n");
8324     flush_sequence();
8325     flush_events();
8326     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8327
8328     ok(DestroyWindow(hchild), "failed to destroy window\n");
8329     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8330     flush_sequence();
8331 }
8332
8333 static const struct message destroy_window_with_children[] = {
8334     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8335     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8336     { 0x0090, sent|optional },
8337     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8338     { 0x0090, sent|optional },
8339     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8340     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8341     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8342     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8343     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8344     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8345     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8346     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8347     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8348     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8349     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8350     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8351     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8352     { 0 }
8353 };
8354
8355 static void test_DestroyWindow(void)
8356 {
8357     BOOL ret;
8358     HWND parent, child1, child2, child3, child4, test;
8359     UINT_PTR child_id = WND_CHILD_ID + 1;
8360
8361     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8362                              100, 100, 200, 200, 0, 0, 0, NULL);
8363     assert(parent != 0);
8364     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8365                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8366     assert(child1 != 0);
8367     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8368                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8369     assert(child2 != 0);
8370     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8371                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8372     assert(child3 != 0);
8373     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8374                              0, 0, 50, 50, parent, 0, 0, NULL);
8375     assert(child4 != 0);
8376
8377     /* test owner/parent of child2 */
8378     test = GetParent(child2);
8379     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8380     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8381     if(pGetAncestor) {
8382         test = pGetAncestor(child2, GA_PARENT);
8383         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8384     }
8385     test = GetWindow(child2, GW_OWNER);
8386     ok(!test, "wrong owner %p\n", test);
8387
8388     test = SetParent(child2, parent);
8389     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8390
8391     /* test owner/parent of the parent */
8392     test = GetParent(parent);
8393     ok(!test, "wrong parent %p\n", test);
8394     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8395     if(pGetAncestor) {
8396         test = pGetAncestor(parent, GA_PARENT);
8397         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8398     }
8399     test = GetWindow(parent, GW_OWNER);
8400     ok(!test, "wrong owner %p\n", test);
8401
8402     /* test owner/parent of child1 */
8403     test = GetParent(child1);
8404     ok(test == parent, "wrong parent %p\n", test);
8405     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8406     if(pGetAncestor) {
8407         test = pGetAncestor(child1, GA_PARENT);
8408         ok(test == parent, "wrong parent %p\n", test);
8409     }
8410     test = GetWindow(child1, GW_OWNER);
8411     ok(!test, "wrong owner %p\n", test);
8412
8413     /* test owner/parent of child2 */
8414     test = GetParent(child2);
8415     ok(test == parent, "wrong parent %p\n", test);
8416     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8417     if(pGetAncestor) {
8418         test = pGetAncestor(child2, GA_PARENT);
8419         ok(test == parent, "wrong parent %p\n", test);
8420     }
8421     test = GetWindow(child2, GW_OWNER);
8422     ok(!test, "wrong owner %p\n", test);
8423
8424     /* test owner/parent of child3 */
8425     test = GetParent(child3);
8426     ok(test == child1, "wrong parent %p\n", test);
8427     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8428     if(pGetAncestor) {
8429         test = pGetAncestor(child3, GA_PARENT);
8430         ok(test == child1, "wrong parent %p\n", test);
8431     }
8432     test = GetWindow(child3, GW_OWNER);
8433     ok(!test, "wrong owner %p\n", test);
8434
8435     /* test owner/parent of child4 */
8436     test = GetParent(child4);
8437     ok(test == parent, "wrong parent %p\n", test);
8438     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8439     if(pGetAncestor) {
8440         test = pGetAncestor(child4, GA_PARENT);
8441         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8442     }
8443     test = GetWindow(child4, GW_OWNER);
8444     ok(test == parent, "wrong owner %p\n", test);
8445
8446     flush_sequence();
8447
8448     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8449            parent, child1, child2, child3, child4);
8450
8451     SetCapture(child4);
8452     test = GetCapture();
8453     ok(test == child4, "wrong capture window %p\n", test);
8454
8455     test_DestroyWindow_flag = TRUE;
8456     ret = DestroyWindow(parent);
8457     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8458     test_DestroyWindow_flag = FALSE;
8459     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8460
8461     ok(!IsWindow(parent), "parent still exists\n");
8462     ok(!IsWindow(child1), "child1 still exists\n");
8463     ok(!IsWindow(child2), "child2 still exists\n");
8464     ok(!IsWindow(child3), "child3 still exists\n");
8465     ok(!IsWindow(child4), "child4 still exists\n");
8466
8467     test = GetCapture();
8468     ok(!test, "wrong capture window %p\n", test);
8469 }
8470
8471
8472 static const struct message WmDispatchPaint[] = {
8473     { WM_NCPAINT, sent },
8474     { WM_GETTEXT, sent|defwinproc|optional },
8475     { WM_GETTEXT, sent|defwinproc|optional },
8476     { WM_ERASEBKGND, sent },
8477     { 0 }
8478 };
8479
8480 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8481 {
8482     if (message == WM_PAINT) return 0;
8483     return MsgCheckProcA( hwnd, message, wParam, lParam );
8484 }
8485
8486 static void test_DispatchMessage(void)
8487 {
8488     RECT rect;
8489     MSG msg;
8490     int count;
8491     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8492                                100, 100, 200, 200, 0, 0, 0, NULL);
8493     ShowWindow( hwnd, SW_SHOW );
8494     UpdateWindow( hwnd );
8495     flush_events();
8496     flush_sequence();
8497     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8498
8499     SetRect( &rect, -5, -5, 5, 5 );
8500     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8501     count = 0;
8502     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8503     {
8504         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8505         else
8506         {
8507             flush_sequence();
8508             DispatchMessage( &msg );
8509             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8510             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8511             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8512             if (++count > 10) break;
8513         }
8514     }
8515     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8516
8517     trace("now without DispatchMessage\n");
8518     flush_sequence();
8519     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8520     count = 0;
8521     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8522     {
8523         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8524         else
8525         {
8526             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8527             flush_sequence();
8528             /* this will send WM_NCCPAINT just like DispatchMessage does */
8529             GetUpdateRgn( hwnd, hrgn, TRUE );
8530             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8531             DeleteObject( hrgn );
8532             GetClientRect( hwnd, &rect );
8533             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8534             ok( !count, "Got multiple WM_PAINTs\n" );
8535             if (++count > 10) break;
8536         }
8537     }
8538     DestroyWindow(hwnd);
8539 }
8540
8541
8542 static const struct message WmUser[] = {
8543     { WM_USER, sent },
8544     { 0 }
8545 };
8546
8547 struct sendmsg_info
8548 {
8549     HWND  hwnd;
8550     DWORD timeout;
8551     DWORD ret;
8552 };
8553
8554 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8555 {
8556     struct sendmsg_info *info = arg;
8557     SetLastError( 0xdeadbeef );
8558     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8559     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8560                         broken(GetLastError() == 0),  /* win9x */
8561                         "unexpected error %d\n", GetLastError());
8562     return 0;
8563 }
8564
8565 static void wait_for_thread( HANDLE thread )
8566 {
8567     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8568     {
8569         MSG msg;
8570         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8571     }
8572 }
8573
8574 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8575 {
8576     if (message == WM_USER) Sleep(200);
8577     return MsgCheckProcA( hwnd, message, wParam, lParam );
8578 }
8579
8580 static void test_SendMessageTimeout(void)
8581 {
8582     HANDLE thread;
8583     struct sendmsg_info info;
8584     DWORD tid;
8585     BOOL is_win9x;
8586
8587     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8588                                100, 100, 200, 200, 0, 0, 0, NULL);
8589     flush_events();
8590     flush_sequence();
8591
8592     info.timeout = 1000;
8593     info.ret = 0xdeadbeef;
8594     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8595     wait_for_thread( thread );
8596     CloseHandle( thread );
8597     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8598     ok_sequence( WmUser, "WmUser", FALSE );
8599
8600     info.timeout = 1;
8601     info.ret = 0xdeadbeef;
8602     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8603     Sleep(100);  /* SendMessageTimeout should time out here */
8604     wait_for_thread( thread );
8605     CloseHandle( thread );
8606     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8607     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8608
8609     /* 0 means infinite timeout (but not on win9x) */
8610     info.timeout = 0;
8611     info.ret = 0xdeadbeef;
8612     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8613     Sleep(100);
8614     wait_for_thread( thread );
8615     CloseHandle( thread );
8616     is_win9x = !info.ret;
8617     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8618     else ok_sequence( WmUser, "WmUser", FALSE );
8619
8620     /* timeout is treated as signed despite the prototype (but not on win9x) */
8621     info.timeout = 0x7fffffff;
8622     info.ret = 0xdeadbeef;
8623     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8624     Sleep(100);
8625     wait_for_thread( thread );
8626     CloseHandle( thread );
8627     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8628     ok_sequence( WmUser, "WmUser", FALSE );
8629
8630     info.timeout = 0x80000000;
8631     info.ret = 0xdeadbeef;
8632     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8633     Sleep(100);
8634     wait_for_thread( thread );
8635     CloseHandle( thread );
8636     if (is_win9x)
8637     {
8638         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8639         ok_sequence( WmUser, "WmUser", FALSE );
8640     }
8641     else
8642     {
8643         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8644         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8645     }
8646
8647     /* now check for timeout during message processing */
8648     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8649     info.timeout = 100;
8650     info.ret = 0xdeadbeef;
8651     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8652     wait_for_thread( thread );
8653     CloseHandle( thread );
8654     /* we should time out but still get the message */
8655     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8656     ok_sequence( WmUser, "WmUser", FALSE );
8657
8658     DestroyWindow( info.hwnd );
8659 }
8660
8661
8662 /****************** edit message test *************************/
8663 #define ID_EDIT 0x1234
8664 static const struct message sl_edit_setfocus[] =
8665 {
8666     { HCBT_SETFOCUS, hook },
8667     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8668     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8669     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8670     { WM_SETFOCUS, sent|wparam, 0 },
8671     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8672     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8673     { WM_CTLCOLOREDIT, sent|parent },
8674     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8675     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8676     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8677     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8678     { 0 }
8679 };
8680 static const struct message ml_edit_setfocus[] =
8681 {
8682     { HCBT_SETFOCUS, hook },
8683     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8684     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8685     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8686     { WM_SETFOCUS, sent|wparam, 0 },
8687     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8688     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8689     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8690     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8691     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8692     { 0 }
8693 };
8694 static const struct message sl_edit_killfocus[] =
8695 {
8696     { HCBT_SETFOCUS, hook },
8697     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8698     { WM_KILLFOCUS, sent|wparam, 0 },
8699     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8700     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8701     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8702     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8703     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8704     { 0 }
8705 };
8706 static const struct message sl_edit_lbutton_dblclk[] =
8707 {
8708     { WM_LBUTTONDBLCLK, sent },
8709     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8710     { 0 }
8711 };
8712 static const struct message sl_edit_lbutton_down[] =
8713 {
8714     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8715     { HCBT_SETFOCUS, hook },
8716     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8717     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8718     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8719     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8720     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8721     { WM_CTLCOLOREDIT, sent|parent },
8722     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8723     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8724     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8725     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8726     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8727     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8728     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8729     { WM_CTLCOLOREDIT, sent|parent|optional },
8730     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8731     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8732     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8733     { 0 }
8734 };
8735 static const struct message ml_edit_lbutton_down[] =
8736 {
8737     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8738     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8739     { HCBT_SETFOCUS, hook },
8740     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8741     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8742     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8743     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8744     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8745     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8746     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8747     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8748     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8749     { 0 }
8750 };
8751 static const struct message sl_edit_lbutton_up[] =
8752 {
8753     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8754     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8755     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8756     { WM_CAPTURECHANGED, sent|defwinproc },
8757     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8758     { 0 }
8759 };
8760 static const struct message ml_edit_lbutton_up[] =
8761 {
8762     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8763     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8764     { WM_CAPTURECHANGED, sent|defwinproc },
8765     { 0 }
8766 };
8767
8768 static WNDPROC old_edit_proc;
8769
8770 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8771 {
8772     static long defwndproc_counter = 0;
8773     LRESULT ret;
8774     struct recvd_message msg;
8775
8776     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8777
8778     msg.hwnd = hwnd;
8779     msg.message = message;
8780     msg.flags = sent|wparam|lparam;
8781     if (defwndproc_counter) msg.flags |= defwinproc;
8782     msg.wParam = wParam;
8783     msg.lParam = lParam;
8784     msg.descr = "edit";
8785     add_message(&msg);
8786
8787     defwndproc_counter++;
8788     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8789     defwndproc_counter--;
8790
8791     return ret;
8792 }
8793
8794 static void subclass_edit(void)
8795 {
8796     WNDCLASSA cls;
8797
8798     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8799
8800     old_edit_proc = cls.lpfnWndProc;
8801
8802     cls.hInstance = GetModuleHandle(0);
8803     cls.lpfnWndProc = edit_hook_proc;
8804     cls.lpszClassName = "my_edit_class";
8805     UnregisterClass(cls.lpszClassName, cls.hInstance);
8806     if (!RegisterClassA(&cls)) assert(0);
8807 }
8808
8809 static void test_edit_messages(void)
8810 {
8811     HWND hwnd, parent;
8812     DWORD dlg_code;
8813
8814     subclass_edit();
8815     log_all_parent_messages++;
8816
8817     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8818                              100, 100, 200, 200, 0, 0, 0, NULL);
8819     ok (parent != 0, "Failed to create parent window\n");
8820
8821     /* test single line edit */
8822     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8823                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8824     ok(hwnd != 0, "Failed to create edit window\n");
8825
8826     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8827     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8828
8829     ShowWindow(hwnd, SW_SHOW);
8830     UpdateWindow(hwnd);
8831     SetFocus(0);
8832     flush_sequence();
8833
8834     SetFocus(hwnd);
8835     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8836
8837     SetFocus(0);
8838     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8839
8840     SetFocus(0);
8841     ReleaseCapture();
8842     flush_sequence();
8843
8844     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8845     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8846
8847     SetFocus(0);
8848     ReleaseCapture();
8849     flush_sequence();
8850
8851     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8852     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8853
8854     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8855     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8856
8857     DestroyWindow(hwnd);
8858
8859     /* test multiline edit */
8860     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8861                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8862     ok(hwnd != 0, "Failed to create edit window\n");
8863
8864     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8865     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8866        "wrong dlg_code %08x\n", dlg_code);
8867
8868     ShowWindow(hwnd, SW_SHOW);
8869     UpdateWindow(hwnd);
8870     SetFocus(0);
8871     flush_sequence();
8872
8873     SetFocus(hwnd);
8874     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8875
8876     SetFocus(0);
8877     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8878
8879     SetFocus(0);
8880     ReleaseCapture();
8881     flush_sequence();
8882
8883     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8884     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8885
8886     SetFocus(0);
8887     ReleaseCapture();
8888     flush_sequence();
8889
8890     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8891     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8892
8893     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8894     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8895
8896     DestroyWindow(hwnd);
8897     DestroyWindow(parent);
8898
8899     log_all_parent_messages--;
8900 }
8901
8902 /**************************** End of Edit test ******************************/
8903
8904 static const struct message WmKeyDownSkippedSeq[] =
8905 {
8906     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8907     { 0 }
8908 };
8909 static const struct message WmKeyDownWasDownSkippedSeq[] =
8910 {
8911     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8912     { 0 }
8913 };
8914 static const struct message WmKeyUpSkippedSeq[] =
8915 {
8916     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8917     { 0 }
8918 };
8919 static const struct message WmUserKeyUpSkippedSeq[] =
8920 {
8921     { WM_USER, sent },
8922     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8923     { 0 }
8924 };
8925
8926 #define EV_STOP 0
8927 #define EV_SENDMSG 1
8928 #define EV_ACK 2
8929
8930 struct peekmsg_info
8931 {
8932     HWND  hwnd;
8933     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8934 };
8935
8936 static DWORD CALLBACK send_msg_thread_2(void *param)
8937 {
8938     DWORD ret;
8939     struct peekmsg_info *info = param;
8940
8941     trace("thread: looping\n");
8942     SetEvent(info->hevent[EV_ACK]);
8943
8944     while (1)
8945     {
8946         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8947
8948         switch (ret)
8949         {
8950         case WAIT_OBJECT_0 + EV_STOP:
8951             trace("thread: exiting\n");
8952             return 0;
8953
8954         case WAIT_OBJECT_0 + EV_SENDMSG:
8955             trace("thread: sending message\n");
8956             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8957                 "SendNotifyMessageA failed error %u\n", GetLastError());
8958             SetEvent(info->hevent[EV_ACK]);
8959             break;
8960
8961         default:
8962             trace("unexpected return: %04x\n", ret);
8963             assert(0);
8964             break;
8965         }
8966     }
8967     return 0;
8968 }
8969
8970 static void test_PeekMessage(void)
8971 {
8972     MSG msg;
8973     HANDLE hthread;
8974     DWORD tid, qstatus;
8975     UINT qs_all_input = QS_ALLINPUT;
8976     UINT qs_input = QS_INPUT;
8977     BOOL ret;
8978     struct peekmsg_info info;
8979
8980     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8981                               100, 100, 200, 200, 0, 0, 0, NULL);
8982     assert(info.hwnd);
8983     ShowWindow(info.hwnd, SW_SHOW);
8984     UpdateWindow(info.hwnd);
8985     SetFocus(info.hwnd);
8986
8987     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8988     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8989     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8990
8991     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8992     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8993
8994     flush_events();
8995     flush_sequence();
8996
8997     SetLastError(0xdeadbeef);
8998     qstatus = GetQueueStatus(qs_all_input);
8999     if (GetLastError() == ERROR_INVALID_FLAGS)
9000     {
9001         trace("QS_RAWINPUT not supported on this platform\n");
9002         qs_all_input &= ~QS_RAWINPUT;
9003         qs_input &= ~QS_RAWINPUT;
9004     }
9005     if (qstatus & QS_POSTMESSAGE)
9006     {
9007         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9008         qstatus = GetQueueStatus(qs_all_input);
9009     }
9010     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9011
9012     trace("signalling to send message\n");
9013     SetEvent(info.hevent[EV_SENDMSG]);
9014     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9015
9016     /* pass invalid QS_xxxx flags */
9017     SetLastError(0xdeadbeef);
9018     qstatus = GetQueueStatus(0xffffffff);
9019     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9020     if (!qstatus)
9021     {
9022         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9023         qstatus = GetQueueStatus(qs_all_input);
9024     }
9025     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9026     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9027        "wrong qstatus %08x\n", qstatus);
9028
9029     msg.message = 0;
9030     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9031     ok(!ret,
9032        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9033         msg.message);
9034     ok_sequence(WmUser, "WmUser", FALSE);
9035
9036     qstatus = GetQueueStatus(qs_all_input);
9037     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9038
9039     keybd_event('N', 0, 0, 0);
9040     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9041     qstatus = GetQueueStatus(qs_all_input);
9042     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9043     {
9044         skip( "queuing key events not supported\n" );
9045         goto done;
9046     }
9047     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
9048        "wrong qstatus %08x\n", qstatus);
9049
9050     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9051     qstatus = GetQueueStatus(qs_all_input);
9052     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9053        "wrong qstatus %08x\n", qstatus);
9054
9055     InvalidateRect(info.hwnd, NULL, FALSE);
9056     qstatus = GetQueueStatus(qs_all_input);
9057     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9058        "wrong qstatus %08x\n", qstatus);
9059
9060     trace("signalling to send message\n");
9061     SetEvent(info.hevent[EV_SENDMSG]);
9062     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9063
9064     qstatus = GetQueueStatus(qs_all_input);
9065     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9066        "wrong qstatus %08x\n", qstatus);
9067
9068     msg.message = 0;
9069     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9070     if (ret && msg.message == WM_CHAR)
9071     {
9072         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9073         goto done;
9074     }
9075     ok(!ret,
9076        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9077         msg.message);
9078     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9079     {
9080         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9081         goto done;
9082     }
9083     ok_sequence(WmUser, "WmUser", FALSE);
9084
9085     qstatus = GetQueueStatus(qs_all_input);
9086     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9087        "wrong qstatus %08x\n", qstatus);
9088
9089     trace("signalling to send message\n");
9090     SetEvent(info.hevent[EV_SENDMSG]);
9091     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9092
9093     qstatus = GetQueueStatus(qs_all_input);
9094     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9095        "wrong qstatus %08x\n", qstatus);
9096
9097     msg.message = 0;
9098     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9099     ok(!ret,
9100        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9101         msg.message);
9102     ok_sequence(WmUser, "WmUser", FALSE);
9103
9104     qstatus = GetQueueStatus(qs_all_input);
9105     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9106        "wrong qstatus %08x\n", qstatus);
9107
9108     msg.message = 0;
9109     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9110     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9111        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9112        ret, msg.message, msg.wParam);
9113     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9114
9115     qstatus = GetQueueStatus(qs_all_input);
9116     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9117        "wrong qstatus %08x\n", qstatus);
9118
9119     msg.message = 0;
9120     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9121     ok(!ret,
9122        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9123         msg.message);
9124     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9125
9126     qstatus = GetQueueStatus(qs_all_input);
9127     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9128        "wrong qstatus %08x\n", qstatus);
9129
9130     msg.message = 0;
9131     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9132     ok(ret && msg.message == WM_PAINT,
9133        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9134     DispatchMessageA(&msg);
9135     ok_sequence(WmPaint, "WmPaint", FALSE);
9136
9137     qstatus = GetQueueStatus(qs_all_input);
9138     ok(qstatus == MAKELONG(0, QS_KEY),
9139        "wrong qstatus %08x\n", qstatus);
9140
9141     msg.message = 0;
9142     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9143     ok(!ret,
9144        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9145         msg.message);
9146     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9147
9148     qstatus = GetQueueStatus(qs_all_input);
9149     ok(qstatus == MAKELONG(0, QS_KEY),
9150        "wrong qstatus %08x\n", qstatus);
9151
9152     trace("signalling to send message\n");
9153     SetEvent(info.hevent[EV_SENDMSG]);
9154     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9155
9156     qstatus = GetQueueStatus(qs_all_input);
9157     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9158        "wrong qstatus %08x\n", qstatus);
9159
9160     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9161
9162     qstatus = GetQueueStatus(qs_all_input);
9163     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9164        "wrong qstatus %08x\n", qstatus);
9165
9166     msg.message = 0;
9167     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9168     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9169        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9170        ret, msg.message, msg.wParam);
9171     ok_sequence(WmUser, "WmUser", FALSE);
9172
9173     qstatus = GetQueueStatus(qs_all_input);
9174     ok(qstatus == MAKELONG(0, QS_KEY),
9175        "wrong qstatus %08x\n", qstatus);
9176
9177     msg.message = 0;
9178     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9179     ok(!ret,
9180        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9181         msg.message);
9182     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9183
9184     qstatus = GetQueueStatus(qs_all_input);
9185     ok(qstatus == MAKELONG(0, QS_KEY),
9186        "wrong qstatus %08x\n", qstatus);
9187
9188     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9189
9190     qstatus = GetQueueStatus(qs_all_input);
9191     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9192        "wrong qstatus %08x\n", qstatus);
9193
9194     trace("signalling to send message\n");
9195     SetEvent(info.hevent[EV_SENDMSG]);
9196     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9197
9198     qstatus = GetQueueStatus(qs_all_input);
9199     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9200        "wrong qstatus %08x\n", qstatus);
9201
9202     msg.message = 0;
9203     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9204     ok(!ret,
9205        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9206         msg.message);
9207     ok_sequence(WmUser, "WmUser", FALSE);
9208
9209     qstatus = GetQueueStatus(qs_all_input);
9210     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9211        "wrong qstatus %08x\n", qstatus);
9212
9213     msg.message = 0;
9214     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9215         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9216     else /* workaround for a missing QS_RAWINPUT support */
9217         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9218     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9219        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9220        ret, msg.message, msg.wParam);
9221     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9222
9223     qstatus = GetQueueStatus(qs_all_input);
9224     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9225        "wrong qstatus %08x\n", qstatus);
9226
9227     msg.message = 0;
9228     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9229         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9230     else /* workaround for a missing QS_RAWINPUT support */
9231         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9232     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9233        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9234        ret, msg.message, msg.wParam);
9235     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9236
9237     qstatus = GetQueueStatus(qs_all_input);
9238     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9239        "wrong qstatus %08x\n", qstatus);
9240
9241     msg.message = 0;
9242     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9243     ok(!ret,
9244        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9245         msg.message);
9246     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9247
9248     qstatus = GetQueueStatus(qs_all_input);
9249     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9250        "wrong qstatus %08x\n", qstatus);
9251
9252     msg.message = 0;
9253     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9254     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9255        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9256        ret, msg.message, msg.wParam);
9257     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9258
9259     qstatus = GetQueueStatus(qs_all_input);
9260     ok(qstatus == 0,
9261        "wrong qstatus %08x\n", qstatus);
9262
9263     msg.message = 0;
9264     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9265     ok(!ret,
9266        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9267         msg.message);
9268     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9269
9270     qstatus = GetQueueStatus(qs_all_input);
9271     ok(qstatus == 0,
9272        "wrong qstatus %08x\n", qstatus);
9273
9274     /* test whether presence of the quit flag in the queue affects
9275      * the queue state
9276      */
9277     PostQuitMessage(0x1234abcd);
9278
9279     qstatus = GetQueueStatus(qs_all_input);
9280     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9281        "wrong qstatus %08x\n", qstatus);
9282
9283     PostMessageA(info.hwnd, WM_USER, 0, 0);
9284
9285     qstatus = GetQueueStatus(qs_all_input);
9286     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9287        "wrong qstatus %08x\n", qstatus);
9288
9289     msg.message = 0;
9290     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9291     ok(ret && msg.message == WM_USER,
9292        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9293     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9294
9295     qstatus = GetQueueStatus(qs_all_input);
9296     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9297        "wrong qstatus %08x\n", qstatus);
9298
9299     msg.message = 0;
9300     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9301     ok(ret && msg.message == WM_QUIT,
9302        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9303     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9304     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9305     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9306
9307     qstatus = GetQueueStatus(qs_all_input);
9308 todo_wine {
9309     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9310        "wrong qstatus %08x\n", qstatus);
9311 }
9312
9313     msg.message = 0;
9314     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9315     ok(!ret,
9316        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9317         msg.message);
9318     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9319
9320     qstatus = GetQueueStatus(qs_all_input);
9321     ok(qstatus == 0,
9322        "wrong qstatus %08x\n", qstatus);
9323
9324     /* some GetMessage tests */
9325
9326     keybd_event('N', 0, 0, 0);
9327     qstatus = GetQueueStatus(qs_all_input);
9328     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9329
9330     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9331     qstatus = GetQueueStatus(qs_all_input);
9332     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9333
9334     if (qstatus)
9335     {
9336         ret = GetMessageA( &msg, 0, 0, 0 );
9337         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9338            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9339            ret, msg.message, msg.wParam);
9340         qstatus = GetQueueStatus(qs_all_input);
9341         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9342     }
9343
9344     if (qstatus)
9345     {
9346         ret = GetMessageA( &msg, 0, 0, 0 );
9347         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9348            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9349            ret, msg.message, msg.wParam);
9350         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9351         qstatus = GetQueueStatus(qs_all_input);
9352         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9353     }
9354
9355     keybd_event('N', 0, 0, 0);
9356     qstatus = GetQueueStatus(qs_all_input);
9357     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9358
9359     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9360     qstatus = GetQueueStatus(qs_all_input);
9361     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9362
9363     if (qstatus & (QS_KEY << 16))
9364     {
9365         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9366         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9367            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9368            ret, msg.message, msg.wParam);
9369         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9370         qstatus = GetQueueStatus(qs_all_input);
9371         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9372     }
9373
9374     if (qstatus)
9375     {
9376         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9377         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9378            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9379            ret, msg.message, msg.wParam);
9380         qstatus = GetQueueStatus(qs_all_input);
9381         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9382     }
9383
9384     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9385     qstatus = GetQueueStatus(qs_all_input);
9386     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9387
9388     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9389     qstatus = GetQueueStatus(qs_all_input);
9390     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9391
9392     trace("signalling to send message\n");
9393     SetEvent(info.hevent[EV_SENDMSG]);
9394     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9395     qstatus = GetQueueStatus(qs_all_input);
9396     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9397        "wrong qstatus %08x\n", qstatus);
9398
9399     if (qstatus & (QS_KEY << 16))
9400     {
9401         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9402         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9403            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9404            ret, msg.message, msg.wParam);
9405         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9406         qstatus = GetQueueStatus(qs_all_input);
9407         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9408     }
9409
9410     if (qstatus)
9411     {
9412         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9413         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9414            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9415            ret, msg.message, msg.wParam);
9416         qstatus = GetQueueStatus(qs_all_input);
9417         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9418     }
9419 done:
9420     trace("signalling to exit\n");
9421     SetEvent(info.hevent[EV_STOP]);
9422
9423     WaitForSingleObject(hthread, INFINITE);
9424
9425     CloseHandle(hthread);
9426     CloseHandle(info.hevent[0]);
9427     CloseHandle(info.hevent[1]);
9428     CloseHandle(info.hevent[2]);
9429
9430     DestroyWindow(info.hwnd);
9431 }
9432
9433 static void wait_move_event(HWND hwnd, int x, int y)
9434 {
9435     MSG msg;
9436     DWORD time;
9437     BOOL  ret;
9438     int go = 0;
9439
9440     time = GetTickCount();
9441     while (GetTickCount() - time < 200 && !go) {
9442         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9443         go  = ret && msg.pt.x > x && msg.pt.y > y;
9444         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9445     }
9446 }
9447
9448 #define STEP 5
9449 static void test_PeekMessage2(void)
9450 {
9451     HWND hwnd;
9452     BOOL ret;
9453     MSG msg;
9454     UINT message;
9455     DWORD time1, time2, time3;
9456     int x1, y1, x2, y2, x3, y3;
9457     POINT pos;
9458
9459     time1 = time2 = time3 = 0;
9460     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9461
9462     /* Initialise window and make sure it is ready for events */
9463     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9464                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9465     assert(hwnd);
9466     trace("Window for test_PeekMessage2 %p\n", hwnd);
9467     ShowWindow(hwnd, SW_SHOW);
9468     UpdateWindow(hwnd);
9469     SetFocus(hwnd);
9470     GetCursorPos(&pos);
9471     SetCursorPos(100, 100);
9472     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9473     flush_events();
9474
9475     /* Do initial mousemove, wait until we can see it
9476        and then do our test peek with PM_NOREMOVE. */
9477     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9478     wait_move_event(hwnd, 100-STEP, 100-STEP);
9479
9480     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9481     if (!ret)
9482     {
9483         skip( "queuing mouse events not supported\n" );
9484         goto done;
9485     }
9486     else
9487     {
9488         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9489         message = msg.message;
9490         time1 = msg.time;
9491         x1 = msg.pt.x;
9492         y1 = msg.pt.y;
9493         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9494     }
9495
9496     /* Allow time to advance a bit, and then simulate the user moving their
9497      * mouse around. After that we peek again with PM_NOREMOVE.
9498      * Although the previous mousemove message was never removed, the
9499      * mousemove we now peek should reflect the recent mouse movements
9500      * because the input queue will merge the move events. */
9501     Sleep(100);
9502     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9503     wait_move_event(hwnd, x1, y1);
9504
9505     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9506     ok(ret, "no message available\n");
9507     if (ret) {
9508         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9509         message = msg.message;
9510         time2 = msg.time;
9511         x2 = msg.pt.x;
9512         y2 = msg.pt.y;
9513         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9514         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9515         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9516     }
9517
9518     /* Have another go, to drive the point home */
9519     Sleep(100);
9520     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9521     wait_move_event(hwnd, x2, y2);
9522
9523     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9524     ok(ret, "no message available\n");
9525     if (ret) {
9526         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9527         message = msg.message;
9528         time3 = msg.time;
9529         x3 = msg.pt.x;
9530         y3 = msg.pt.y;
9531         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9532         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9533         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9534     }
9535
9536 done:
9537     DestroyWindow(hwnd);
9538     SetCursorPos(pos.x, pos.y);
9539     flush_events();
9540 }
9541
9542 static void test_quit_message(void)
9543 {
9544     MSG msg;
9545     BOOL ret;
9546
9547     /* test using PostQuitMessage */
9548     flush_events();
9549     PostQuitMessage(0xbeef);
9550
9551     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9552     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9553     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9554     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9555
9556     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9557     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9558
9559     ret = GetMessage(&msg, NULL, 0, 0);
9560     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9561     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9562
9563     /* note: WM_QUIT message received after WM_USER message */
9564     ret = GetMessage(&msg, NULL, 0, 0);
9565     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9566     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9567     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9568
9569     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9570     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9571
9572     /* now test with PostThreadMessage - different behaviour! */
9573     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9574
9575     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9576     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9577     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9578     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9579
9580     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9581     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9582
9583     /* note: we receive the WM_QUIT message first this time */
9584     ret = GetMessage(&msg, NULL, 0, 0);
9585     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9586     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9587     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9588
9589     ret = GetMessage(&msg, NULL, 0, 0);
9590     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9591     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9592 }
9593
9594 static const struct message WmMouseHoverSeq[] = {
9595     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9596     { WM_MOUSEACTIVATE, sent|optional },
9597     { WM_TIMER, sent|optional }, /* XP sends it */
9598     { WM_SYSTIMER, sent },
9599     { WM_MOUSEHOVER, sent|wparam, 0 },
9600     { 0 }
9601 };
9602
9603 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9604 {
9605     MSG msg;
9606     DWORD start_ticks, end_ticks;
9607
9608     start_ticks = GetTickCount();
9609     /* add some deviation (50%) to cover not expected delays */
9610     start_ticks += timeout / 2;
9611
9612     do
9613     {
9614         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9615         {
9616             /* Timer proc messages are not dispatched to the window proc,
9617              * and therefore not logged.
9618              */
9619             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9620             {
9621                 struct recvd_message s_msg;
9622
9623                 s_msg.hwnd = msg.hwnd;
9624                 s_msg.message = msg.message;
9625                 s_msg.flags = sent|wparam|lparam;
9626                 s_msg.wParam = msg.wParam;
9627                 s_msg.lParam = msg.lParam;
9628                 s_msg.descr = "msg_loop";
9629                 add_message(&s_msg);
9630             }
9631             DispatchMessage(&msg);
9632         }
9633
9634         end_ticks = GetTickCount();
9635
9636         /* inject WM_MOUSEMOVE to see how it changes tracking */
9637         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9638         {
9639             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9640             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9641
9642             inject_mouse_move = FALSE;
9643         }
9644     } while (start_ticks + timeout >= end_ticks);
9645 }
9646
9647 static void test_TrackMouseEvent(void)
9648 {
9649     TRACKMOUSEEVENT tme;
9650     BOOL ret;
9651     HWND hwnd, hchild;
9652     RECT rc_parent, rc_child;
9653     UINT default_hover_time, hover_width = 0, hover_height = 0;
9654
9655 #define track_hover(track_hwnd, track_hover_time) \
9656     tme.cbSize = sizeof(tme); \
9657     tme.dwFlags = TME_HOVER; \
9658     tme.hwndTrack = track_hwnd; \
9659     tme.dwHoverTime = track_hover_time; \
9660     SetLastError(0xdeadbeef); \
9661     ret = pTrackMouseEvent(&tme); \
9662     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9663
9664 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9665     tme.cbSize = sizeof(tme); \
9666     tme.dwFlags = TME_QUERY; \
9667     tme.hwndTrack = (HWND)0xdeadbeef; \
9668     tme.dwHoverTime = 0xdeadbeef; \
9669     SetLastError(0xdeadbeef); \
9670     ret = pTrackMouseEvent(&tme); \
9671     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9672     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9673     ok(tme.dwFlags == (expected_track_flags), \
9674        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9675     ok(tme.hwndTrack == (expected_track_hwnd), \
9676        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9677     ok(tme.dwHoverTime == (expected_hover_time), \
9678        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9679
9680 #define track_hover_cancel(track_hwnd) \
9681     tme.cbSize = sizeof(tme); \
9682     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9683     tme.hwndTrack = track_hwnd; \
9684     tme.dwHoverTime = 0xdeadbeef; \
9685     SetLastError(0xdeadbeef); \
9686     ret = pTrackMouseEvent(&tme); \
9687     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9688
9689     default_hover_time = 0xdeadbeef;
9690     SetLastError(0xdeadbeef);
9691     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9692     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9693        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9694     if (!ret) default_hover_time = 400;
9695     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9696
9697     SetLastError(0xdeadbeef);
9698     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9699     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9700        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9701     if (!ret) hover_width = 4;
9702     SetLastError(0xdeadbeef);
9703     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9704     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9705        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9706     if (!ret) hover_height = 4;
9707     trace("hover rect is %u x %d\n", hover_width, hover_height);
9708
9709     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9710                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9711                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9712                           NULL, NULL, 0);
9713     assert(hwnd);
9714
9715     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9716                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9717                           50, 50, 200, 200, hwnd,
9718                           NULL, NULL, 0);
9719     assert(hchild);
9720
9721     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9722     flush_events();
9723     flush_sequence();
9724
9725     tme.cbSize = 0;
9726     tme.dwFlags = TME_QUERY;
9727     tme.hwndTrack = (HWND)0xdeadbeef;
9728     tme.dwHoverTime = 0xdeadbeef;
9729     SetLastError(0xdeadbeef);
9730     ret = pTrackMouseEvent(&tme);
9731     ok(!ret, "TrackMouseEvent should fail\n");
9732     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9733        "not expected error %u\n", GetLastError());
9734
9735     tme.cbSize = sizeof(tme);
9736     tme.dwFlags = TME_HOVER;
9737     tme.hwndTrack = (HWND)0xdeadbeef;
9738     tme.dwHoverTime = 0xdeadbeef;
9739     SetLastError(0xdeadbeef);
9740     ret = pTrackMouseEvent(&tme);
9741     ok(!ret, "TrackMouseEvent should fail\n");
9742     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9743        "not expected error %u\n", GetLastError());
9744
9745     tme.cbSize = sizeof(tme);
9746     tme.dwFlags = TME_HOVER | TME_CANCEL;
9747     tme.hwndTrack = (HWND)0xdeadbeef;
9748     tme.dwHoverTime = 0xdeadbeef;
9749     SetLastError(0xdeadbeef);
9750     ret = pTrackMouseEvent(&tme);
9751     ok(!ret, "TrackMouseEvent should fail\n");
9752     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9753        "not expected error %u\n", GetLastError());
9754
9755     GetWindowRect(hwnd, &rc_parent);
9756     GetWindowRect(hchild, &rc_child);
9757     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9758
9759     /* Process messages so that the system updates its internal current
9760      * window and hittest, otherwise TrackMouseEvent calls don't have any
9761      * effect.
9762      */
9763     flush_events();
9764     flush_sequence();
9765
9766     track_query(0, NULL, 0);
9767     track_hover(hchild, 0);
9768     track_query(0, NULL, 0);
9769
9770     flush_events();
9771     flush_sequence();
9772
9773     track_hover(hwnd, 0);
9774     tme.cbSize = sizeof(tme);
9775     tme.dwFlags = TME_QUERY;
9776     tme.hwndTrack = (HWND)0xdeadbeef;
9777     tme.dwHoverTime = 0xdeadbeef;
9778     SetLastError(0xdeadbeef);
9779     ret = pTrackMouseEvent(&tme);
9780     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9781     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9782     if (!tme.dwFlags)
9783     {
9784         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9785         DestroyWindow( hwnd );
9786         return;
9787     }
9788     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9789     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9790     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9791        tme.dwHoverTime, default_hover_time);
9792
9793     pump_msg_loop_timeout(default_hover_time, FALSE);
9794     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9795
9796     track_query(0, NULL, 0);
9797
9798     track_hover(hwnd, HOVER_DEFAULT);
9799     track_query(TME_HOVER, hwnd, default_hover_time);
9800
9801     Sleep(default_hover_time / 2);
9802     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9803     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9804
9805     track_query(TME_HOVER, hwnd, default_hover_time);
9806
9807     pump_msg_loop_timeout(default_hover_time, FALSE);
9808     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9809
9810     track_query(0, NULL, 0);
9811
9812     track_hover(hwnd, HOVER_DEFAULT);
9813     track_query(TME_HOVER, hwnd, default_hover_time);
9814
9815     pump_msg_loop_timeout(default_hover_time, TRUE);
9816     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9817
9818     track_query(0, NULL, 0);
9819
9820     track_hover(hwnd, HOVER_DEFAULT);
9821     track_query(TME_HOVER, hwnd, default_hover_time);
9822     track_hover_cancel(hwnd);
9823
9824     DestroyWindow(hwnd);
9825
9826 #undef track_hover
9827 #undef track_query
9828 #undef track_hover_cancel
9829 }
9830
9831
9832 static const struct message WmSetWindowRgn[] = {
9833     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9834     { WM_NCCALCSIZE, sent|wparam, 1 },
9835     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9836     { WM_GETTEXT, sent|defwinproc|optional },
9837     { WM_ERASEBKGND, sent|optional },
9838     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9839     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9840     { 0 }
9841 };
9842
9843 static const struct message WmSetWindowRgn_no_redraw[] = {
9844     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9845     { WM_NCCALCSIZE, sent|wparam, 1 },
9846     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9847     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9848     { 0 }
9849 };
9850
9851 static const struct message WmSetWindowRgn_clear[] = {
9852     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9853     { WM_NCCALCSIZE, sent|wparam, 1 },
9854     { WM_NCPAINT, sent|optional },
9855     { WM_GETTEXT, sent|defwinproc|optional },
9856     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9858     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9859     { WM_NCPAINT, sent|optional },
9860     { WM_GETTEXT, sent|defwinproc|optional },
9861     { WM_ERASEBKGND, sent|optional },
9862     { WM_WINDOWPOSCHANGING, sent|optional },
9863     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9864     { WM_NCPAINT, sent|optional },
9865     { WM_GETTEXT, sent|defwinproc|optional },
9866     { WM_ERASEBKGND, sent|optional },
9867     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9868     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9869     { WM_NCPAINT, sent|optional },
9870     { WM_GETTEXT, sent|defwinproc|optional },
9871     { WM_ERASEBKGND, sent|optional },
9872     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9874     { 0 }
9875 };
9876
9877 static void test_SetWindowRgn(void)
9878 {
9879     HRGN hrgn;
9880     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9881                                 100, 100, 200, 200, 0, 0, 0, NULL);
9882     ok( hwnd != 0, "Failed to create overlapped window\n" );
9883
9884     ShowWindow( hwnd, SW_SHOW );
9885     UpdateWindow( hwnd );
9886     flush_events();
9887     flush_sequence();
9888
9889     trace("testing SetWindowRgn\n");
9890     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9891     SetWindowRgn( hwnd, hrgn, TRUE );
9892     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9893
9894     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9895     SetWindowRgn( hwnd, hrgn, FALSE );
9896     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9897
9898     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9899     SetWindowRgn( hwnd, hrgn, TRUE );
9900     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9901
9902     SetWindowRgn( hwnd, 0, TRUE );
9903     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9904
9905     DestroyWindow( hwnd );
9906 }
9907
9908 /*************************** ShowWindow() test ******************************/
9909 static const struct message WmShowNormal[] = {
9910     { WM_SHOWWINDOW, sent|wparam, 1 },
9911     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9912     { HCBT_ACTIVATE, hook },
9913     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9914     { HCBT_SETFOCUS, hook },
9915     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9916     { 0 }
9917 };
9918 static const struct message WmShow[] = {
9919     { WM_SHOWWINDOW, sent|wparam, 1 },
9920     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9921     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9922     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9923     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9924     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9925     { 0 }
9926 };
9927 static const struct message WmShowNoActivate_1[] = {
9928     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9930     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9931     { WM_MOVE, sent|defwinproc|optional },
9932     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9933     { 0 }
9934 };
9935 static const struct message WmShowNoActivate_2[] = {
9936     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9937     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9938     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9939     { WM_MOVE, sent|defwinproc },
9940     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9941     { HCBT_SETFOCUS, hook|optional },
9942     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9943     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9944     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9945     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9946     { 0 }
9947 };
9948 static const struct message WmShowNA_1[] = {
9949     { WM_SHOWWINDOW, sent|wparam, 1 },
9950     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9951     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9952     { 0 }
9953 };
9954 static const struct message WmShowNA_2[] = {
9955     { WM_SHOWWINDOW, sent|wparam, 1 },
9956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9957     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9958     { 0 }
9959 };
9960 static const struct message WmRestore_1[] = {
9961     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9962     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9963     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9964     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9965     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9966     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9967     { WM_MOVE, sent|defwinproc },
9968     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9969     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9970     { 0 }
9971 };
9972 static const struct message WmRestore_2[] = {
9973     { WM_SHOWWINDOW, sent|wparam, 1 },
9974     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9975     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9976     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9977     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9978     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9979     { 0 }
9980 };
9981 static const struct message WmRestore_3[] = {
9982     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9983     { WM_GETMINMAXINFO, sent },
9984     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9985     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9986     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9987     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9988     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9989     { WM_MOVE, sent|defwinproc },
9990     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9991     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9992     { 0 }
9993 };
9994 static const struct message WmRestore_4[] = {
9995     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
9996     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9997     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9998     { WM_MOVE, sent|defwinproc|optional },
9999     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10000     { 0 }
10001 };
10002 static const struct message WmRestore_5[] = {
10003     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10004     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10005     { HCBT_ACTIVATE, hook|optional },
10006     { HCBT_SETFOCUS, hook|optional },
10007     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10008     { WM_MOVE, sent|defwinproc|optional },
10009     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10010     { 0 }
10011 };
10012 static const struct message WmHide_1[] = {
10013     { WM_SHOWWINDOW, sent|wparam, 0 },
10014     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10015     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10016     { HCBT_ACTIVATE, hook|optional },
10017     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10018     { 0 }
10019 };
10020 static const struct message WmHide_2[] = {
10021     { WM_SHOWWINDOW, sent|wparam, 0 },
10022     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10023     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10024     { HCBT_ACTIVATE, hook|optional },
10025     { 0 }
10026 };
10027 static const struct message WmHide_3[] = {
10028     { WM_SHOWWINDOW, sent|wparam, 0 },
10029     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10030     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10031     { HCBT_SETFOCUS, hook|optional },
10032     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10033     { 0 }
10034 };
10035 static const struct message WmShowMinimized_1[] = {
10036     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10037     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10038     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10039     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10040     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10041     { WM_MOVE, sent|defwinproc },
10042     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10043     { 0 }
10044 };
10045 static const struct message WmMinimize_1[] = {
10046     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10047     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10048     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10049     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10050     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10051     { WM_MOVE, sent|defwinproc },
10052     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10053     { 0 }
10054 };
10055 static const struct message WmMinimize_2[] = {
10056     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10057     { HCBT_SETFOCUS, hook|optional },
10058     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10059     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10060     { WM_MOVE, sent|defwinproc },
10061     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10062     { 0 }
10063 };
10064 static const struct message WmMinimize_3[] = {
10065     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10066     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10067     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10068     { WM_MOVE, sent|defwinproc },
10069     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10070     { 0 }
10071 };
10072 static const struct message WmShowMinNoActivate[] = {
10073     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10074     { WM_WINDOWPOSCHANGING, sent },
10075     { WM_WINDOWPOSCHANGED, sent },
10076     { WM_MOVE, sent|defwinproc|optional },
10077     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MINIMIZED },
10078     { 0 }
10079 };
10080 static const struct message WmMinMax_1[] = {
10081     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10082     { 0 }
10083 };
10084 static const struct message WmMinMax_2[] = {
10085     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10086     { WM_GETMINMAXINFO, sent|optional },
10087     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10088     { HCBT_ACTIVATE, hook|optional },
10089     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10090     { HCBT_SETFOCUS, hook|optional },
10091     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10092     { WM_MOVE, sent|defwinproc|optional },
10093     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10094     { HCBT_SETFOCUS, hook|optional },
10095     { 0 }
10096 };
10097 static const struct message WmMinMax_3[] = {
10098     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10099     { HCBT_SETFOCUS, hook|optional },
10100     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10101     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10102     { WM_MOVE, sent|defwinproc|optional },
10103     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MINIMIZED },
10104     { 0 }
10105 };
10106 static const struct message WmMinMax_4[] = {
10107     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10108     { 0 }
10109 };
10110 static const struct message WmShowMaximized_1[] = {
10111     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10112     { WM_GETMINMAXINFO, sent },
10113     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10114     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10115     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10116     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10117     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10118     { WM_MOVE, sent|defwinproc },
10119     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10120     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10121     { 0 }
10122 };
10123 static const struct message WmShowMaximized_2[] = {
10124     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10125     { WM_GETMINMAXINFO, sent },
10126     { WM_WINDOWPOSCHANGING, sent|optional },
10127     { HCBT_ACTIVATE, hook|optional },
10128     { WM_WINDOWPOSCHANGED, sent|optional },
10129     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10130     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10131     { WM_WINDOWPOSCHANGING, sent|optional },
10132     { HCBT_SETFOCUS, hook|optional },
10133     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10134     { WM_MOVE, sent|defwinproc },
10135     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10136     { HCBT_SETFOCUS, hook|optional },
10137     { 0 }
10138 };
10139 static const struct message WmShowMaximized_3[] = {
10140     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10141     { WM_GETMINMAXINFO, sent },
10142     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10143     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10144     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10145     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10146     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10147     { WM_MOVE, sent|defwinproc|optional },
10148     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10149     { 0 }
10150 };
10151
10152 static void test_ShowWindow(void)
10153 {
10154     /* ShowWindow commands in random order */
10155     static const struct
10156     {
10157         INT cmd; /* ShowWindow command */
10158         LPARAM ret; /* ShowWindow return value */
10159         DWORD style; /* window style after the command */
10160         const struct message *msg; /* message sequence the command produces */
10161         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10162     } sw[] =
10163     {
10164 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10165 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10166 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10167 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10168 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10169 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10170 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10171 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10172 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10173 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10174 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10175 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10176 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10177 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10178 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10179 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10180 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10181 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10182 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10183 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10184 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10185 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10186 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10187 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10188 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10189 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10190 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10191 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10192 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10193 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10194 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10195 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10196 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10197 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10198 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10199 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10200 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10201 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10202 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10203 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10204 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10205 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10206 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10207 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10208 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10209 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10210 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10211 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10212 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10213 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10214 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10215 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10216 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10217 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10218 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10219 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10220 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10221     };
10222     HWND hwnd;
10223     DWORD style;
10224     LPARAM ret;
10225     INT i;
10226
10227 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10228     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10229                           120, 120, 90, 90,
10230                           0, 0, 0, NULL);
10231     assert(hwnd);
10232
10233     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10234     ok(style == 0, "expected style 0, got %08x\n", style);
10235
10236     flush_events();
10237     flush_sequence();
10238
10239     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10240     {
10241         static const char * const sw_cmd_name[13] =
10242         {
10243             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10244             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10245             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10246             "SW_NORMALNA" /* 0xCC */
10247         };
10248         char comment[64];
10249         INT idx; /* index into the above array of names */
10250
10251         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10252
10253         style = GetWindowLong(hwnd, GWL_STYLE);
10254         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10255         ret = ShowWindow(hwnd, sw[i].cmd);
10256         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10257         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10258         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10259
10260         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10261         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10262
10263         flush_events();
10264         flush_sequence();
10265     }
10266
10267     DestroyWindow(hwnd);
10268 }
10269
10270 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10271 {
10272     struct recvd_message msg;
10273
10274     switch (message)
10275     {
10276     case WM_GETICON:
10277     case WM_GETOBJECT:
10278         return 0;  /* ignore them */
10279     }
10280
10281     msg.hwnd = hwnd;
10282     msg.message = message;
10283     msg.flags = sent|wparam|lparam;
10284     msg.wParam = wParam;
10285     msg.lParam = lParam;
10286     msg.descr = "dialog";
10287     add_message(&msg);
10288
10289     /* calling DefDlgProc leads to a recursion under XP */
10290
10291     switch (message)
10292     {
10293     case WM_INITDIALOG:
10294     case WM_GETDLGCODE:
10295         return 0;
10296     }
10297     return 1;
10298 }
10299
10300 static const struct message WmDefDlgSetFocus_1[] = {
10301     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10302     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10303     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10304     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10305     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10306     { HCBT_SETFOCUS, hook },
10307     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10308     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10309     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10310     { WM_SETFOCUS, sent|wparam, 0 },
10311     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10312     { WM_CTLCOLOREDIT, sent },
10313     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10314     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10315     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10316     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10317     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10318     { 0 }
10319 };
10320 static const struct message WmDefDlgSetFocus_2[] = {
10321     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10322     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10323     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10324     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10325     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10326     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10327     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10328     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10329     { 0 }
10330 };
10331 /* Creation of a dialog */
10332 static const struct message WmCreateDialogParamSeq_1[] = {
10333     { HCBT_CREATEWND, hook },
10334     { WM_NCCREATE, sent },
10335     { WM_NCCALCSIZE, sent|wparam, 0 },
10336     { WM_CREATE, sent },
10337     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10338     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10339     { WM_MOVE, sent },
10340     { WM_SETFONT, sent },
10341     { WM_INITDIALOG, sent },
10342     { WM_CHANGEUISTATE, sent|optional },
10343     { 0 }
10344 };
10345 /* Creation of a dialog */
10346 static const struct message WmCreateDialogParamSeq_2[] = {
10347     { HCBT_CREATEWND, hook },
10348     { WM_NCCREATE, sent },
10349     { WM_NCCALCSIZE, sent|wparam, 0 },
10350     { WM_CREATE, sent },
10351     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10352     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10353     { WM_MOVE, sent },
10354     { WM_CHANGEUISTATE, sent|optional },
10355     { 0 }
10356 };
10357
10358 static void test_dialog_messages(void)
10359 {
10360     WNDCLASS cls;
10361     HWND hdlg, hedit1, hedit2, hfocus;
10362     LRESULT ret;
10363
10364 #define set_selection(hctl, start, end) \
10365     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10366     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10367
10368 #define check_selection(hctl, start, end) \
10369     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10370     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10371
10372     subclass_edit();
10373
10374     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10375                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10376                           0, 0, 100, 100, 0, 0, 0, NULL);
10377     ok(hdlg != 0, "Failed to create custom dialog window\n");
10378
10379     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10380                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10381                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10382     ok(hedit1 != 0, "Failed to create edit control\n");
10383     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10384                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10385                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10386     ok(hedit2 != 0, "Failed to create edit control\n");
10387
10388     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10389     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10390
10391     hfocus = GetFocus();
10392     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10393
10394     SetFocus(hedit2);
10395     hfocus = GetFocus();
10396     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10397
10398     check_selection(hedit1, 0, 0);
10399     check_selection(hedit2, 0, 0);
10400
10401     set_selection(hedit2, 0, -1);
10402     check_selection(hedit2, 0, 3);
10403
10404     SetFocus(0);
10405     hfocus = GetFocus();
10406     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10407
10408     flush_sequence();
10409     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10410     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10411     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10412
10413     hfocus = GetFocus();
10414     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10415
10416     check_selection(hedit1, 0, 5);
10417     check_selection(hedit2, 0, 3);
10418
10419     flush_sequence();
10420     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10421     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10422     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10423
10424     hfocus = GetFocus();
10425     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10426
10427     check_selection(hedit1, 0, 5);
10428     check_selection(hedit2, 0, 3);
10429
10430     EndDialog(hdlg, 0);
10431     DestroyWindow(hedit1);
10432     DestroyWindow(hedit2);
10433     DestroyWindow(hdlg);
10434     flush_sequence();
10435
10436 #undef set_selection
10437 #undef check_selection
10438
10439     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10440     cls.lpszClassName = "MyDialogClass";
10441     cls.hInstance = GetModuleHandle(0);
10442     /* need a cast since a dlgproc is used as a wndproc */
10443     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10444     if (!RegisterClass(&cls)) assert(0);
10445
10446     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10447     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10448     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10449     EndDialog(hdlg, 0);
10450     DestroyWindow(hdlg);
10451     flush_sequence();
10452
10453     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10454     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10455     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10456     EndDialog(hdlg, 0);
10457     DestroyWindow(hdlg);
10458     flush_sequence();
10459
10460     UnregisterClass(cls.lpszClassName, cls.hInstance);
10461 }
10462
10463 static void test_nullCallback(void)
10464 {
10465     HWND hwnd;
10466
10467     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10468                            100, 100, 200, 200, 0, 0, 0, NULL);
10469     ok (hwnd != 0, "Failed to create overlapped window\n");
10470
10471     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10472     flush_events();
10473     DestroyWindow(hwnd);
10474 }
10475
10476 /* SetActiveWindow( 0 ) hwnd visible */
10477 static const struct message SetActiveWindowSeq0[] =
10478 {
10479     { HCBT_ACTIVATE, hook|optional },
10480     { WM_NCACTIVATE, sent|wparam, 0 },
10481     { WM_GETTEXT, sent|defwinproc|optional },
10482     { WM_ACTIVATE, sent|wparam, 0 },
10483     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10484     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10485     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10486     { WM_KILLFOCUS, sent|optional },
10487     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10488     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10489     { WM_NCACTIVATE, sent|wparam|optional, 1 },
10490     { WM_GETTEXT, sent|defwinproc|optional },
10491     { WM_ACTIVATE, sent|wparam|optional, 1 },
10492     { HCBT_SETFOCUS, hook|optional },
10493     { WM_KILLFOCUS, sent|defwinproc|optional },
10494     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10495     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10496     { WM_IME_SETCONTEXT, sent|optional },
10497     { WM_IME_SETCONTEXT, sent|optional },
10498     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10499     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10500     { WM_SETFOCUS, sent|defwinproc|optional },
10501     { WM_GETTEXT, sent|optional },
10502     { 0 }
10503 };
10504 /* SetActiveWindow( hwnd ) hwnd visible */
10505 static const struct message SetActiveWindowSeq1[] =
10506 {
10507     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10508     { 0 }
10509 };
10510 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10511 static const struct message SetActiveWindowSeq2[] =
10512 {
10513     { HCBT_ACTIVATE, hook },
10514     { WM_NCACTIVATE, sent|wparam, 0 },
10515     { WM_GETTEXT, sent|defwinproc|optional },
10516     { WM_ACTIVATE, sent|wparam, 0 },
10517     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10518     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10519     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10520     { WM_NCPAINT, sent|optional },
10521     { WM_GETTEXT, sent|defwinproc|optional },
10522     { WM_ERASEBKGND, sent|optional },
10523     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10524     { WM_NCACTIVATE, sent|wparam, 1 },
10525     { WM_GETTEXT, sent|defwinproc|optional },
10526     { WM_ACTIVATE, sent|wparam, 1 },
10527     { HCBT_SETFOCUS, hook },
10528     { WM_KILLFOCUS, sent|defwinproc },
10529     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10530     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10531     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10532     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10533     { WM_SETFOCUS, sent|defwinproc },
10534     { WM_GETTEXT, sent|optional },
10535     { 0 }
10536 };
10537
10538 /* SetActiveWindow( hwnd ) hwnd not visible */
10539 static const struct message SetActiveWindowSeq3[] =
10540 {
10541     { HCBT_ACTIVATE, hook },
10542     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10543     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10544     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10545     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10546     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10547     { WM_ACTIVATEAPP, sent|wparam, 1 },
10548     { WM_ACTIVATEAPP, sent|wparam, 1 },
10549     { WM_NCACTIVATE, sent|wparam, 1 },
10550     { WM_ACTIVATE, sent|wparam, 1 },
10551     { HCBT_SETFOCUS, hook },
10552     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10553     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10554     { WM_SETFOCUS, sent|defwinproc },
10555     { 0 }
10556 };
10557 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10558 static const struct message SetActiveWindowSeq4[] =
10559 {
10560     { HCBT_ACTIVATE, hook },
10561     { WM_NCACTIVATE, sent|wparam, 0 },
10562     { WM_GETTEXT, sent|defwinproc|optional },
10563     { WM_ACTIVATE, sent|wparam, 0 },
10564     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10565     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10566     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10567     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10568     { WM_NCACTIVATE, sent|wparam, 1 },
10569     { WM_GETTEXT, sent|defwinproc|optional },
10570     { WM_ACTIVATE, sent|wparam, 1 },
10571     { HCBT_SETFOCUS, hook },
10572     { WM_KILLFOCUS, sent|defwinproc },
10573     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10574     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10575     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10576     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10577     { WM_SETFOCUS, sent|defwinproc },
10578     { 0 }
10579 };
10580
10581
10582 static void test_SetActiveWindow(void)
10583 {
10584     HWND hwnd, popup, ret;
10585
10586     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10587                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10588                            100, 100, 200, 200, 0, 0, 0, NULL);
10589
10590     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10591                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10592                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10593
10594     ok(hwnd != 0, "Failed to create overlapped window\n");
10595     ok(popup != 0, "Failed to create popup window\n");
10596     SetForegroundWindow( popup );
10597     flush_sequence();
10598
10599     trace("SetActiveWindow(0)\n");
10600     ret = SetActiveWindow(0);
10601     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10602     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10603     flush_sequence();
10604
10605     trace("SetActiveWindow(hwnd), hwnd visible\n");
10606     ret = SetActiveWindow(hwnd);
10607     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10608     flush_sequence();
10609
10610     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10611     ret = SetActiveWindow(popup);
10612     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10613     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10614     flush_sequence();
10615
10616     ShowWindow(hwnd, SW_HIDE);
10617     ShowWindow(popup, SW_HIDE);
10618     flush_sequence();
10619
10620     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10621     ret = SetActiveWindow(hwnd);
10622     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10623     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10624     flush_sequence();
10625
10626     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10627     ret = SetActiveWindow(popup);
10628     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10629     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10630     flush_sequence();
10631
10632     trace("done\n");
10633
10634     DestroyWindow(hwnd);
10635 }
10636
10637 static const struct message SetForegroundWindowSeq[] =
10638 {
10639     { WM_NCACTIVATE, sent|wparam, 0 },
10640     { WM_GETTEXT, sent|defwinproc|optional },
10641     { WM_ACTIVATE, sent|wparam, 0 },
10642     { WM_ACTIVATEAPP, sent|wparam, 0 },
10643     { WM_KILLFOCUS, sent },
10644     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10645     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10646     { 0 }
10647 };
10648
10649 static void test_SetForegroundWindow(void)
10650 {
10651     HWND hwnd;
10652
10653     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10654                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10655                            100, 100, 200, 200, 0, 0, 0, NULL);
10656     ok (hwnd != 0, "Failed to create overlapped window\n");
10657     SetForegroundWindow( hwnd );
10658     flush_sequence();
10659
10660     trace("SetForegroundWindow( 0 )\n");
10661     SetForegroundWindow( 0 );
10662     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10663     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10664     SetForegroundWindow( GetDesktopWindow() );
10665     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10666                                         "foreground top level window", FALSE);
10667     trace("done\n");
10668
10669     DestroyWindow(hwnd);
10670 }
10671
10672 static void test_dbcs_wm_char(void)
10673 {
10674     BYTE dbch[2];
10675     WCHAR wch, bad_wch;
10676     HWND hwnd, hwnd2;
10677     MSG msg;
10678     DWORD time;
10679     POINT pt;
10680     DWORD_PTR res;
10681     CPINFOEXA cpinfo;
10682     UINT i, j, k;
10683     struct message wmCharSeq[2];
10684
10685     if (!pGetCPInfoExA)
10686     {
10687         win_skip("GetCPInfoExA is not available\n");
10688         return;
10689     }
10690
10691     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10692     if (cpinfo.MaxCharSize != 2)
10693     {
10694         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10695         return;
10696     }
10697
10698     dbch[0] = dbch[1] = 0;
10699     wch = 0;
10700     bad_wch = cpinfo.UnicodeDefaultChar;
10701     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10702         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10703             for (k = 128; k <= 255; k++)
10704             {
10705                 char str[2];
10706                 WCHAR wstr[2];
10707                 str[0] = j;
10708                 str[1] = k;
10709                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10710                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10711                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10712                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10713                 {
10714                     dbch[0] = j;
10715                     dbch[1] = k;
10716                     wch = wstr[0];
10717                     break;
10718                 }
10719             }
10720
10721     if (!wch)
10722     {
10723         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10724         return;
10725     }
10726     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10727            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10728
10729     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10730                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10731     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10732                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10733     ok (hwnd != 0, "Failed to create overlapped window\n");
10734     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10735     flush_sequence();
10736
10737     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10738     wmCharSeq[0].message = WM_CHAR;
10739     wmCharSeq[0].flags = sent|wparam;
10740     wmCharSeq[0].wParam = wch;
10741
10742     /* posted message */
10743     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10744     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10745     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10746     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10747     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10748     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10749     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10750
10751     /* posted thread message */
10752     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10753     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10754     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10755     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10756     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10757     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10758     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10759
10760     /* sent message */
10761     flush_sequence();
10762     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10763     ok_sequence( WmEmptySeq, "no messages", FALSE );
10764     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10765     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10766     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10767
10768     /* sent message with timeout */
10769     flush_sequence();
10770     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10771     ok_sequence( WmEmptySeq, "no messages", FALSE );
10772     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10773     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10774     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10775
10776     /* sent message with timeout and callback */
10777     flush_sequence();
10778     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10779     ok_sequence( WmEmptySeq, "no messages", FALSE );
10780     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10781     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10782     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10783
10784     /* sent message with callback */
10785     flush_sequence();
10786     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10787     ok_sequence( WmEmptySeq, "no messages", FALSE );
10788     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10789     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10790     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10791
10792     /* direct window proc call */
10793     flush_sequence();
10794     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10795     ok_sequence( WmEmptySeq, "no messages", FALSE );
10796     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10797     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10798
10799     /* dispatch message */
10800     msg.hwnd = hwnd;
10801     msg.message = WM_CHAR;
10802     msg.wParam = dbch[0];
10803     msg.lParam = 0;
10804     DispatchMessageA( &msg );
10805     ok_sequence( WmEmptySeq, "no messages", FALSE );
10806     msg.wParam = dbch[1];
10807     DispatchMessageA( &msg );
10808     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10809
10810     /* window handle is irrelevant */
10811     flush_sequence();
10812     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10813     ok_sequence( WmEmptySeq, "no messages", FALSE );
10814     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10815     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10816     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10817
10818     /* interleaved post and send */
10819     flush_sequence();
10820     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10821     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10822     ok_sequence( WmEmptySeq, "no messages", FALSE );
10823     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10824     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10825     ok_sequence( WmEmptySeq, "no messages", FALSE );
10826     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10827     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10828     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10829     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10830     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10831     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10832     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10833
10834     /* interleaved sent message and winproc */
10835     flush_sequence();
10836     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10837     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10838     ok_sequence( WmEmptySeq, "no messages", FALSE );
10839     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10840     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10841     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10842     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10843
10844     /* interleaved winproc and dispatch */
10845     msg.hwnd = hwnd;
10846     msg.message = WM_CHAR;
10847     msg.wParam = dbch[0];
10848     msg.lParam = 0;
10849     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10850     DispatchMessageA( &msg );
10851     ok_sequence( WmEmptySeq, "no messages", FALSE );
10852     msg.wParam = dbch[1];
10853     DispatchMessageA( &msg );
10854     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10855     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10856     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10857
10858     /* interleaved sends */
10859     flush_sequence();
10860     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10861     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10862     ok_sequence( WmEmptySeq, "no messages", FALSE );
10863     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10864     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10865     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10866     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10867
10868     /* dbcs WM_CHAR */
10869     flush_sequence();
10870     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10871     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10872     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10873
10874     /* other char messages are not magic */
10875     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10876     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10877     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10878     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10879     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10880     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10881     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10882     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10883     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10884     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10885
10886     /* test retrieving messages */
10887
10888     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10889     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10890     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10891     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10892     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10893     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10894     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10895     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10896     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10897     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10898
10899     /* message filters */
10900     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10901     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10902     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10903     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10904     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10905     /* message id is filtered, hwnd is not */
10906     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10907     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10908     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10909     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10910     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10911     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10912
10913     /* mixing GetMessage and PostMessage */
10914     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10915     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10916     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10917     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10918     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10919     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10920     time = msg.time;
10921     pt = msg.pt;
10922     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10923     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10924     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10925     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10926     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10927     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10928     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10929     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 );
10930     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10931
10932     /* without PM_REMOVE */
10933     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10934     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10935     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10936     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10937     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10938     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10939     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10940     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10941     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10942     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10943     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10944     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10945     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10946     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10947     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10948     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10949     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10950     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10951
10952     DestroyWindow(hwnd);
10953 }
10954
10955 #define ID_LISTBOX 0x000f
10956
10957 static const struct message wm_lb_setcursel_0[] =
10958 {
10959     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10960     { WM_CTLCOLORLISTBOX, sent|parent },
10961     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10962     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10963     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10964     { 0 }
10965 };
10966 static const struct message wm_lb_setcursel_1[] =
10967 {
10968     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10969     { WM_CTLCOLORLISTBOX, sent|parent },
10970     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10971     { WM_CTLCOLORLISTBOX, sent|parent },
10972     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10973     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10974     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10975     { 0 }
10976 };
10977 static const struct message wm_lb_setcursel_2[] =
10978 {
10979     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10980     { WM_CTLCOLORLISTBOX, sent|parent },
10981     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10982     { WM_CTLCOLORLISTBOX, sent|parent },
10983     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10984     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10985     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10986     { 0 }
10987 };
10988 static const struct message wm_lb_click_0[] =
10989 {
10990     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10991     { HCBT_SETFOCUS, hook },
10992     { WM_KILLFOCUS, sent|parent },
10993     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10994     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10995     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10996     { WM_SETFOCUS, sent|defwinproc },
10997
10998     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10999     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11000     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11001     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11002     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11003
11004     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11005     { WM_CTLCOLORLISTBOX, sent|parent },
11006     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11007     { WM_CTLCOLORLISTBOX, sent|parent },
11008     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11009     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11010
11011     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11012     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11013
11014     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11015     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11016     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11017     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11018     { 0 }
11019 };
11020
11021 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11022
11023 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11024
11025 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11026 {
11027     static long defwndproc_counter = 0;
11028     LRESULT ret;
11029     struct recvd_message msg;
11030
11031     /* do not log painting messages */
11032     if (message != WM_PAINT &&
11033         message != WM_NCPAINT &&
11034         message != WM_SYNCPAINT &&
11035         message != WM_ERASEBKGND &&
11036         message != WM_NCHITTEST &&
11037         message != WM_GETTEXT &&
11038         message != WM_GETOBJECT &&
11039         message != WM_GETICON &&
11040         message != WM_DEVICECHANGE)
11041     {
11042         msg.hwnd = hwnd;
11043         msg.message = message;
11044         msg.flags = sent|wparam|lparam;
11045         if (defwndproc_counter) msg.flags |= defwinproc;
11046         msg.wParam = wp;
11047         msg.lParam = lp;
11048         msg.descr = "listbox";
11049         add_message(&msg);
11050     }
11051
11052     defwndproc_counter++;
11053     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11054     defwndproc_counter--;
11055
11056     return ret;
11057 }
11058
11059 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11060                                int caret_index, int top_index, int line)
11061 {
11062     LRESULT ret;
11063
11064     /* calling an orig proc helps to avoid unnecessary message logging */
11065     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11066     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11067     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11068     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11069     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11070     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
11071     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11072     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11073 }
11074
11075 static void test_listbox_messages(void)
11076 {
11077     HWND parent, listbox;
11078     LRESULT ret;
11079
11080     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11081                              100, 100, 200, 200, 0, 0, 0, NULL);
11082     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11083                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11084                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11085     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11086
11087     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11088
11089     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11090     ok(ret == 0, "expected 0, got %ld\n", ret);
11091     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11092     ok(ret == 1, "expected 1, got %ld\n", ret);
11093     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11094     ok(ret == 2, "expected 2, got %ld\n", ret);
11095
11096     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11097
11098     flush_sequence();
11099
11100     log_all_parent_messages++;
11101
11102     trace("selecting item 0\n");
11103     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11104     ok(ret == 0, "expected 0, got %ld\n", ret);
11105     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11106     check_lb_state(listbox, 3, 0, 0, 0);
11107     flush_sequence();
11108
11109     trace("selecting item 1\n");
11110     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11111     ok(ret == 1, "expected 1, got %ld\n", ret);
11112     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11113     check_lb_state(listbox, 3, 1, 1, 0);
11114
11115     trace("selecting item 2\n");
11116     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11117     ok(ret == 2, "expected 2, got %ld\n", ret);
11118     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11119     check_lb_state(listbox, 3, 2, 2, 0);
11120
11121     trace("clicking on item 0\n");
11122     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11123     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11124     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11125     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11126     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11127     check_lb_state(listbox, 3, 0, 0, 0);
11128     flush_sequence();
11129
11130     log_all_parent_messages--;
11131
11132     DestroyWindow(listbox);
11133     DestroyWindow(parent);
11134 }
11135
11136 /*************************** Menu test ******************************/
11137 static const struct message wm_popup_menu_1[] =
11138 {
11139     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11140     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11141     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11142     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11143     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11144     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11145     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11146     { WM_INITMENU, sent|lparam, 0, 0 },
11147     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11148     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11149     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11150     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11151     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11152     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11153     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11154     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11155     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11156     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11157     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11158     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11159     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11160     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11161     { 0 }
11162 };
11163 static const struct message wm_popup_menu_2[] =
11164 {
11165     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11166     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11167     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11168     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11169     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11170     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11171     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11172     { WM_INITMENU, sent|lparam, 0, 0 },
11173     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11174     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11175     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11176     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11177     { HCBT_CREATEWND, hook },
11178     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11179                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11180     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11181     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11182     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11183     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11184     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11185     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11186     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11187     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11188     { HCBT_DESTROYWND, hook },
11189     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11190     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11191     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11192     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11193     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11194     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11195     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11196     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11197     { 0 }
11198 };
11199 static const struct message wm_popup_menu_3[] =
11200 {
11201     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11202     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11203     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11204     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11205     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11206     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11207     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11208     { WM_INITMENU, sent|lparam, 0, 0 },
11209     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11210     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11211     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11212     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11213     { HCBT_CREATEWND, hook },
11214     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11215                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11216     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11217     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11218     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11219     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11220     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11221     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11222     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11223     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11224     { HCBT_DESTROYWND, hook },
11225     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11226     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11227     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11228     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11229     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11230     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11231     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11232     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11233     { 0 }
11234 };
11235
11236 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11237 {
11238     if (message == WM_ENTERIDLE ||
11239         message == WM_INITMENU ||
11240         message == WM_INITMENUPOPUP ||
11241         message == WM_MENUSELECT ||
11242         message == WM_PARENTNOTIFY ||
11243         message == WM_ENTERMENULOOP ||
11244         message == WM_EXITMENULOOP ||
11245         message == WM_UNINITMENUPOPUP ||
11246         message == WM_KEYDOWN ||
11247         message == WM_KEYUP ||
11248         message == WM_CHAR ||
11249         message == WM_SYSKEYDOWN ||
11250         message == WM_SYSKEYUP ||
11251         message == WM_SYSCHAR ||
11252         message == WM_COMMAND ||
11253         message == WM_MENUCOMMAND)
11254     {
11255         struct recvd_message msg;
11256
11257         msg.hwnd = hwnd;
11258         msg.message = message;
11259         msg.flags = sent|wparam|lparam;
11260         msg.wParam = wp;
11261         msg.lParam = lp;
11262         msg.descr = "parent_menu_proc";
11263         add_message(&msg);
11264     }
11265
11266     return DefWindowProcA(hwnd, message, wp, lp);
11267 }
11268
11269 static void set_menu_style(HMENU hmenu, DWORD style)
11270 {
11271     MENUINFO mi;
11272     BOOL ret;
11273
11274     mi.cbSize = sizeof(mi);
11275     mi.fMask = MIM_STYLE;
11276     mi.dwStyle = style;
11277     SetLastError(0xdeadbeef);
11278     ret = pSetMenuInfo(hmenu, &mi);
11279     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11280 }
11281
11282 static DWORD get_menu_style(HMENU hmenu)
11283 {
11284     MENUINFO mi;
11285     BOOL ret;
11286
11287     mi.cbSize = sizeof(mi);
11288     mi.fMask = MIM_STYLE;
11289     mi.dwStyle = 0;
11290     SetLastError(0xdeadbeef);
11291     ret = pGetMenuInfo(hmenu, &mi);
11292     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11293
11294     return mi.dwStyle;
11295 }
11296
11297 static void test_menu_messages(void)
11298 {
11299     MSG msg;
11300     WNDCLASSA cls;
11301     HMENU hmenu, hmenu_popup;
11302     HWND hwnd;
11303     DWORD style;
11304
11305     if (!pGetMenuInfo || !pSetMenuInfo)
11306     {
11307         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11308         return;
11309     }
11310     cls.style = 0;
11311     cls.lpfnWndProc = parent_menu_proc;
11312     cls.cbClsExtra = 0;
11313     cls.cbWndExtra = 0;
11314     cls.hInstance = GetModuleHandleA(0);
11315     cls.hIcon = 0;
11316     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11317     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11318     cls.lpszMenuName = NULL;
11319     cls.lpszClassName = "TestMenuClass";
11320     UnregisterClass(cls.lpszClassName, cls.hInstance);
11321     if (!RegisterClassA(&cls)) assert(0);
11322
11323     SetLastError(0xdeadbeef);
11324     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11325                            100, 100, 200, 200, 0, 0, 0, NULL);
11326     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11327
11328     SetLastError(0xdeadbeef);
11329     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11330     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11331
11332     SetMenu(hwnd, hmenu);
11333     SetForegroundWindow( hwnd );
11334
11335     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11336     style = get_menu_style(hmenu);
11337     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11338
11339     hmenu_popup = GetSubMenu(hmenu, 0);
11340     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11341     style = get_menu_style(hmenu_popup);
11342     ok(style == 0, "expected 0, got %u\n", style);
11343
11344     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11345     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11346     style = get_menu_style(hmenu_popup);
11347     ok(style == 0, "expected 0, got %u\n", style);
11348
11349     /* Alt+E, Enter */
11350     trace("testing a popup menu command\n");
11351     flush_sequence();
11352     keybd_event(VK_MENU, 0, 0, 0);
11353     keybd_event('E', 0, 0, 0);
11354     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11355     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11356     keybd_event(VK_RETURN, 0, 0, 0);
11357     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11358     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11359     {
11360         TranslateMessage(&msg);
11361         DispatchMessage(&msg);
11362     }
11363     if (!sequence_cnt)  /* we didn't get any message */
11364     {
11365         skip( "queuing key events not supported\n" );
11366         goto done;
11367     }
11368     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11369     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11370     {
11371         win_skip( "menu tracking through VK_MENU not supported\n" );
11372         goto done;
11373     }
11374     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11375
11376     /* Alt+F, Right, Enter */
11377     trace("testing submenu of a popup menu command\n");
11378     flush_sequence();
11379     keybd_event(VK_MENU, 0, 0, 0);
11380     keybd_event('F', 0, 0, 0);
11381     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11382     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11383     keybd_event(VK_RIGHT, 0, 0, 0);
11384     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11385     keybd_event(VK_RETURN, 0, 0, 0);
11386     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11387     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11388     {
11389         TranslateMessage(&msg);
11390         DispatchMessage(&msg);
11391     }
11392     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11393
11394     set_menu_style(hmenu, 0);
11395     style = get_menu_style(hmenu);
11396     ok(style == 0, "expected 0, got %u\n", style);
11397
11398     hmenu_popup = GetSubMenu(hmenu, 0);
11399     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11400     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11401     style = get_menu_style(hmenu_popup);
11402     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11403
11404     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11405     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11406     style = get_menu_style(hmenu_popup);
11407     ok(style == 0, "expected 0, got %u\n", style);
11408
11409     /* Alt+F, Right, Enter */
11410     trace("testing submenu of a popup menu command\n");
11411     flush_sequence();
11412     keybd_event(VK_MENU, 0, 0, 0);
11413     keybd_event('F', 0, 0, 0);
11414     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11415     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11416     keybd_event(VK_RIGHT, 0, 0, 0);
11417     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11418     keybd_event(VK_RETURN, 0, 0, 0);
11419     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11420     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11421     {
11422         TranslateMessage(&msg);
11423         DispatchMessage(&msg);
11424     }
11425     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11426
11427 done:
11428     DestroyWindow(hwnd);
11429     DestroyMenu(hmenu);
11430 }
11431
11432
11433 static void test_paintingloop(void)
11434 {
11435     HWND hwnd;
11436
11437     paint_loop_done = 0;
11438     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11439                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11440                                 100, 100, 100, 100, 0, 0, 0, NULL );
11441     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11442     ShowWindow(hwnd,SW_NORMAL);
11443     SetFocus(hwnd);
11444
11445     while (!paint_loop_done)
11446     {
11447         MSG msg;
11448         if (PeekMessageA(&msg, 0, 0, 0, 1))
11449         {
11450             TranslateMessage(&msg);
11451             DispatchMessage(&msg);
11452         }
11453     }
11454     DestroyWindow(hwnd);
11455 }
11456
11457 static void test_defwinproc(void)
11458 {
11459     HWND hwnd;
11460     MSG msg;
11461     int gotwmquit = FALSE;
11462     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11463     assert(hwnd);
11464     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11465     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11466         if( msg.message == WM_QUIT) gotwmquit = TRUE;
11467         DispatchMessageA( &msg );
11468     }
11469     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11470     DestroyWindow( hwnd);
11471 }
11472
11473 START_TEST(msg)
11474 {
11475     BOOL ret;
11476     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11477
11478     init_procs();
11479
11480     if (!RegisterWindowClasses()) assert(0);
11481
11482     if (pSetWinEventHook)
11483     {
11484         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11485                                        GetModuleHandleA(0), win_event_proc,
11486                                        0, GetCurrentThreadId(),
11487                                        WINEVENT_INCONTEXT);
11488         if (pIsWinEventHookInstalled && hEvent_hook)
11489         {
11490             UINT event;
11491             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11492                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11493         }
11494     }
11495     if (!hEvent_hook) win_skip( "no win event hook support\n" );
11496
11497     cbt_hook_thread_id = GetCurrentThreadId();
11498     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11499     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
11500
11501     test_winevents();
11502
11503     /* Fix message sequences before removing 4 lines below */
11504 #if 1
11505     if (pUnhookWinEvent && hEvent_hook)
11506     {
11507         ret = pUnhookWinEvent(hEvent_hook);
11508         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11509         pUnhookWinEvent = 0;
11510     }
11511     hEvent_hook = 0;
11512 #endif
11513
11514     test_ShowWindow();
11515     test_PeekMessage();
11516     test_PeekMessage2();
11517     test_scrollwindowex();
11518     test_messages();
11519     test_setwindowpos();
11520     test_showwindow();
11521     invisible_parent_tests();
11522     test_mdi_messages();
11523     test_button_messages();
11524     test_static_messages();
11525     test_listbox_messages();
11526     test_combobox_messages();
11527     test_wmime_keydown_message();
11528     test_paint_messages();
11529     test_interthread_messages();
11530     test_message_conversion();
11531     test_accelerators();
11532     test_timers();
11533     test_timers_no_wnd();
11534     if (hCBT_hook) test_set_hook();
11535     test_DestroyWindow();
11536     test_DispatchMessage();
11537     test_SendMessageTimeout();
11538     test_edit_messages();
11539     test_quit_message();
11540     test_SetActiveWindow();
11541
11542     if (!pTrackMouseEvent)
11543         win_skip("TrackMouseEvent is not available\n");
11544     else
11545         test_TrackMouseEvent();
11546
11547     test_SetWindowRgn();
11548     test_sys_menu();
11549     test_dialog_messages();
11550     test_nullCallback();
11551     test_dbcs_wm_char();
11552     test_menu_messages();
11553     test_paintingloop();
11554     test_defwinproc();
11555     /* keep it the last test, under Windows it tends to break the tests
11556      * which rely on active/foreground windows being correct.
11557      */
11558     test_SetForegroundWindow();
11559
11560     UnhookWindowsHookEx(hCBT_hook);
11561     if (pUnhookWinEvent && hEvent_hook)
11562     {
11563         ret = pUnhookWinEvent(hEvent_hook);
11564         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11565         SetLastError(0xdeadbeef);
11566         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11567         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11568            GetLastError() == 0xdeadbeef, /* Win9x */
11569            "unexpected error %d\n", GetLastError());
11570     }
11571 }