crypt32/tests: Fix some test failures on Win9x.
[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     /* Vista sometimes restores the window right away... */
594     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
595     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
596     { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
597     { WM_PAINT, sent|optional },
598     { WM_NCPAINT, sent|beginpaint|optional },
599     { WM_ERASEBKGND, sent|beginpaint|optional },
600     { 0 }
601 };
602 /* ShowWindow(SW_HIDE) for a visible overlapped window */
603 static const struct message WmHideOverlappedSeq[] = {
604     { WM_SHOWWINDOW, sent|wparam, 0 },
605     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
606     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
607     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
608     { WM_SIZE, sent|optional }, /* XP doesn't send it */
609     { WM_MOVE, sent|optional }, /* XP doesn't send it */
610     { WM_NCACTIVATE, sent|wparam, 0 },
611     { WM_ACTIVATE, sent|wparam, 0 },
612     { WM_ACTIVATEAPP, sent|wparam, 0 },
613     { WM_KILLFOCUS, sent|wparam, 0 },
614     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
615     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
616     { 0 }
617 };
618 /* DestroyWindow for a visible overlapped window */
619 static const struct message WmDestroyOverlappedSeq[] = {
620     { HCBT_DESTROYWND, hook },
621     { 0x0090, sent|optional },
622     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
623     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
624     { 0x0090, sent|optional },
625     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
626     { WM_NCACTIVATE, sent|optional|wparam, 0 },
627     { WM_ACTIVATE, sent|optional },
628     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
629     { WM_KILLFOCUS, sent|optional|wparam, 0 },
630     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
631     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
632     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
633     { WM_DESTROY, sent },
634     { WM_NCDESTROY, sent },
635     { 0 }
636 };
637 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
638 static const struct message WmCreateMaxPopupSeq[] = {
639     { HCBT_CREATEWND, hook },
640     { WM_NCCREATE, sent },
641     { WM_NCCALCSIZE, sent|wparam, 0 },
642     { WM_CREATE, sent },
643     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
644     { WM_SIZE, sent|wparam, SIZE_RESTORED },
645     { WM_MOVE, sent },
646     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
647     { WM_GETMINMAXINFO, sent },
648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
649     { WM_NCCALCSIZE, sent|wparam, TRUE },
650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
651     { WM_MOVE, sent|defwinproc },
652     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
653     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
654     { WM_SHOWWINDOW, sent|wparam, 1 },
655     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
656     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
657     { HCBT_ACTIVATE, hook },
658     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
659     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
660     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
661     { WM_NCPAINT, sent|wparam|optional, 1 },
662     { WM_ERASEBKGND, sent|optional },
663     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
664     { WM_ACTIVATEAPP, sent|wparam, 1 },
665     { WM_NCACTIVATE, sent },
666     { WM_ACTIVATE, sent|wparam, 1 },
667     { HCBT_SETFOCUS, hook },
668     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
669     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
670     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
671     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
672     { WM_GETTEXT, sent|optional },
673     { WM_SYNCPAINT, sent|wparam|optional, 4 },
674     { WM_NCPAINT, sent|wparam|optional, 1 },
675     { WM_ERASEBKGND, sent|optional },
676     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
677     { WM_ERASEBKGND, sent|defwinproc|optional },
678     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
679     { 0 }
680 };
681 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
682 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
683     { HCBT_CREATEWND, hook },
684     { WM_NCCREATE, sent },
685     { WM_NCCALCSIZE, sent|wparam, 0 },
686     { WM_CREATE, sent },
687     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
688     { WM_SIZE, sent|wparam, SIZE_RESTORED },
689     { WM_MOVE, sent },
690     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
691     { WM_GETMINMAXINFO, sent },
692     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
693     { WM_NCCALCSIZE, sent|wparam, TRUE },
694     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
695     { WM_MOVE, sent|defwinproc },
696     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
697     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
698     { 0 }
699 };
700 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
701 static const struct message WmShowMaxPopupResizedSeq[] = {
702     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
703     { WM_GETMINMAXINFO, sent },
704     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
705     { WM_NCCALCSIZE, sent|wparam, TRUE },
706     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
707     { HCBT_ACTIVATE, hook },
708     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
709     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
710     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
711     { WM_NCPAINT, sent|wparam|optional, 1 },
712     { WM_ERASEBKGND, sent|optional },
713     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
714     { WM_ACTIVATEAPP, sent|wparam, 1 },
715     { WM_NCACTIVATE, sent },
716     { WM_ACTIVATE, sent|wparam, 1 },
717     { HCBT_SETFOCUS, hook },
718     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
719     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
720     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
721     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
722     { WM_GETTEXT, sent|optional },
723     { WM_NCPAINT, sent|wparam|optional, 1 },
724     { WM_ERASEBKGND, sent|optional },
725     { WM_WINDOWPOSCHANGED, sent },
726     /* WinNT4.0 sends WM_MOVE */
727     { WM_MOVE, sent|defwinproc|optional },
728     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
729     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
730     { 0 }
731 };
732 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
733 static const struct message WmShowMaxPopupSeq[] = {
734     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
735     { WM_GETMINMAXINFO, sent },
736     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
737     { WM_NCCALCSIZE, sent|wparam, TRUE },
738     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
739     { HCBT_ACTIVATE, hook },
740     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
741     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
742     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
743     { WM_ACTIVATEAPP, sent|wparam, 1 },
744     { WM_NCACTIVATE, sent },
745     { WM_ACTIVATE, sent|wparam, 1 },
746     { HCBT_SETFOCUS, hook },
747     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
748     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
749     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
750     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
751     { WM_GETTEXT, sent|optional },
752     { WM_SYNCPAINT, sent|wparam|optional, 4 },
753     { WM_NCPAINT, sent|wparam|optional, 1 },
754     { WM_ERASEBKGND, sent|optional },
755     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
756     { WM_ERASEBKGND, sent|defwinproc|optional },
757     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
758     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
759     { 0 }
760 };
761 /* CreateWindow(WS_VISIBLE) for popup window */
762 static const struct message WmCreatePopupSeq[] = {
763     { HCBT_CREATEWND, hook },
764     { WM_NCCREATE, sent },
765     { WM_NCCALCSIZE, sent|wparam, 0 },
766     { WM_CREATE, sent },
767     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
768     { WM_SIZE, sent|wparam, SIZE_RESTORED },
769     { WM_MOVE, sent },
770     { WM_SHOWWINDOW, sent|wparam, 1 },
771     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
772     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
773     { HCBT_ACTIVATE, hook },
774     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
775     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
776     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
777     { WM_NCPAINT, sent|wparam|optional, 1 },
778     { WM_ERASEBKGND, sent|optional },
779     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
780     { WM_ACTIVATEAPP, sent|wparam, 1 },
781     { WM_NCACTIVATE, sent },
782     { WM_ACTIVATE, sent|wparam, 1 },
783     { HCBT_SETFOCUS, hook },
784     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
785     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
786     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
787     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
788     { WM_GETTEXT, sent|optional },
789     { WM_SYNCPAINT, sent|wparam|optional, 4 },
790     { WM_NCPAINT, sent|wparam|optional, 1 },
791     { WM_ERASEBKGND, sent|optional },
792     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
793     { 0 }
794 };
795 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
796 static const struct message WmShowVisMaxPopupSeq[] = {
797     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
798     { WM_GETMINMAXINFO, sent },
799     { WM_GETTEXT, sent|optional },
800     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
801     { WM_GETTEXT, sent|optional },
802     { WM_NCCALCSIZE, sent|wparam, TRUE },
803     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
804     { WM_NCPAINT, sent|wparam|optional, 1 },
805     { WM_ERASEBKGND, sent|optional },
806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
807     { WM_MOVE, sent|defwinproc },
808     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
809     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
810     { 0 }
811 };
812 /* CreateWindow (for a child popup window, not initially visible) */
813 static const struct message WmCreateChildPopupSeq[] = {
814     { HCBT_CREATEWND, hook },
815     { WM_NCCREATE, sent }, 
816     { WM_NCCALCSIZE, sent|wparam, 0 },
817     { WM_CREATE, sent },
818     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
819     { WM_SIZE, sent|wparam, SIZE_RESTORED },
820     { WM_MOVE, sent },
821     { 0 }
822 };
823 /* CreateWindow (for a popup window, not initially visible,
824  * which sets WS_VISIBLE in WM_CREATE handler)
825  */
826 static const struct message WmCreateInvisiblePopupSeq[] = {
827     { HCBT_CREATEWND, hook },
828     { WM_NCCREATE, sent }, 
829     { WM_NCCALCSIZE, sent|wparam, 0 },
830     { WM_CREATE, sent },
831     { WM_STYLECHANGING, sent },
832     { WM_STYLECHANGED, sent },
833     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
834     { WM_SIZE, sent|wparam, SIZE_RESTORED },
835     { WM_MOVE, sent },
836     { 0 }
837 };
838 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
839  * for a popup window with WS_VISIBLE style set
840  */
841 static const struct message WmShowVisiblePopupSeq_2[] = {
842     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
843     { 0 }
844 };
845 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
846  * for a popup window with WS_VISIBLE style set
847  */
848 static const struct message WmShowVisiblePopupSeq_3[] = {
849     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
850     { HCBT_ACTIVATE, hook },
851     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
852     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
853     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
854     { WM_NCACTIVATE, sent },
855     { WM_ACTIVATE, sent|wparam, 1 },
856     { HCBT_SETFOCUS, hook },
857     { WM_KILLFOCUS, sent|parent },
858     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
859     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
860     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
861     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
862     { WM_SETFOCUS, sent|defwinproc },
863     { WM_GETTEXT, sent|optional },
864     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
865     { 0 }
866 };
867 /* CreateWindow (for child window, not initially visible) */
868 static const struct message WmCreateChildSeq[] = {
869     { HCBT_CREATEWND, hook },
870     { WM_NCCREATE, sent }, 
871     /* child is inserted into parent's child list after WM_NCCREATE returns */
872     { WM_NCCALCSIZE, sent|wparam, 0 },
873     { WM_CREATE, sent },
874     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
875     { WM_SIZE, sent|wparam, SIZE_RESTORED },
876     { WM_MOVE, sent },
877     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
878     { 0 }
879 };
880 /* CreateWindow (for maximized child window, not initially visible) */
881 static const struct message WmCreateMaximizedChildSeq[] = {
882     { HCBT_CREATEWND, hook },
883     { WM_NCCREATE, sent }, 
884     { WM_NCCALCSIZE, sent|wparam, 0 },
885     { WM_CREATE, sent },
886     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
887     { WM_SIZE, sent|wparam, SIZE_RESTORED },
888     { WM_MOVE, sent },
889     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
890     { WM_GETMINMAXINFO, sent },
891     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
892     { WM_NCCALCSIZE, sent|wparam, 1 },
893     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
894     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
895     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
896     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
897     { 0 }
898 };
899 /* CreateWindow (for a child window, initially visible) */
900 static const struct message WmCreateVisibleChildSeq[] = {
901     { HCBT_CREATEWND, hook },
902     { WM_NCCREATE, sent }, 
903     /* child is inserted into parent's child list after WM_NCCREATE returns */
904     { WM_NCCALCSIZE, sent|wparam, 0 },
905     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
906     { WM_CREATE, sent },
907     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
908     { WM_SIZE, sent|wparam, SIZE_RESTORED },
909     { WM_MOVE, sent },
910     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
911     { WM_SHOWWINDOW, sent|wparam, 1 },
912     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
913     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
914     { WM_ERASEBKGND, sent|parent|optional },
915     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
916     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
917     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
918     { 0 }
919 };
920 /* ShowWindow(SW_SHOW) for a not visible child window */
921 static const struct message WmShowChildSeq[] = {
922     { WM_SHOWWINDOW, sent|wparam, 1 },
923     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
924     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
925     { WM_ERASEBKGND, sent|parent|optional },
926     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
927     { 0 }
928 };
929 /* ShowWindow(SW_HIDE) for a visible child window */
930 static const struct message WmHideChildSeq[] = {
931     { WM_SHOWWINDOW, sent|wparam, 0 },
932     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
933     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
934     { WM_ERASEBKGND, sent|parent|optional },
935     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
936     { 0 }
937 };
938 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
939 static const struct message WmHideChildSeq2[] = {
940     { WM_SHOWWINDOW, sent|wparam, 0 },
941     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
942     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
943     { WM_ERASEBKGND, sent|parent|optional },
944     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
945     { 0 }
946 };
947 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
948  * for a not visible child window
949  */
950 static const struct message WmShowChildSeq_2[] = {
951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
952     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
953     { WM_CHILDACTIVATE, sent },
954     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
955     { 0 }
956 };
957 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
958  * for a not visible child window
959  */
960 static const struct message WmShowChildSeq_3[] = {
961     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
962     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
963     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
964     { 0 }
965 };
966 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
967  * for a visible child window with a caption
968  */
969 static const struct message WmShowChildSeq_4[] = {
970     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
971     { WM_CHILDACTIVATE, sent },
972     { 0 }
973 };
974 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
975 static const struct message WmShowChildInvisibleParentSeq_1[] = {
976     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
977     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
978     { WM_NCCALCSIZE, sent|wparam, 1 },
979     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
980     { WM_CHILDACTIVATE, sent|optional },
981     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
982     { WM_MOVE, sent|defwinproc },
983     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
984     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
985     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
986     /* FIXME: Wine creates an icon/title window while Windows doesn't */
987     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
988     { WM_GETTEXT, sent|optional },
989     { 0 }
990 };
991 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
992 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
993     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
994     { 0 }
995 };
996 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
997 static const struct message WmShowChildInvisibleParentSeq_2[] = {
998     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
999     { WM_GETMINMAXINFO, sent },
1000     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1001     { WM_NCCALCSIZE, sent|wparam, 1 },
1002     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1003     { WM_CHILDACTIVATE, sent },
1004     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1005     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1006     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1007     { 0 }
1008 };
1009 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1010 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1011     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1012     { 0 }
1013 };
1014 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1015 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1016     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1017     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1018     { WM_NCCALCSIZE, sent|wparam, 1 },
1019     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1020     { WM_CHILDACTIVATE, sent },
1021     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1022     { WM_MOVE, sent|defwinproc },
1023     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1024     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1025     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1026     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1027     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1028     { WM_GETTEXT, sent|optional },
1029     { 0 }
1030 };
1031 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1032 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1033     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1034     { 0 }
1035 };
1036 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1037 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1038     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1039     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1040     { WM_NCCALCSIZE, sent|wparam, 1 },
1041     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1042     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1043     { WM_MOVE, sent|defwinproc },
1044     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1045     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1046     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1047     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1048     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1049     { WM_GETTEXT, sent|optional },
1050     { 0 }
1051 };
1052 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1053 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1054     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1055     { 0 }
1056 };
1057 /* ShowWindow(SW_SHOW) for child with invisible parent */
1058 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1059     { WM_SHOWWINDOW, sent|wparam, 1 },
1060     { 0 }
1061 };
1062 /* ShowWindow(SW_HIDE) for child with invisible parent */
1063 static const struct message WmHideChildInvisibleParentSeq[] = {
1064     { WM_SHOWWINDOW, sent|wparam, 0 },
1065     { 0 }
1066 };
1067 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1068 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1069     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1070     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1071     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1072     { 0 }
1073 };
1074 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1075 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1076     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1077     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1078     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1079     { 0 }
1080 };
1081 /* DestroyWindow for a visible child window */
1082 static const struct message WmDestroyChildSeq[] = {
1083     { HCBT_DESTROYWND, hook },
1084     { 0x0090, sent|optional },
1085     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1086     { WM_SHOWWINDOW, sent|wparam, 0 },
1087     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1088     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1089     { WM_ERASEBKGND, sent|parent|optional },
1090     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1091     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1092     { WM_KILLFOCUS, sent },
1093     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1094     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1095     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1096     { WM_SETFOCUS, sent|parent },
1097     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1098     { WM_DESTROY, sent },
1099     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1100     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1101     { WM_NCDESTROY, sent },
1102     { 0 }
1103 };
1104 /* DestroyWindow for a visible child window with invisible parent */
1105 static const struct message WmDestroyInvisibleChildSeq[] = {
1106     { HCBT_DESTROYWND, hook },
1107     { 0x0090, sent|optional },
1108     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1109     { WM_SHOWWINDOW, sent|wparam, 0 },
1110     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1111     { WM_DESTROY, sent },
1112     { WM_NCDESTROY, sent },
1113     { 0 }
1114 };
1115 /* Moving the mouse in nonclient area */
1116 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1117     { WM_NCHITTEST, sent },
1118     { WM_SETCURSOR, sent },
1119     { WM_NCMOUSEMOVE, posted },
1120     { 0 }
1121 };
1122 /* Moving the mouse in client area */
1123 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1124     { WM_NCHITTEST, sent },
1125     { WM_SETCURSOR, sent },
1126     { WM_MOUSEMOVE, posted },
1127     { 0 }
1128 };
1129 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1130 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1131     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1132     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1133     { WM_GETMINMAXINFO, sent|defwinproc },
1134     { WM_ENTERSIZEMOVE, sent|defwinproc },
1135     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1136     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1137     { WM_MOVE, sent|defwinproc },
1138     { WM_EXITSIZEMOVE, sent|defwinproc },
1139     { 0 }
1140 };
1141 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1142 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1143     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1144     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1145     { WM_GETMINMAXINFO, sent|defwinproc },
1146     { WM_ENTERSIZEMOVE, sent|defwinproc },
1147     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1148     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1149     { WM_GETMINMAXINFO, sent|defwinproc },
1150     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1151     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1152     { WM_GETTEXT, sent|defwinproc },
1153     { WM_ERASEBKGND, sent|defwinproc },
1154     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1155     { WM_MOVE, sent|defwinproc },
1156     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1157     { WM_EXITSIZEMOVE, sent|defwinproc },
1158     { 0 }
1159 };
1160 /* Resizing child window with MoveWindow (32) */
1161 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1162     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1163     { WM_NCCALCSIZE, sent|wparam, 1 },
1164     { WM_ERASEBKGND, sent|parent|optional },
1165     { WM_ERASEBKGND, sent|optional },
1166     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1167     { WM_MOVE, sent|defwinproc },
1168     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1169     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1170     { 0 }
1171 };
1172 /* Clicking on inactive button */
1173 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1174     { WM_NCHITTEST, sent },
1175     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1176     { WM_MOUSEACTIVATE, sent },
1177     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1178     { WM_SETCURSOR, sent },
1179     { WM_SETCURSOR, sent|parent|defwinproc },
1180     { WM_LBUTTONDOWN, posted },
1181     { WM_KILLFOCUS, posted|parent },
1182     { WM_SETFOCUS, posted },
1183     { WM_CTLCOLORBTN, posted|parent },
1184     { BM_SETSTATE, posted },
1185     { WM_CTLCOLORBTN, posted|parent },
1186     { WM_LBUTTONUP, posted },
1187     { BM_SETSTATE, posted },
1188     { WM_CTLCOLORBTN, posted|parent },
1189     { WM_COMMAND, posted|parent },
1190     { 0 }
1191 };
1192 /* Reparenting a button (16/32) */
1193 /* The last child (button) reparented gets topmost for its new parent. */
1194 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1195     { WM_SHOWWINDOW, sent|wparam, 0 },
1196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1197     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1198     { WM_ERASEBKGND, sent|parent },
1199     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1200     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1201     { WM_CHILDACTIVATE, sent },
1202     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1203     { WM_MOVE, sent|defwinproc },
1204     { WM_SHOWWINDOW, sent|wparam, 1 },
1205     { 0 }
1206 };
1207 /* Creation of a custom dialog (32) */
1208 static const struct message WmCreateCustomDialogSeq[] = {
1209     { HCBT_CREATEWND, hook },
1210     { WM_GETMINMAXINFO, sent },
1211     { WM_NCCREATE, sent },
1212     { WM_NCCALCSIZE, sent|wparam, 0 },
1213     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1214     { WM_CREATE, sent },
1215     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1216     { WM_NOTIFYFORMAT, sent|optional },
1217     { WM_QUERYUISTATE, sent|optional },
1218     { WM_WINDOWPOSCHANGING, sent|optional },
1219     { WM_GETMINMAXINFO, sent|optional },
1220     { WM_NCCALCSIZE, sent|optional },
1221     { WM_WINDOWPOSCHANGED, sent|optional },
1222     { WM_SHOWWINDOW, sent|wparam, 1 },
1223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1224     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1225     { HCBT_ACTIVATE, hook },
1226     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1227
1228
1229     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1230
1231     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1232
1233     { WM_NCACTIVATE, sent },
1234     { WM_GETTEXT, sent|optional|defwinproc },
1235     { WM_GETTEXT, sent|optional|defwinproc },
1236     { WM_GETTEXT, sent|optional|defwinproc },
1237     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1238     { WM_ACTIVATE, sent|wparam, 1 },
1239     { WM_GETTEXT, sent|optional },
1240     { WM_KILLFOCUS, sent|parent },
1241     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1242     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1243     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1244     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1245     { WM_SETFOCUS, sent },
1246     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1247     { WM_NCPAINT, sent|wparam, 1 },
1248     { WM_GETTEXT, sent|optional|defwinproc },
1249     { WM_GETTEXT, sent|optional|defwinproc },
1250     { WM_ERASEBKGND, sent },
1251     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1252     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1253     { WM_GETTEXT, sent|optional },
1254     { WM_GETTEXT, sent|optional },
1255     { WM_NCCALCSIZE, sent|optional },
1256     { WM_NCPAINT, sent|optional },
1257     { WM_GETTEXT, sent|optional|defwinproc },
1258     { WM_GETTEXT, sent|optional|defwinproc },
1259     { WM_ERASEBKGND, sent|optional },
1260     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1261     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1262     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1263     { WM_MOVE, sent },
1264     { 0 }
1265 };
1266 /* Calling EndDialog for a custom dialog (32) */
1267 static const struct message WmEndCustomDialogSeq[] = {
1268     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1269     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1270     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1271     { WM_GETTEXT, sent|optional },
1272     { HCBT_ACTIVATE, hook },
1273     { WM_NCACTIVATE, sent|wparam, 0 },
1274     { WM_GETTEXT, sent|optional|defwinproc },
1275     { WM_GETTEXT, sent|optional|defwinproc },
1276     { WM_ACTIVATE, sent|wparam, 0 },
1277     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1278     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1279     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1280     { WM_GETTEXT, sent|optional|defwinproc },
1281     { WM_GETTEXT, sent|optional|defwinproc },
1282     { HCBT_SETFOCUS, hook },
1283     { WM_KILLFOCUS, sent },
1284     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1285     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1286     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1287     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1288     { WM_SETFOCUS, sent|parent|defwinproc },
1289     { 0 }
1290 };
1291 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1292 static const struct message WmShowCustomDialogSeq[] = {
1293     { WM_SHOWWINDOW, sent|wparam, 1 },
1294     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1295     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1296     { HCBT_ACTIVATE, hook },
1297     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1298
1299     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1300
1301     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1302     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1303     { WM_NCACTIVATE, sent },
1304     { WM_ACTIVATE, sent|wparam, 1 },
1305     { WM_GETTEXT, sent|optional },
1306
1307     { WM_KILLFOCUS, sent|parent },
1308     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1309     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1310     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1311     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1312     { WM_SETFOCUS, sent },
1313     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1314     { WM_NCPAINT, sent|wparam, 1 },
1315     { WM_ERASEBKGND, sent },
1316     { WM_CTLCOLORDLG, sent|defwinproc },
1317     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1318     { 0 }
1319 };
1320 /* Creation and destruction of a modal dialog (32) */
1321 static const struct message WmModalDialogSeq[] = {
1322     { WM_CANCELMODE, sent|parent },
1323     { HCBT_SETFOCUS, hook },
1324     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1325     { WM_KILLFOCUS, sent|parent },
1326     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1327     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1328     { WM_ENABLE, sent|parent|wparam, 0 },
1329     { HCBT_CREATEWND, hook },
1330     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1331     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1332     { WM_SETFONT, sent },
1333     { WM_INITDIALOG, sent },
1334     { WM_CHANGEUISTATE, sent|optional },
1335     { WM_UPDATEUISTATE, sent|optional },
1336     { WM_SHOWWINDOW, sent },
1337     { HCBT_ACTIVATE, hook },
1338     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1339     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1340     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1341     { WM_NCACTIVATE, sent },
1342     { WM_GETTEXT, sent|optional },
1343     { WM_ACTIVATE, sent|wparam, 1 },
1344     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1345     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1346     { WM_NCPAINT, sent|optional },
1347     { WM_GETTEXT, sent|optional },
1348     { WM_ERASEBKGND, sent|optional },
1349     { WM_CTLCOLORDLG, sent|optional },
1350     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1351     { WM_GETTEXT, sent|optional },
1352     { WM_NCCALCSIZE, sent|optional },
1353     { WM_NCPAINT, sent|optional },
1354     { WM_GETTEXT, sent|optional },
1355     { WM_ERASEBKGND, sent|optional },
1356     { WM_CTLCOLORDLG, sent|optional },
1357     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1358     { WM_PAINT, sent|optional },
1359     { WM_CTLCOLORBTN, sent|optional },
1360     { WM_GETTITLEBARINFOEX, sent|optional },
1361     { WM_ENTERIDLE, sent|parent|optional },
1362     { WM_ENTERIDLE, sent|parent|optional },
1363     { WM_ENTERIDLE, sent|parent|optional },
1364     { WM_ENTERIDLE, sent|parent|optional },
1365     { WM_ENTERIDLE, sent|parent|optional },
1366     { WM_ENTERIDLE, sent|parent|optional },
1367     { WM_ENTERIDLE, sent|parent|optional },
1368     { WM_ENTERIDLE, sent|parent|optional },
1369     { WM_ENTERIDLE, sent|parent|optional },
1370     { WM_ENTERIDLE, sent|parent|optional },
1371     { WM_ENTERIDLE, sent|parent|optional },
1372     { WM_ENTERIDLE, sent|parent|optional },
1373     { WM_ENTERIDLE, sent|parent|optional },
1374     { WM_ENTERIDLE, sent|parent|optional },
1375     { WM_ENTERIDLE, sent|parent|optional },
1376     { WM_ENTERIDLE, sent|parent|optional },
1377     { WM_ENTERIDLE, sent|parent|optional },
1378     { WM_ENTERIDLE, sent|parent|optional },
1379     { WM_ENTERIDLE, sent|parent|optional },
1380     { WM_ENTERIDLE, sent|parent|optional },
1381     { WM_TIMER, sent },
1382     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1383     { WM_ENABLE, sent|parent|wparam, 1 },
1384     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1385     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1386     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1387     { WM_GETTEXT, sent|optional },
1388     { HCBT_ACTIVATE, hook },
1389     { WM_NCACTIVATE, sent|wparam, 0 },
1390     { WM_GETTEXT, sent|optional },
1391     { WM_ACTIVATE, sent|wparam, 0 },
1392     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1393     { WM_WINDOWPOSCHANGING, sent|optional },
1394     { WM_WINDOWPOSCHANGED, sent|optional },
1395     { HCBT_SETFOCUS, hook },
1396     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1397     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1398     { WM_SETFOCUS, sent|parent|defwinproc },
1399     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1400     { HCBT_DESTROYWND, hook },
1401     { 0x0090, sent|optional },
1402     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1403     { WM_DESTROY, sent },
1404     { WM_NCDESTROY, sent },
1405     { 0 }
1406 };
1407 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1408 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1409     /* (inside dialog proc, handling WM_INITDIALOG) */
1410     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1411     { WM_NCCALCSIZE, sent },
1412     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1413     { WM_GETTEXT, sent|defwinproc },
1414     { WM_ACTIVATE, sent|parent|wparam, 0 },
1415     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1416     { WM_WINDOWPOSCHANGING, sent|parent },
1417     { WM_NCACTIVATE, sent|wparam, 1 },
1418     { WM_ACTIVATE, sent|wparam, 1 },
1419     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1420     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1421     /* (setting focus) */
1422     { WM_SHOWWINDOW, sent|wparam, 1 },
1423     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1424     { WM_NCPAINT, sent },
1425     { WM_GETTEXT, sent|defwinproc },
1426     { WM_ERASEBKGND, sent },
1427     { WM_CTLCOLORDLG, sent|defwinproc },
1428     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1429     { WM_PAINT, sent },
1430     /* (bunch of WM_CTLCOLOR* for each control) */
1431     { WM_PAINT, sent|parent },
1432     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1433     { WM_SETCURSOR, sent|parent },
1434     { 0 }
1435 };
1436 /* SetMenu for NonVisible windows with size change*/
1437 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1438     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1439     { WM_NCCALCSIZE, sent|wparam, 1 },
1440     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1441     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1442     { WM_MOVE, sent|defwinproc },
1443     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1444     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1445     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1446     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1447     { WM_GETTEXT, sent|optional },
1448     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1449     { 0 }
1450 };
1451 /* SetMenu for NonVisible windows with no size change */
1452 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1453     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1454     { WM_NCCALCSIZE, sent|wparam, 1 },
1455     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1456     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1457     { 0 }
1458 };
1459 /* SetMenu for Visible windows with size change */
1460 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1461     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1462     { WM_NCCALCSIZE, sent|wparam, 1 },
1463     { 0x0093, sent|defwinproc|optional },
1464     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1465     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1466     { 0x0093, sent|defwinproc|optional },
1467     { 0x0093, sent|defwinproc|optional },
1468     { 0x0091, sent|defwinproc|optional },
1469     { 0x0092, sent|defwinproc|optional },
1470     { WM_GETTEXT, sent|defwinproc|optional },
1471     { WM_ERASEBKGND, sent|optional },
1472     { WM_ACTIVATE, sent|optional },
1473     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474     { WM_MOVE, sent|defwinproc },
1475     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1476     { 0x0093, sent|optional },
1477     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1478     { 0x0093, sent|defwinproc|optional },
1479     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1480     { 0x0093, sent|defwinproc|optional },
1481     { 0x0093, sent|defwinproc|optional },
1482     { 0x0091, sent|defwinproc|optional },
1483     { 0x0092, sent|defwinproc|optional },
1484     { WM_ERASEBKGND, sent|optional },
1485     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1486     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1487     { 0 }
1488 };
1489 /* SetMenu for Visible windows with no size change */
1490 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1491     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1492     { WM_NCCALCSIZE, sent|wparam, 1 },
1493     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
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|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1498     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1499     { 0 }
1500 };
1501 /* DrawMenuBar for a visible window */
1502 static const struct message WmDrawMenuBarSeq[] =
1503 {
1504     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1505     { WM_NCCALCSIZE, sent|wparam, 1 },
1506     { 0x0093, sent|defwinproc|optional },
1507     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1508     { 0x0093, sent|defwinproc|optional },
1509     { 0x0093, sent|defwinproc|optional },
1510     { 0x0091, sent|defwinproc|optional },
1511     { 0x0092, sent|defwinproc|optional },
1512     { WM_GETTEXT, sent|defwinproc|optional },
1513     { WM_ERASEBKGND, sent|optional },
1514     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1515     { 0x0093, sent|optional },
1516     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1517     { 0 }
1518 };
1519
1520 static const struct message WmSetRedrawFalseSeq[] =
1521 {
1522     { WM_SETREDRAW, sent|wparam, 0 },
1523     { 0 }
1524 };
1525
1526 static const struct message WmSetRedrawTrueSeq[] =
1527 {
1528     { WM_SETREDRAW, sent|wparam, 1 },
1529     { 0 }
1530 };
1531
1532 static const struct message WmEnableWindowSeq_1[] =
1533 {
1534     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1535     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1536     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1537     { 0 }
1538 };
1539
1540 static const struct message WmEnableWindowSeq_2[] =
1541 {
1542     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1543     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1544     { 0 }
1545 };
1546
1547 static const struct message WmGetScrollRangeSeq[] =
1548 {
1549     { SBM_GETRANGE, sent },
1550     { 0 }
1551 };
1552 static const struct message WmGetScrollInfoSeq[] =
1553 {
1554     { SBM_GETSCROLLINFO, sent },
1555     { 0 }
1556 };
1557 static const struct message WmSetScrollRangeSeq[] =
1558 {
1559     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1560        sends SBM_SETSCROLLINFO.
1561      */
1562     { SBM_SETSCROLLINFO, sent },
1563     { 0 }
1564 };
1565 /* SetScrollRange for a window without a non-client area */
1566 static const struct message WmSetScrollRangeHSeq_empty[] =
1567 {
1568     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1569     { 0 }
1570 };
1571 static const struct message WmSetScrollRangeVSeq_empty[] =
1572 {
1573     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1574     { 0 }
1575 };
1576 static const struct message WmSetScrollRangeHVSeq[] =
1577 {
1578     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1579     { WM_NCCALCSIZE, sent|wparam, 1 },
1580     { WM_GETTEXT, sent|defwinproc|optional },
1581     { WM_ERASEBKGND, sent|optional },
1582     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1583     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1584     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1585     { 0 }
1586 };
1587 /* SetScrollRange for a window with a non-client area */
1588 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1589 {
1590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1591     { WM_NCCALCSIZE, sent|wparam, 1 },
1592     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1593     { WM_NCPAINT, sent|optional },
1594     { WM_STYLECHANGING, sent|defwinproc|optional },
1595     { WM_STYLECHANGED, sent|defwinproc|optional },
1596     { WM_STYLECHANGING, sent|defwinproc|optional },
1597     { WM_STYLECHANGED, sent|defwinproc|optional },
1598     { WM_STYLECHANGING, sent|defwinproc|optional },
1599     { WM_STYLECHANGED, sent|defwinproc|optional },
1600     { WM_STYLECHANGING, sent|defwinproc|optional },
1601     { WM_STYLECHANGED, sent|defwinproc|optional },
1602     { WM_GETTEXT, sent|defwinproc|optional },
1603     { WM_GETTEXT, sent|defwinproc|optional },
1604     { WM_ERASEBKGND, sent|optional },
1605     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1606     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1607     { WM_SIZE, sent|defwinproc|optional },
1608     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1609     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1610     { WM_GETTEXT, sent|optional },
1611     { WM_GETTEXT, sent|optional },
1612     { WM_GETTEXT, sent|optional },
1613     { WM_GETTEXT, sent|optional },
1614     { 0 }
1615 };
1616 /* test if we receive the right sequence of messages */
1617 /* after calling ShowWindow( SW_SHOWNA) */
1618 static const struct message WmSHOWNAChildInvisParInvis[] = {
1619     { WM_SHOWWINDOW, sent|wparam, 1 },
1620     { 0 }
1621 };
1622 static const struct message WmSHOWNAChildVisParInvis[] = {
1623     { WM_SHOWWINDOW, sent|wparam, 1 },
1624     { 0 }
1625 };
1626 static const struct message WmSHOWNAChildVisParVis[] = {
1627     { WM_SHOWWINDOW, sent|wparam, 1 },
1628     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1629     { 0 }
1630 };
1631 static const struct message WmSHOWNAChildInvisParVis[] = {
1632     { WM_SHOWWINDOW, sent|wparam, 1 },
1633     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1634     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1635     { WM_ERASEBKGND, sent|optional },
1636     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1637     { 0 }
1638 };
1639 static const struct message WmSHOWNATopVisible[] = {
1640     { WM_SHOWWINDOW, sent|wparam, 1 },
1641     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1642     { WM_NCPAINT, sent|wparam|optional, 1 },
1643     { WM_GETTEXT, sent|defwinproc|optional },
1644     { WM_ERASEBKGND, sent|optional },
1645     { WM_WINDOWPOSCHANGED, sent|optional },
1646     { 0 }
1647 };
1648 static const struct message WmSHOWNATopInvisible[] = {
1649     { WM_NOTIFYFORMAT, sent|optional },
1650     { WM_QUERYUISTATE, sent|optional },
1651     { WM_WINDOWPOSCHANGING, sent|optional },
1652     { WM_GETMINMAXINFO, sent|optional },
1653     { WM_NCCALCSIZE, sent|optional },
1654     { WM_WINDOWPOSCHANGED, sent|optional },
1655     { WM_SHOWWINDOW, sent|wparam, 1 },
1656     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1657     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1658     { WM_NCPAINT, sent|wparam|optional, 1 },
1659     { WM_GETTEXT, sent|defwinproc|optional },
1660     { WM_ERASEBKGND, sent|optional },
1661     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1662     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1663     { WM_NCPAINT, sent|wparam|optional, 1 },
1664     { WM_ERASEBKGND, sent|optional },
1665     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1666     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1667     { WM_MOVE, sent },
1668     { 0 }
1669 };
1670
1671 static int after_end_dialog, test_def_id;
1672 static int sequence_cnt, sequence_size;
1673 static struct recvd_message* sequence;
1674 static int log_all_parent_messages;
1675 static int paint_loop_done;
1676
1677 /* user32 functions */
1678 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1679 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1680 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1681 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1682 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1683 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1684 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1685 /* kernel32 functions */
1686 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1687
1688 static void init_procs(void)
1689 {
1690     HMODULE user32 = GetModuleHandleA("user32.dll");
1691     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1692
1693 #define GET_PROC(dll, func) \
1694     p ## func = (void*)GetProcAddress(dll, #func); \
1695     if(!p ## func) { \
1696       trace("GetProcAddress(%s) failed\n", #func); \
1697     }
1698
1699     GET_PROC(user32, GetAncestor)
1700     GET_PROC(user32, GetMenuInfo)
1701     GET_PROC(user32, NotifyWinEvent)
1702     GET_PROC(user32, SetMenuInfo)
1703     GET_PROC(user32, SetWinEventHook)
1704     GET_PROC(user32, TrackMouseEvent)
1705     GET_PROC(user32, UnhookWinEvent)
1706
1707     GET_PROC(kernel32, GetCPInfoExA)
1708
1709 #undef GET_PROC
1710 }
1711
1712 static const char *get_winpos_flags(UINT flags)
1713 {
1714     static char buffer[300];
1715
1716     buffer[0] = 0;
1717 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1718     DUMP( SWP_SHOWWINDOW );
1719     DUMP( SWP_HIDEWINDOW );
1720     DUMP( SWP_NOACTIVATE );
1721     DUMP( SWP_FRAMECHANGED );
1722     DUMP( SWP_NOCOPYBITS );
1723     DUMP( SWP_NOOWNERZORDER );
1724     DUMP( SWP_NOSENDCHANGING );
1725     DUMP( SWP_DEFERERASE );
1726     DUMP( SWP_ASYNCWINDOWPOS );
1727     DUMP( SWP_NOZORDER );
1728     DUMP( SWP_NOREDRAW );
1729     DUMP( SWP_NOSIZE );
1730     DUMP( SWP_NOMOVE );
1731     DUMP( SWP_NOCLIENTSIZE );
1732     DUMP( SWP_NOCLIENTMOVE );
1733     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1734     return buffer + 1;
1735 #undef DUMP
1736 }
1737
1738
1739 #define add_message(msg) add_message_(__LINE__,msg);
1740 static void add_message_(int line, const struct recvd_message *msg)
1741 {
1742     struct recvd_message *seq;
1743
1744     if (!sequence) 
1745     {
1746         sequence_size = 10;
1747         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1748     }
1749     if (sequence_cnt == sequence_size) 
1750     {
1751         sequence_size *= 2;
1752         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1753     }
1754     assert(sequence);
1755
1756     seq = &sequence[sequence_cnt];
1757     seq->hwnd = msg->hwnd;
1758     seq->message = msg->message;
1759     seq->flags = msg->flags;
1760     seq->wParam = msg->wParam;
1761     seq->lParam = msg->lParam;
1762     seq->line   = line;
1763     seq->descr  = msg->descr;
1764     seq->output[0] = 0;
1765
1766     if (msg->descr)
1767     {
1768         if (msg->flags & hook)
1769         {
1770             static const char * const CBT_code_name[10] =
1771             {
1772                 "HCBT_MOVESIZE",
1773                 "HCBT_MINMAX",
1774                 "HCBT_QS",
1775                 "HCBT_CREATEWND",
1776                 "HCBT_DESTROYWND",
1777                 "HCBT_ACTIVATE",
1778                 "HCBT_CLICKSKIPPED",
1779                 "HCBT_KEYSKIPPED",
1780                 "HCBT_SYSCOMMAND",
1781                 "HCBT_SETFOCUS"
1782             };
1783             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1784
1785             sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1786                      msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1787         }
1788         else if (msg->flags & winevent_hook)
1789         {
1790             sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1791                      msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1792         }
1793         else
1794         {
1795             switch (msg->message)
1796             {
1797             case WM_WINDOWPOSCHANGING:
1798             case WM_WINDOWPOSCHANGED:
1799             {
1800                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1801
1802                 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1803                           msg->descr, msg->hwnd,
1804                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1805                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1806                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1807                           get_winpos_flags(winpos->flags) );
1808
1809                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1810                  * in the high word for internal purposes
1811                  */
1812                 seq->wParam = winpos->flags & 0xffff;
1813                 /* We are not interested in the flags that don't match under XP and Win9x */
1814                 seq->wParam &= ~SWP_NOZORDER;
1815                 break;
1816             }
1817
1818             case WM_DRAWITEM:
1819             {
1820                 DRAW_ITEM_STRUCT di;
1821                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1822
1823                 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1824                          msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1825                          dis->itemID, dis->itemAction, dis->itemState);
1826
1827                 di.u.lp = 0;
1828                 di.u.item.type = dis->CtlType;
1829                 di.u.item.ctl_id = dis->CtlID;
1830                 di.u.item.item_id = dis->itemID;
1831                 di.u.item.action = dis->itemAction;
1832                 di.u.item.state = dis->itemState;
1833
1834                 seq->lParam = di.u.lp;
1835                 break;
1836             }
1837             default:
1838                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1839                 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1840                          msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1841             }
1842         }
1843     }
1844
1845     sequence_cnt++;
1846 }
1847
1848 /* try to make sure pending X events have been processed before continuing */
1849 static void flush_events(void)
1850 {
1851     MSG msg;
1852     int diff = 200;
1853     int min_timeout = 100;
1854     DWORD time = GetTickCount() + diff;
1855
1856     while (diff > 0)
1857     {
1858         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1859         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1860         diff = time - GetTickCount();
1861     }
1862 }
1863
1864 static void flush_sequence(void)
1865 {
1866     HeapFree(GetProcessHeap(), 0, sequence);
1867     sequence = 0;
1868     sequence_cnt = sequence_size = 0;
1869 }
1870
1871 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1872 {
1873     const struct recvd_message *actual = sequence;
1874     unsigned int count = 0;
1875
1876     trace_(file, line)("Failed sequence %s:\n", context );
1877     while (expected->message && actual->message)
1878     {
1879         if (actual->output[0])
1880         {
1881             if (expected->flags & hook)
1882             {
1883                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1884                                     count, expected->message, actual->output );
1885             }
1886             else if (expected->flags & winevent_hook)
1887             {
1888                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1889                                     count, expected->message, actual->output );
1890             }
1891             else
1892             {
1893                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1894                                     count, expected->message, actual->output );
1895             }
1896         }
1897
1898         if (expected->message == actual->message)
1899         {
1900             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1901                 (expected->flags & optional))
1902             {
1903                 /* don't match messages if their defwinproc status differs */
1904                 expected++;
1905             }
1906             else
1907             {
1908                 expected++;
1909                 actual++;
1910             }
1911         }
1912         /* silently drop winevent messages if there is no support for them */
1913         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1914             expected++;
1915         else
1916         {
1917             expected++;
1918             actual++;
1919         }
1920         count++;
1921     }
1922
1923     /* optional trailing messages */
1924     while (expected->message && ((expected->flags & optional) ||
1925             ((expected->flags & winevent_hook) && !hEvent_hook)))
1926     {
1927         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1928         expected++;
1929         count++;
1930     }
1931
1932     if (expected->message)
1933     {
1934         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1935         return;
1936     }
1937
1938     while (actual->message && actual->output[0])
1939     {
1940         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1941         actual++;
1942         count++;
1943     }
1944 }
1945
1946 #define ok_sequence( exp, contx, todo) \
1947         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1948
1949
1950 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1951                          const char *file, int line)
1952 {
1953     static const struct recvd_message end_of_sequence;
1954     const struct message *expected = expected_list;
1955     const struct recvd_message *actual;
1956     int failcount = 0, dump = 0;
1957     unsigned int count = 0;
1958
1959     add_message(&end_of_sequence);
1960
1961     actual = sequence;
1962
1963     while (expected->message && actual->message)
1964     {
1965         if (expected->message == actual->message)
1966         {
1967             if (expected->flags & wparam)
1968             {
1969                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1970                 {
1971                     todo_wine {
1972                         failcount ++;
1973                         if (strcmp(winetest_platform, "wine")) dump++;
1974                         ok_( file, line) (FALSE,
1975                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1976                             context, count, expected->message, expected->wParam, actual->wParam);
1977                     }
1978                 }
1979                 else
1980                 {
1981                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
1982                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1983                                      context, count, expected->message, expected->wParam, actual->wParam);
1984                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
1985                 }
1986
1987             }
1988             if (expected->flags & lparam)
1989             {
1990                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
1991                 {
1992                     todo_wine {
1993                         failcount ++;
1994                         if (strcmp(winetest_platform, "wine")) dump++;
1995                         ok_( file, line) (FALSE,
1996                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1997                             context, count, expected->message, expected->lParam, actual->lParam);
1998                     }
1999                 }
2000                 else
2001                 {
2002                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2003                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2004                                      context, count, expected->message, expected->lParam, actual->lParam);
2005                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2006                 }
2007             }
2008             if ((expected->flags & optional) &&
2009                 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2010             {
2011                 /* don't match optional messages if their defwinproc or parent status differs */
2012                 expected++;
2013                 count++;
2014                 continue;
2015             }
2016             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2017             {
2018                     todo_wine {
2019                         failcount ++;
2020                         if (strcmp(winetest_platform, "wine")) dump++;
2021                         ok_( file, line) (FALSE,
2022                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2023                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2024                     }
2025             }
2026             else
2027             {
2028                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2029                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2030                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2031                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2032             }
2033
2034             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2035                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2036                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2037             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2038
2039             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2040                 "%s: %u: the msg 0x%04x should have been %s\n",
2041                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2042             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2043
2044             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2045                 "%s: %u: the msg 0x%04x was expected in %s\n",
2046                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2047             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2048
2049             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2050                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2051                 context, count, expected->message);
2052             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2053
2054             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2055                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2056                 context, count, expected->message);
2057             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2058
2059             expected++;
2060             actual++;
2061         }
2062         /* silently drop hook messages if there is no support for them */
2063         else if ((expected->flags & optional) ||
2064                  ((expected->flags & hook) && !hCBT_hook) ||
2065                  ((expected->flags & winevent_hook) && !hEvent_hook))
2066             expected++;
2067         else if (todo)
2068         {
2069             failcount++;
2070             todo_wine {
2071                 if (strcmp(winetest_platform, "wine")) dump++;
2072                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2073                                   context, count, expected->message, actual->message);
2074             }
2075             goto done;
2076         }
2077         else
2078         {
2079             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2080                               context, count, expected->message, actual->message);
2081             dump++;
2082             expected++;
2083             actual++;
2084         }
2085         count++;
2086     }
2087
2088     /* skip all optional trailing messages */
2089     while (expected->message && ((expected->flags & optional) ||
2090                                  ((expected->flags & hook) && !hCBT_hook) ||
2091                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2092         expected++;
2093
2094     if (todo)
2095     {
2096         todo_wine {
2097             if (expected->message || actual->message) {
2098                 failcount++;
2099                 if (strcmp(winetest_platform, "wine")) dump++;
2100                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2101                                   context, count, expected->message, actual->message);
2102             }
2103         }
2104     }
2105     else
2106     {
2107         if (expected->message || actual->message)
2108         {
2109             dump++;
2110             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2111                               context, count, expected->message, actual->message);
2112         }
2113     }
2114     if( todo && !failcount) /* succeeded yet marked todo */
2115         todo_wine {
2116             if (!strcmp(winetest_platform, "wine")) dump++;
2117             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2118         }
2119
2120 done:
2121     if (dump) dump_sequence(expected_list, context, file, line);
2122     flush_sequence();
2123 }
2124
2125 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2126
2127 /******************************** MDI test **********************************/
2128
2129 /* CreateWindow for MDI frame window, initially visible */
2130 static const struct message WmCreateMDIframeSeq[] = {
2131     { HCBT_CREATEWND, hook },
2132     { WM_GETMINMAXINFO, sent },
2133     { WM_NCCREATE, sent },
2134     { WM_NCCALCSIZE, sent|wparam, 0 },
2135     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2136     { WM_CREATE, sent },
2137     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2138     { WM_NOTIFYFORMAT, sent|optional },
2139     { WM_QUERYUISTATE, sent|optional },
2140     { WM_WINDOWPOSCHANGING, sent|optional },
2141     { WM_GETMINMAXINFO, sent|optional },
2142     { WM_NCCALCSIZE, sent|optional },
2143     { WM_WINDOWPOSCHANGED, sent|optional },
2144     { WM_SHOWWINDOW, sent|wparam, 1 },
2145     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2146     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2147     { HCBT_ACTIVATE, hook },
2148     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2149     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2150     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2151     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2152     { WM_NCACTIVATE, sent },
2153     { WM_GETTEXT, sent|defwinproc|optional },
2154     { WM_ACTIVATE, sent|wparam, 1 },
2155     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2156     { HCBT_SETFOCUS, hook },
2157     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2158     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2159     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2160     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2161     /* Win9x adds SWP_NOZORDER below */
2162     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2163     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2164     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2165     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2166     { WM_MOVE, sent },
2167     { 0 }
2168 };
2169 /* DestroyWindow for MDI frame window, initially visible */
2170 static const struct message WmDestroyMDIframeSeq[] = {
2171     { HCBT_DESTROYWND, hook },
2172     { 0x0090, sent|optional },
2173     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2174     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2175     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2176     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2177     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2178     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2179     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2180     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2181     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2182     { WM_DESTROY, sent },
2183     { WM_NCDESTROY, sent },
2184     { 0 }
2185 };
2186 /* CreateWindow for MDI client window, initially visible */
2187 static const struct message WmCreateMDIclientSeq[] = {
2188     { HCBT_CREATEWND, hook },
2189     { WM_NCCREATE, sent },
2190     { WM_NCCALCSIZE, sent|wparam, 0 },
2191     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2192     { WM_CREATE, sent },
2193     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2194     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2195     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2196     { WM_MOVE, sent },
2197     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2198     { WM_SHOWWINDOW, sent|wparam, 1 },
2199     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2200     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2201     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2202     { 0 }
2203 };
2204 /* ShowWindow(SW_SHOW) for MDI client window */
2205 static const struct message WmShowMDIclientSeq[] = {
2206     { WM_SHOWWINDOW, sent|wparam, 1 },
2207     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2208     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2209     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2210     { 0 }
2211 };
2212 /* ShowWindow(SW_HIDE) for MDI client window */
2213 static const struct message WmHideMDIclientSeq[] = {
2214     { WM_SHOWWINDOW, sent|wparam, 0 },
2215     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2216     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2217     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2218     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2219     { 0 }
2220 };
2221 /* DestroyWindow for MDI client window, initially visible */
2222 static const struct message WmDestroyMDIclientSeq[] = {
2223     { HCBT_DESTROYWND, hook },
2224     { 0x0090, sent|optional },
2225     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2226     { WM_SHOWWINDOW, sent|wparam, 0 },
2227     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2228     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2229     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2230     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2231     { WM_DESTROY, sent },
2232     { WM_NCDESTROY, sent },
2233     { 0 }
2234 };
2235 /* CreateWindow for MDI child window, initially visible */
2236 static const struct message WmCreateMDIchildVisibleSeq[] = {
2237     { HCBT_CREATEWND, hook },
2238     { WM_NCCREATE, sent }, 
2239     { WM_NCCALCSIZE, sent|wparam, 0 },
2240     { WM_CREATE, sent },
2241     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2242     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2243     { WM_MOVE, sent },
2244     /* Win2k sends wparam set to
2245      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2246      * while Win9x doesn't bother to set child window id according to
2247      * CLIENTCREATESTRUCT.idFirstChild
2248      */
2249     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2250     { WM_SHOWWINDOW, sent|wparam, 1 },
2251     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2252     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2253     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2254     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2255     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2256     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2257     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2258
2259     /* Win9x: message sequence terminates here. */
2260
2261     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2262     { HCBT_SETFOCUS, hook }, /* in MDI client */
2263     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2264     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2265     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2266     { WM_SETFOCUS, sent }, /* in MDI client */
2267     { HCBT_SETFOCUS, hook },
2268     { WM_KILLFOCUS, sent }, /* in MDI client */
2269     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2270     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2271     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2272     { WM_SETFOCUS, sent|defwinproc },
2273     { WM_MDIACTIVATE, sent|defwinproc },
2274     { 0 }
2275 };
2276 /* CreateWindow for MDI child window with invisible parent */
2277 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2278     { HCBT_CREATEWND, hook },
2279     { WM_GETMINMAXINFO, sent },
2280     { WM_NCCREATE, sent }, 
2281     { WM_NCCALCSIZE, sent|wparam, 0 },
2282     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2283     { WM_CREATE, sent },
2284     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2285     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2286     { WM_MOVE, sent },
2287     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2288     { WM_SHOWWINDOW, sent|wparam, 1 },
2289     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2290     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2291     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2292     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2293
2294     /* Win9x: message sequence terminates here. */
2295
2296     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2297     { HCBT_SETFOCUS, hook }, /* in MDI client */
2298     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2299     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2300     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2301     { WM_SETFOCUS, sent }, /* in MDI client */
2302     { HCBT_SETFOCUS, hook },
2303     { WM_KILLFOCUS, sent }, /* in MDI client */
2304     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2305     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2306     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2307     { WM_SETFOCUS, sent|defwinproc },
2308     { WM_MDIACTIVATE, sent|defwinproc },
2309     { 0 }
2310 };
2311 /* DestroyWindow for MDI child window, initially visible */
2312 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2313     { HCBT_DESTROYWND, hook },
2314     /* Win2k sends wparam set to
2315      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2316      * while Win9x doesn't bother to set child window id according to
2317      * CLIENTCREATESTRUCT.idFirstChild
2318      */
2319     { 0x0090, sent|optional },
2320     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2321     { WM_SHOWWINDOW, sent|wparam, 0 },
2322     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2323     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2324     { WM_ERASEBKGND, sent|parent|optional },
2325     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2326
2327     /* { WM_DESTROY, sent }
2328      * Win9x: message sequence terminates here.
2329      */
2330
2331     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2332     { WM_KILLFOCUS, sent },
2333     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2334     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2335     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2336     { WM_SETFOCUS, sent }, /* in MDI client */
2337
2338     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2339     { WM_KILLFOCUS, sent }, /* in MDI client */
2340     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2341     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2342     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2343     { WM_SETFOCUS, sent }, /* in MDI client */
2344
2345     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2346
2347     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2348     { WM_KILLFOCUS, sent },
2349     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2350     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2351     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2352     { WM_SETFOCUS, sent }, /* in MDI client */
2353
2354     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2355     { WM_KILLFOCUS, sent }, /* in MDI client */
2356     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2357     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2358     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2359     { WM_SETFOCUS, sent }, /* in MDI client */
2360
2361     { WM_DESTROY, sent },
2362
2363     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2364     { WM_KILLFOCUS, sent },
2365     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2366     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2367     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2368     { WM_SETFOCUS, sent }, /* in MDI client */
2369
2370     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2371     { WM_KILLFOCUS, sent }, /* in MDI client */
2372     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2373     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2374     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2375     { WM_SETFOCUS, sent }, /* in MDI client */
2376
2377     { WM_NCDESTROY, sent },
2378     { 0 }
2379 };
2380 /* CreateWindow for MDI child window, initially invisible */
2381 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2382     { HCBT_CREATEWND, hook },
2383     { WM_NCCREATE, sent }, 
2384     { WM_NCCALCSIZE, sent|wparam, 0 },
2385     { WM_CREATE, sent },
2386     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2387     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2388     { WM_MOVE, sent },
2389     /* Win2k sends wparam set to
2390      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2391      * while Win9x doesn't bother to set child window id according to
2392      * CLIENTCREATESTRUCT.idFirstChild
2393      */
2394     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2395     { 0 }
2396 };
2397 /* DestroyWindow for MDI child window, initially invisible */
2398 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2399     { HCBT_DESTROYWND, hook },
2400     /* Win2k sends wparam set to
2401      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2402      * while Win9x doesn't bother to set child window id according to
2403      * CLIENTCREATESTRUCT.idFirstChild
2404      */
2405     { 0x0090, sent|optional },
2406     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2407     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2408     { WM_DESTROY, sent },
2409     { WM_NCDESTROY, sent },
2410     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2411     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2412     { 0 }
2413 };
2414 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2415 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2416     { HCBT_CREATEWND, hook },
2417     { WM_NCCREATE, sent }, 
2418     { WM_NCCALCSIZE, sent|wparam, 0 },
2419     { WM_CREATE, sent },
2420     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2421     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2422     { WM_MOVE, sent },
2423     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2424     { WM_GETMINMAXINFO, sent },
2425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2426     { WM_NCCALCSIZE, sent|wparam, 1 },
2427     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2428     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2429      /* in MDI frame */
2430     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2431     { WM_NCCALCSIZE, sent|wparam, 1 },
2432     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2433     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2434     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2435     /* Win2k sends wparam set to
2436      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2437      * while Win9x doesn't bother to set child window id according to
2438      * CLIENTCREATESTRUCT.idFirstChild
2439      */
2440     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2441     { WM_SHOWWINDOW, sent|wparam, 1 },
2442     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2443     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2444     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2445     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2446     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2447     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2448     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2449
2450     /* Win9x: message sequence terminates here. */
2451
2452     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2453     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2454     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2455     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2456     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2457     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2458     { HCBT_SETFOCUS, hook|optional },
2459     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2460     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2461     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2462     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2463     { WM_SETFOCUS, sent|defwinproc|optional },
2464     { WM_MDIACTIVATE, sent|defwinproc|optional },
2465      /* in MDI frame */
2466     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2467     { WM_NCCALCSIZE, sent|wparam, 1 },
2468     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2469     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2470     { 0 }
2471 };
2472 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2473 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2474     /* restore the 1st MDI child */
2475     { WM_SETREDRAW, sent|wparam, 0 },
2476     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2477     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2478     { WM_NCCALCSIZE, sent|wparam, 1 },
2479     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2480     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2481     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2482      /* in MDI frame */
2483     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2484     { WM_NCCALCSIZE, sent|wparam, 1 },
2485     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2486     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2487     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2488     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2489     /* create the 2nd MDI child */
2490     { HCBT_CREATEWND, hook },
2491     { WM_NCCREATE, sent }, 
2492     { WM_NCCALCSIZE, sent|wparam, 0 },
2493     { WM_CREATE, sent },
2494     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2495     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2496     { WM_MOVE, sent },
2497     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2498     { WM_GETMINMAXINFO, sent },
2499     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2500     { WM_NCCALCSIZE, sent|wparam, 1 },
2501     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2502     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2503     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2504      /* in MDI frame */
2505     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2506     { WM_NCCALCSIZE, sent|wparam, 1 },
2507     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2508     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2509     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2510     /* Win2k sends wparam set to
2511      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2512      * while Win9x doesn't bother to set child window id according to
2513      * CLIENTCREATESTRUCT.idFirstChild
2514      */
2515     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2516     { WM_SHOWWINDOW, sent|wparam, 1 },
2517     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2518     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2519     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2520     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2521     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2522     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2523
2524     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2525     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2526
2527     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2528
2529     /* Win9x: message sequence terminates here. */
2530
2531     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2532     { HCBT_SETFOCUS, hook },
2533     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2534     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2535     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2536     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2537     { WM_SETFOCUS, sent }, /* in MDI client */
2538     { HCBT_SETFOCUS, hook },
2539     { WM_KILLFOCUS, sent }, /* in MDI client */
2540     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2541     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2542     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2543     { WM_SETFOCUS, sent|defwinproc },
2544
2545     { WM_MDIACTIVATE, sent|defwinproc },
2546      /* in MDI frame */
2547     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2548     { WM_NCCALCSIZE, sent|wparam, 1 },
2549     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2550     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2551     { 0 }
2552 };
2553 /* WM_MDICREATE MDI child window, initially visible and maximized */
2554 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2555     { WM_MDICREATE, sent },
2556     { HCBT_CREATEWND, hook },
2557     { WM_NCCREATE, sent }, 
2558     { WM_NCCALCSIZE, sent|wparam, 0 },
2559     { WM_CREATE, sent },
2560     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2561     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2562     { WM_MOVE, sent },
2563     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2564     { WM_GETMINMAXINFO, sent },
2565     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2566     { WM_NCCALCSIZE, sent|wparam, 1 },
2567     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2568     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2569
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     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2576
2577     /* Win2k sends wparam set to
2578      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2579      * while Win9x doesn't bother to set child window id according to
2580      * CLIENTCREATESTRUCT.idFirstChild
2581      */
2582     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2583     { WM_SHOWWINDOW, sent|wparam, 1 },
2584     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2585
2586     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2587
2588     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2589     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2591
2592     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2593     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2594
2595     /* Win9x: message sequence terminates here. */
2596
2597     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2598     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2599     { HCBT_SETFOCUS, hook }, /* in MDI client */
2600     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2601     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2602     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2603     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2604     { HCBT_SETFOCUS, hook|optional },
2605     { WM_KILLFOCUS, sent }, /* in MDI client */
2606     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2607     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2608     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2609     { WM_SETFOCUS, sent|defwinproc },
2610
2611     { WM_MDIACTIVATE, sent|defwinproc },
2612
2613      /* in MDI child */
2614     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2615     { WM_NCCALCSIZE, sent|wparam, 1 },
2616     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2617     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2618
2619      /* in MDI frame */
2620     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2621     { WM_NCCALCSIZE, sent|wparam, 1 },
2622     { 0x0093, sent|defwinproc|optional },
2623     { 0x0093, sent|defwinproc|optional },
2624     { 0x0093, sent|defwinproc|optional },
2625     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2626     { WM_MOVE, sent|defwinproc },
2627     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2628
2629      /* in MDI client */
2630     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2631     { WM_NCCALCSIZE, sent|wparam, 1 },
2632     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2633     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2634
2635      /* in MDI child */
2636     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2637     { WM_NCCALCSIZE, sent|wparam, 1 },
2638     { 0x0093, sent|optional },
2639     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2640     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2641
2642     { 0x0093, sent|optional },
2643     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2644     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2645     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2646     { 0x0093, sent|defwinproc|optional },
2647     { 0x0093, sent|defwinproc|optional },
2648     { 0x0093, sent|defwinproc|optional },
2649     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2650     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2651
2652     { 0 }
2653 };
2654 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2655 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2656     { HCBT_CREATEWND, hook },
2657     { WM_GETMINMAXINFO, sent },
2658     { WM_NCCREATE, sent }, 
2659     { WM_NCCALCSIZE, sent|wparam, 0 },
2660     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2661     { WM_CREATE, sent },
2662     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2663     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2664     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2665     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2666     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2667     { WM_MOVE, sent },
2668     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2669     { WM_GETMINMAXINFO, sent },
2670     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2671     { WM_GETMINMAXINFO, sent|defwinproc },
2672     { WM_NCCALCSIZE, sent|wparam, 1 },
2673     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2674     { WM_MOVE, sent|defwinproc },
2675     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2676      /* in MDI frame */
2677     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2678     { WM_NCCALCSIZE, sent|wparam, 1 },
2679     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2680     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2681     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2682     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2683     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2684     /* Win2k sends wparam set to
2685      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2686      * while Win9x doesn't bother to set child window id according to
2687      * CLIENTCREATESTRUCT.idFirstChild
2688      */
2689     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2690     { 0 }
2691 };
2692 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2693 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2694     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2695     { HCBT_SYSCOMMAND, hook },
2696     { WM_CLOSE, sent|defwinproc },
2697     { WM_MDIDESTROY, sent }, /* in MDI client */
2698
2699     /* bring the 1st MDI child to top */
2700     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2701     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2702
2703     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2704
2705     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2706     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2707     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2708
2709     /* maximize the 1st MDI child */
2710     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2711     { WM_GETMINMAXINFO, sent|defwinproc },
2712     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2713     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2714     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2715     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2716     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2717
2718     /* restore the 2nd MDI child */
2719     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2720     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2721     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2722     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2723
2724     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2725
2726     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2727     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2728
2729     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2730
2731     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2732      /* in MDI frame */
2733     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2734     { WM_NCCALCSIZE, sent|wparam, 1 },
2735     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2736     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2737     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2738
2739     /* bring the 1st MDI child to top */
2740     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2741     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2742     { HCBT_SETFOCUS, hook },
2743     { WM_KILLFOCUS, sent|defwinproc },
2744     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2745     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2746     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2747     { WM_SETFOCUS, sent }, /* in MDI client */
2748     { HCBT_SETFOCUS, hook },
2749     { WM_KILLFOCUS, sent }, /* in MDI client */
2750     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2751     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2752     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2753     { WM_SETFOCUS, sent|defwinproc },
2754     { WM_MDIACTIVATE, sent|defwinproc },
2755     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2756
2757     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2758     { WM_SHOWWINDOW, sent|wparam, 1 },
2759     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2760     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2761     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2762     { WM_MDIREFRESHMENU, sent },
2763
2764     { HCBT_DESTROYWND, hook },
2765     /* Win2k sends wparam set to
2766      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2767      * while Win9x doesn't bother to set child window id according to
2768      * CLIENTCREATESTRUCT.idFirstChild
2769      */
2770     { 0x0090, sent|defwinproc|optional },
2771     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2772     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2773     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2774     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2775     { WM_ERASEBKGND, sent|parent|optional },
2776     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2777
2778     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2779     { WM_DESTROY, sent|defwinproc },
2780     { WM_NCDESTROY, sent|defwinproc },
2781     { 0 }
2782 };
2783 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2784 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2785     { WM_MDIDESTROY, sent }, /* in MDI client */
2786     { WM_SHOWWINDOW, sent|wparam, 0 },
2787     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2788     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2789     { WM_ERASEBKGND, sent|parent|optional },
2790     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2791
2792     { HCBT_SETFOCUS, hook },
2793     { WM_KILLFOCUS, sent },
2794     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2795     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2796     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2797     { WM_SETFOCUS, sent }, /* in MDI client */
2798     { HCBT_SETFOCUS, hook },
2799     { WM_KILLFOCUS, sent }, /* in MDI client */
2800     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2801     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2802     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2803     { WM_SETFOCUS, sent },
2804
2805      /* in MDI child */
2806     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2807     { WM_NCCALCSIZE, sent|wparam, 1 },
2808     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2809     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2810
2811      /* in MDI frame */
2812     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2813     { WM_NCCALCSIZE, sent|wparam, 1 },
2814     { 0x0093, sent|defwinproc|optional },
2815     { 0x0093, sent|defwinproc|optional },
2816     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2817     { WM_MOVE, sent|defwinproc },
2818     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2819
2820      /* in MDI client */
2821     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2822     { WM_NCCALCSIZE, sent|wparam, 1 },
2823     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2824     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2825
2826      /* in MDI child */
2827     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2828     { WM_NCCALCSIZE, sent|wparam, 1 },
2829     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2830     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2831
2832      /* in MDI child */
2833     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2834     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2835     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2836     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2837
2838      /* in MDI frame */
2839     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2840     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2841     { 0x0093, sent|defwinproc|optional },
2842     { 0x0093, sent|defwinproc|optional },
2843     { 0x0093, sent|defwinproc|optional },
2844     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2845     { WM_MOVE, sent|defwinproc },
2846     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2847
2848      /* in MDI client */
2849     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2850     { WM_NCCALCSIZE, sent|wparam, 1 },
2851     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2852     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2853
2854      /* in MDI child */
2855     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2856     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2857     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2858     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2859     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2860     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2861
2862     { 0x0093, sent|defwinproc|optional },
2863     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2864     { 0x0093, sent|defwinproc|optional },
2865     { 0x0093, sent|defwinproc|optional },
2866     { 0x0093, sent|defwinproc|optional },
2867     { 0x0093, sent|optional },
2868
2869     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2870     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2871     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2872     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2874
2875      /* in MDI frame */
2876     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2877     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2878     { 0x0093, sent|defwinproc|optional },
2879     { 0x0093, sent|defwinproc|optional },
2880     { 0x0093, sent|defwinproc|optional },
2881     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2882     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2883     { 0x0093, sent|optional },
2884
2885     { WM_NCACTIVATE, sent|wparam, 0 },
2886     { WM_MDIACTIVATE, sent },
2887
2888     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2889     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2890     { WM_NCCALCSIZE, sent|wparam, 1 },
2891
2892     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2893
2894     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2895     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2896     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2897
2898      /* in MDI child */
2899     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2900     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2901     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2902     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2903
2904      /* in MDI frame */
2905     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2906     { WM_NCCALCSIZE, sent|wparam, 1 },
2907     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2908     { WM_MOVE, sent|defwinproc },
2909     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2910
2911      /* in MDI client */
2912     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2913     { WM_NCCALCSIZE, sent|wparam, 1 },
2914     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2915     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2916     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2917     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2918     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2919     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2920     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2921
2922     { HCBT_SETFOCUS, hook },
2923     { WM_KILLFOCUS, sent },
2924     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2925     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2926     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2927     { WM_SETFOCUS, sent }, /* in MDI client */
2928
2929     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2930
2931     { HCBT_DESTROYWND, hook },
2932     /* Win2k sends wparam set to
2933      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2934      * while Win9x doesn't bother to set child window id according to
2935      * CLIENTCREATESTRUCT.idFirstChild
2936      */
2937     { 0x0090, sent|optional },
2938     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2939
2940     { WM_SHOWWINDOW, sent|wparam, 0 },
2941     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2942     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2943     { WM_ERASEBKGND, sent|parent|optional },
2944     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2945
2946     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2947     { WM_DESTROY, sent },
2948     { WM_NCDESTROY, sent },
2949     { 0 }
2950 };
2951 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2952 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2953     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2954     { WM_GETMINMAXINFO, sent },
2955     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2956     { WM_NCCALCSIZE, sent|wparam, 1 },
2957     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2958     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2959
2960     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2961     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2962     { HCBT_SETFOCUS, hook|optional },
2963     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2964     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2965     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2966     { HCBT_SETFOCUS, hook|optional },
2967     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2968     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2969     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2970     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2971     { WM_SETFOCUS, sent|optional|defwinproc },
2972     { WM_MDIACTIVATE, sent|optional|defwinproc },
2973     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2974     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2975      /* in MDI frame */
2976     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2977     { WM_NCCALCSIZE, sent|wparam, 1 },
2978     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2979     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2980     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2981     { 0 }
2982 };
2983 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2984 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2985     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2986     { WM_GETMINMAXINFO, sent },
2987     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2988     { WM_GETMINMAXINFO, sent|defwinproc },
2989     { WM_NCCALCSIZE, sent|wparam, 1 },
2990     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2991     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2992
2993     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2994     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2995     { HCBT_SETFOCUS, hook|optional },
2996     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2997     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2998     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2999     { HCBT_SETFOCUS, hook|optional },
3000     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3001     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3002     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3003     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3004     { WM_SETFOCUS, sent|defwinproc|optional },
3005     { WM_MDIACTIVATE, sent|defwinproc|optional },
3006     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3007     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3008     { 0 }
3009 };
3010 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3011 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3012     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3013     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3014     { WM_GETMINMAXINFO, sent },
3015     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3016     { WM_GETMINMAXINFO, sent|defwinproc },
3017     { WM_NCCALCSIZE, sent|wparam, 1 },
3018     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3019     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3020     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3021     { WM_MOVE, sent|defwinproc },
3022     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3023
3024     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3025     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3026     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3027     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3028     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3029     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3030      /* in MDI frame */
3031     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3032     { WM_NCCALCSIZE, sent|wparam, 1 },
3033     { 0x0093, sent|defwinproc|optional },
3034     { 0x0094, sent|defwinproc|optional },
3035     { 0x0094, sent|defwinproc|optional },
3036     { 0x0094, sent|defwinproc|optional },
3037     { 0x0094, sent|defwinproc|optional },
3038     { 0x0093, sent|defwinproc|optional },
3039     { 0x0093, sent|defwinproc|optional },
3040     { 0x0091, sent|defwinproc|optional },
3041     { 0x0092, sent|defwinproc|optional },
3042     { 0x0092, sent|defwinproc|optional },
3043     { 0x0092, sent|defwinproc|optional },
3044     { 0x0092, sent|defwinproc|optional },
3045     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3046     { WM_MOVE, sent|defwinproc },
3047     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3048     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3049      /* in MDI client */
3050     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3051     { WM_NCCALCSIZE, sent|wparam, 1 },
3052     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3053     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3054      /* in MDI child */
3055     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3056     { WM_GETMINMAXINFO, sent|defwinproc },
3057     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3058     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3059     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3060     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3061     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3062     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3063     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3064     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3065      /* in MDI frame */
3066     { 0x0093, sent|optional },
3067     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3068     { 0x0093, sent|defwinproc|optional },
3069     { 0x0093, sent|defwinproc|optional },
3070     { 0x0093, sent|defwinproc|optional },
3071     { 0x0091, sent|defwinproc|optional },
3072     { 0x0092, sent|defwinproc|optional },
3073     { 0x0092, sent|defwinproc|optional },
3074     { 0x0092, sent|defwinproc|optional },
3075     { 0x0092, sent|defwinproc|optional },
3076     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3077     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3078     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3079     { 0 }
3080 };
3081 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3082 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3083     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3084     { WM_GETMINMAXINFO, sent },
3085     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3086     { WM_NCCALCSIZE, sent|wparam, 1 },
3087     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3088     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3089     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3090      /* in MDI frame */
3091     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3092     { WM_NCCALCSIZE, sent|wparam, 1 },
3093     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3094     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3095     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3096     { 0 }
3097 };
3098 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3099 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3100     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3101     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3102     { WM_NCCALCSIZE, sent|wparam, 1 },
3103     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3104     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3105     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3106      /* in MDI frame */
3107     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3108     { WM_NCCALCSIZE, sent|wparam, 1 },
3109     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3110     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3111     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3112     { 0 }
3113 };
3114 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3115 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3116     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3117     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3118     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3119     { WM_NCCALCSIZE, sent|wparam, 1 },
3120     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3121     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3122     { WM_MOVE, sent|defwinproc },
3123     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3124     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3125     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3126     { HCBT_SETFOCUS, hook },
3127     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3128     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3129     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3130     { WM_SETFOCUS, sent },
3131     { 0 }
3132 };
3133 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3134 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3135     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3136     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3137     { WM_NCCALCSIZE, sent|wparam, 1 },
3138     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3139     { WM_MOVE, sent|defwinproc },
3140     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3141     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3142     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3143     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3144     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3145     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3146     { 0 }
3147 };
3148 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3149 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3150     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3151     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3152     { WM_NCCALCSIZE, sent|wparam, 1 },
3153     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3154     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3155     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3156     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3157      /* in MDI frame */
3158     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3159     { WM_NCCALCSIZE, sent|wparam, 1 },
3160     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3161     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3162     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3163     { 0 }
3164 };
3165
3166 static HWND mdi_client;
3167 static WNDPROC old_mdi_client_proc;
3168
3169 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3170 {
3171     struct recvd_message msg;
3172
3173     /* do not log painting messages */
3174     if (message != WM_PAINT &&
3175         message != WM_NCPAINT &&
3176         message != WM_SYNCPAINT &&
3177         message != WM_ERASEBKGND &&
3178         message != WM_NCHITTEST &&
3179         message != WM_GETTEXT &&
3180         message != WM_MDIGETACTIVE &&
3181         message != WM_GETICON &&
3182         message != WM_GETOBJECT &&
3183         message != WM_DEVICECHANGE)
3184     {
3185         msg.hwnd = hwnd;
3186         msg.message = message;
3187         msg.flags = sent|wparam|lparam;
3188         msg.wParam = wParam;
3189         msg.lParam = lParam;
3190         msg.descr = "mdi client";
3191         add_message(&msg);
3192     }
3193
3194     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3195 }
3196
3197 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3198 {
3199     static long defwndproc_counter = 0;
3200     LRESULT ret;
3201     struct recvd_message msg;
3202
3203     /* do not log painting messages */
3204     if (message != WM_PAINT &&
3205         message != WM_NCPAINT &&
3206         message != WM_SYNCPAINT &&
3207         message != WM_ERASEBKGND &&
3208         message != WM_NCHITTEST &&
3209         message != WM_GETTEXT &&
3210         message != WM_GETICON &&
3211         message != WM_GETOBJECT &&
3212         message != WM_DEVICECHANGE)
3213     {
3214         switch (message)
3215         {
3216             case WM_MDIACTIVATE:
3217             {
3218                 HWND active, client = GetParent(hwnd);
3219
3220                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3221
3222                 if (hwnd == (HWND)lParam) /* if we are being activated */
3223                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3224                 else
3225                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3226                 break;
3227             }
3228         }
3229
3230         msg.hwnd = hwnd;
3231         msg.message = message;
3232         msg.flags = sent|wparam|lparam;
3233         if (defwndproc_counter) msg.flags |= defwinproc;
3234         msg.wParam = wParam;
3235         msg.lParam = lParam;
3236         msg.descr = "mdi child";
3237         add_message(&msg);
3238     }
3239
3240     defwndproc_counter++;
3241     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3242     defwndproc_counter--;
3243
3244     return ret;
3245 }
3246
3247 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3248 {
3249     static long defwndproc_counter = 0;
3250     LRESULT ret;
3251     struct recvd_message msg;
3252
3253     /* do not log painting messages */
3254     if (message != WM_PAINT &&
3255         message != WM_NCPAINT &&
3256         message != WM_SYNCPAINT &&
3257         message != WM_ERASEBKGND &&
3258         message != WM_NCHITTEST &&
3259         message != WM_GETTEXT &&
3260         message != WM_GETICON &&
3261         message != WM_GETOBJECT &&
3262         message != WM_DEVICECHANGE)
3263     {
3264         msg.hwnd = hwnd;
3265         msg.message = message;
3266         msg.flags = sent|wparam|lparam;
3267         if (defwndproc_counter) msg.flags |= defwinproc;
3268         msg.wParam = wParam;
3269         msg.lParam = lParam;
3270         msg.descr = "mdi frame";
3271         add_message(&msg);
3272     }
3273
3274     defwndproc_counter++;
3275     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3276     defwndproc_counter--;
3277
3278     return ret;
3279 }
3280
3281 static BOOL mdi_RegisterWindowClasses(void)
3282 {
3283     WNDCLASSA cls;
3284
3285     cls.style = 0;
3286     cls.lpfnWndProc = mdi_frame_wnd_proc;
3287     cls.cbClsExtra = 0;
3288     cls.cbWndExtra = 0;
3289     cls.hInstance = GetModuleHandleA(0);
3290     cls.hIcon = 0;
3291     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3292     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3293     cls.lpszMenuName = NULL;
3294     cls.lpszClassName = "MDI_frame_class";
3295     if (!RegisterClassA(&cls)) return FALSE;
3296
3297     cls.lpfnWndProc = mdi_child_wnd_proc;
3298     cls.lpszClassName = "MDI_child_class";
3299     if (!RegisterClassA(&cls)) return FALSE;
3300
3301     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3302     old_mdi_client_proc = cls.lpfnWndProc;
3303     cls.hInstance = GetModuleHandleA(0);
3304     cls.lpfnWndProc = mdi_client_hook_proc;
3305     cls.lpszClassName = "MDI_client_class";
3306     if (!RegisterClassA(&cls)) assert(0);
3307
3308     return TRUE;
3309 }
3310
3311 static void test_mdi_messages(void)
3312 {
3313     MDICREATESTRUCTA mdi_cs;
3314     CLIENTCREATESTRUCT client_cs;
3315     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3316     BOOL zoomed;
3317     HMENU hMenu = CreateMenu();
3318
3319     assert(mdi_RegisterWindowClasses());
3320
3321     flush_sequence();
3322
3323     trace("creating MDI frame window\n");
3324     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3325                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3326                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3327                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3328                                 GetDesktopWindow(), hMenu,
3329                                 GetModuleHandleA(0), NULL);
3330     assert(mdi_frame);
3331     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3332
3333     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3334     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3335
3336     trace("creating MDI client window\n");
3337     client_cs.hWindowMenu = 0;
3338     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3339     mdi_client = CreateWindowExA(0, "MDI_client_class",
3340                                  NULL,
3341                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3342                                  0, 0, 0, 0,
3343                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3344     assert(mdi_client);
3345     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3346
3347     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3348     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3349
3350     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3351     ok(!active_child, "wrong active MDI child %p\n", active_child);
3352     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3353
3354     SetFocus(0);
3355     flush_sequence();
3356
3357     trace("creating invisible MDI child window\n");
3358     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3359                                 WS_CHILD,
3360                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3361                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3362     assert(mdi_child);
3363
3364     flush_sequence();
3365     ShowWindow(mdi_child, SW_SHOWNORMAL);
3366     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3367
3368     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3369     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3370
3371     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3372     ok(GetFocus() == 0, "wrong focus window %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     ShowWindow(mdi_child, SW_HIDE);
3379     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3380     flush_sequence();
3381
3382     ShowWindow(mdi_child, SW_SHOW);
3383     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3384
3385     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3386     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3387
3388     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3389     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3390
3391     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3392     ok(!active_child, "wrong active MDI child %p\n", active_child);
3393     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3394
3395     DestroyWindow(mdi_child);
3396     flush_sequence();
3397
3398     trace("creating visible MDI child window\n");
3399     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3400                                 WS_CHILD | WS_VISIBLE,
3401                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3402                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3403     assert(mdi_child);
3404     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3405
3406     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3407     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3408
3409     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3410     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3411
3412     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3413     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3414     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3415     flush_sequence();
3416
3417     DestroyWindow(mdi_child);
3418     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3419
3420     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3421     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3422
3423     /* Win2k: MDI client still returns a just destroyed child as active
3424      * Win9x: MDI client returns 0
3425      */
3426     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3427     ok(active_child == mdi_child || /* win2k */
3428        !active_child, /* win9x */
3429        "wrong active MDI child %p\n", active_child);
3430     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3431
3432     flush_sequence();
3433
3434     trace("creating invisible MDI child window\n");
3435     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3436                                 WS_CHILD,
3437                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3438                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3439     assert(mdi_child2);
3440     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3441
3442     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3443     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3444
3445     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3446     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3447
3448     /* Win2k: MDI client still returns a just destroyed child as active
3449      * Win9x: MDI client returns mdi_child2
3450      */
3451     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3452     ok(active_child == mdi_child || /* win2k */
3453        active_child == mdi_child2, /* win9x */
3454        "wrong active MDI child %p\n", active_child);
3455     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3456     flush_sequence();
3457
3458     ShowWindow(mdi_child2, SW_MAXIMIZE);
3459     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3460
3461     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3462     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3463
3464     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3465     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3466     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3467     flush_sequence();
3468
3469     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3470     ok(GetFocus() == mdi_child2 || /* win2k */
3471        GetFocus() == 0, /* win9x */
3472        "wrong focus window %p\n", GetFocus());
3473
3474     SetFocus(0);
3475     flush_sequence();
3476
3477     ShowWindow(mdi_child2, SW_HIDE);
3478     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3479
3480     ShowWindow(mdi_child2, SW_RESTORE);
3481     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3482     flush_sequence();
3483
3484     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3485     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3486
3487     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3488     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3489     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3490     flush_sequence();
3491
3492     SetFocus(0);
3493     flush_sequence();
3494
3495     ShowWindow(mdi_child2, SW_HIDE);
3496     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3497
3498     ShowWindow(mdi_child2, SW_SHOW);
3499     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3500
3501     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3502     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3503
3504     ShowWindow(mdi_child2, SW_MAXIMIZE);
3505     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3506
3507     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3508     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3509
3510     ShowWindow(mdi_child2, SW_RESTORE);
3511     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3512
3513     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3514     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3515
3516     ShowWindow(mdi_child2, SW_MINIMIZE);
3517     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3518
3519     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3520     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3521
3522     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3523     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3524     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3525     flush_sequence();
3526
3527     ShowWindow(mdi_child2, SW_RESTORE);
3528     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3529
3530     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3531     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3532
3533     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3534     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3535     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3536     flush_sequence();
3537
3538     SetFocus(0);
3539     flush_sequence();
3540
3541     ShowWindow(mdi_child2, SW_HIDE);
3542     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3543
3544     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3545     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3546
3547     DestroyWindow(mdi_child2);
3548     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3549
3550     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3551     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3552
3553     /* test for maximized MDI children */
3554     trace("creating maximized visible MDI child window 1\n");
3555     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3556                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3557                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3558                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3559     assert(mdi_child);
3560     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3561     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3562
3563     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3564     ok(GetFocus() == mdi_child || /* win2k */
3565        GetFocus() == 0, /* win9x */
3566        "wrong focus window %p\n", GetFocus());
3567
3568     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3569     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3570     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3571     flush_sequence();
3572
3573     trace("creating maximized visible MDI child window 2\n");
3574     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3575                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3576                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3577                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3578     assert(mdi_child2);
3579     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3580     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3581     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3582
3583     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3584     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3585
3586     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3587     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3588     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3589     flush_sequence();
3590
3591     trace("destroying maximized visible MDI child window 2\n");
3592     DestroyWindow(mdi_child2);
3593     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3594
3595     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3596
3597     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3598     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3599
3600     /* Win2k: MDI client still returns a just destroyed child as active
3601      * Win9x: MDI client returns 0
3602      */
3603     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3604     ok(active_child == mdi_child2 || /* win2k */
3605        !active_child, /* win9x */
3606        "wrong active MDI child %p\n", active_child);
3607     flush_sequence();
3608
3609     ShowWindow(mdi_child, SW_MAXIMIZE);
3610     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3611     flush_sequence();
3612
3613     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3614     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3615
3616     trace("re-creating maximized visible MDI child window 2\n");
3617     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3618                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3619                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3620                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3621     assert(mdi_child2);
3622     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3623     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3624     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3625
3626     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3627     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3628
3629     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3630     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3631     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3632     flush_sequence();
3633
3634     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3635     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3636     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3637
3638     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3639     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3640     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3641
3642     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3643     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3644     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3645     flush_sequence();
3646
3647     DestroyWindow(mdi_child);
3648     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3649
3650     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3651     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3652
3653     /* Win2k: MDI client still returns a just destroyed child as active
3654      * Win9x: MDI client returns 0
3655      */
3656     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3657     ok(active_child == mdi_child || /* win2k */
3658        !active_child, /* win9x */
3659        "wrong active MDI child %p\n", active_child);
3660     flush_sequence();
3661
3662     trace("creating maximized invisible MDI child window\n");
3663     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3664                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3665                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3666                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3667     assert(mdi_child2);
3668     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3669     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3670     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3671     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3672
3673     /* Win2k: MDI client still returns a just destroyed child as active
3674      * Win9x: MDI client returns 0
3675      */
3676     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3677     ok(active_child == mdi_child || /* win2k */
3678        !active_child || active_child == mdi_child2, /* win9x */
3679        "wrong active MDI child %p\n", active_child);
3680     flush_sequence();
3681
3682     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3683     ShowWindow(mdi_child2, SW_MAXIMIZE);
3684     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3685     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3686     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3687     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3688
3689     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3690     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3691     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3692     flush_sequence();
3693
3694     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3695     flush_sequence();
3696
3697     /* end of test for maximized MDI children */
3698     SetFocus(0);
3699     flush_sequence();
3700     trace("creating maximized visible MDI child window 1(Switch test)\n");
3701     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3702                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3703                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3704                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3705     assert(mdi_child);
3706     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3707     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3708
3709     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3710     ok(GetFocus() == mdi_child || /* win2k */
3711        GetFocus() == 0, /* win9x */
3712        "wrong focus window %p(Switch test)\n", GetFocus());
3713
3714     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3715     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3716     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3717     flush_sequence();
3718
3719     trace("creating maximized visible MDI child window 2(Switch test)\n");
3720     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3721                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3722                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3723                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3724     assert(mdi_child2);
3725     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3726
3727     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3728     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3729
3730     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3731     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3732
3733     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3734     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3735     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3736     flush_sequence();
3737
3738     trace("Switch child window.\n");
3739     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3740     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3741     trace("end of test for switch maximized MDI children\n");
3742     flush_sequence();
3743
3744     /* Prepare for switching test of not maximized MDI children  */
3745     ShowWindow( mdi_child, SW_NORMAL );
3746     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3747     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3748     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3749     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3750     flush_sequence();
3751
3752     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3753     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3754     trace("end of test for switch not maximized MDI children\n");
3755     flush_sequence();
3756
3757     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3758     flush_sequence();
3759
3760     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3761     flush_sequence();
3762
3763     SetFocus(0);
3764     flush_sequence();
3765     /* end of tests for switch maximized/not maximized MDI children */
3766
3767     mdi_cs.szClass = "MDI_child_Class";
3768     mdi_cs.szTitle = "MDI child";
3769     mdi_cs.hOwner = GetModuleHandleA(0);
3770     mdi_cs.x = 0;
3771     mdi_cs.y = 0;
3772     mdi_cs.cx = CW_USEDEFAULT;
3773     mdi_cs.cy = CW_USEDEFAULT;
3774     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3775     mdi_cs.lParam = 0;
3776     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3777     ok(mdi_child != 0, "MDI child creation failed\n");
3778     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3779
3780     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3781
3782     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3783     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3784
3785     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3786     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3787     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3788
3789     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3790     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3791     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3792     flush_sequence();
3793
3794     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3795     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3796
3797     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3798     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3799     ok(!active_child, "wrong active MDI child %p\n", active_child);
3800
3801     SetFocus(0);
3802     flush_sequence();
3803
3804     DestroyWindow(mdi_client);
3805     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3806
3807     /* test maximization of MDI child with invisible parent */
3808     client_cs.hWindowMenu = 0;
3809     mdi_client = CreateWindow("MDI_client_class",
3810                                  NULL,
3811                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3812                                  0, 0, 660, 430,
3813                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3814     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3815
3816     ShowWindow(mdi_client, SW_HIDE);
3817     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3818
3819     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3820                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3821                                 0, 0, 650, 440,
3822                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3823     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3824
3825     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3826     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3827     zoomed = IsZoomed(mdi_child);
3828     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3829     
3830     ShowWindow(mdi_client, SW_SHOW);
3831     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3832
3833     DestroyWindow(mdi_child);
3834     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3835
3836     /* end of test for maximization of MDI child with invisible parent */
3837
3838     DestroyWindow(mdi_client);
3839     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3840
3841     DestroyWindow(mdi_frame);
3842     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3843 }
3844 /************************* End of MDI test **********************************/
3845
3846 static void test_WM_SETREDRAW(HWND hwnd)
3847 {
3848     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3849
3850     flush_events();
3851     flush_sequence();
3852
3853     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3854     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3855
3856     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3857     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3858
3859     flush_sequence();
3860     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3861     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3862
3863     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3864     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3865
3866     /* restore original WS_VISIBLE state */
3867     SetWindowLongA(hwnd, GWL_STYLE, style);
3868
3869     flush_events();
3870     flush_sequence();
3871 }
3872
3873 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3874 {
3875     struct recvd_message msg;
3876
3877     switch (message)
3878     {
3879         /* ignore */
3880         case WM_GETICON:
3881         case WM_GETOBJECT:
3882         case WM_MOUSEMOVE:
3883         case WM_NCMOUSEMOVE:
3884         case WM_NCMOUSELEAVE:
3885         case WM_SETCURSOR:
3886         case WM_DEVICECHANGE:
3887             return 0;
3888         case WM_NCHITTEST:
3889             return HTCLIENT;
3890     }
3891
3892     msg.hwnd = hwnd;
3893     msg.message = message;
3894     msg.flags = sent|wparam|lparam;
3895     msg.wParam = wParam;
3896     msg.lParam = lParam;
3897     msg.descr = "dialog";
3898     add_message(&msg);
3899
3900     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3901     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3902     return 0;
3903 }
3904
3905 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3906 {
3907     DWORD style, exstyle;
3908     INT xmin, xmax;
3909     BOOL ret;
3910
3911     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3912     style = GetWindowLongA(hwnd, GWL_STYLE);
3913     /* do not be confused by WS_DLGFRAME set */
3914     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3915
3916     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3917     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3918
3919     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3920     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3921     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3922         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3923     else
3924         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3925
3926     style = GetWindowLongA(hwnd, GWL_STYLE);
3927     if (set) ok(style & set, "style %08x should be set\n", set);
3928     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3929
3930     /* a subsequent call should do nothing */
3931     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3932     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3933     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3934
3935     xmin = 0xdeadbeef;
3936     xmax = 0xdeadbeef;
3937     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3938     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3939     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3940     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3941     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3942     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3943 }
3944
3945 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3946 {
3947     DWORD style, exstyle;
3948     SCROLLINFO si;
3949     BOOL ret;
3950
3951     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3952     style = GetWindowLongA(hwnd, GWL_STYLE);
3953     /* do not be confused by WS_DLGFRAME set */
3954     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3955
3956     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3957     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3958
3959     si.cbSize = sizeof(si);
3960     si.fMask = SIF_RANGE;
3961     si.nMin = min;
3962     si.nMax = max;
3963     SetScrollInfo(hwnd, ctl, &si, TRUE);
3964     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3965         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3966     else
3967         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3968
3969     style = GetWindowLongA(hwnd, GWL_STYLE);
3970     if (set) ok(style & set, "style %08x should be set\n", set);
3971     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3972
3973     /* a subsequent call should do nothing */
3974     SetScrollInfo(hwnd, ctl, &si, TRUE);
3975     if (style & WS_HSCROLL)
3976         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3977     else if (style & WS_VSCROLL)
3978         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3979     else
3980         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3981
3982     si.fMask = SIF_PAGE;
3983     si.nPage = 5;
3984     SetScrollInfo(hwnd, ctl, &si, FALSE);
3985     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3986
3987     si.fMask = SIF_POS;
3988     si.nPos = max - 1;
3989     SetScrollInfo(hwnd, ctl, &si, FALSE);
3990     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3991
3992     si.fMask = SIF_RANGE;
3993     si.nMin = 0xdeadbeef;
3994     si.nMax = 0xdeadbeef;
3995     ret = GetScrollInfo(hwnd, ctl, &si);
3996     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3997     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3998     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3999     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4000 }
4001
4002 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4003 static void test_scroll_messages(HWND hwnd)
4004 {
4005     SCROLLINFO si;
4006     INT min, max;
4007     BOOL ret;
4008
4009     flush_events();
4010     flush_sequence();
4011
4012     min = 0xdeadbeef;
4013     max = 0xdeadbeef;
4014     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4015     ok( ret, "GetScrollRange error %d\n", GetLastError());
4016     if (sequence->message != WmGetScrollRangeSeq[0].message)
4017         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4018     /* values of min and max are undefined */
4019     flush_sequence();
4020
4021     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4022     ok( ret, "SetScrollRange error %d\n", GetLastError());
4023     if (sequence->message != WmSetScrollRangeSeq[0].message)
4024         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4025     flush_sequence();
4026
4027     min = 0xdeadbeef;
4028     max = 0xdeadbeef;
4029     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4030     ok( ret, "GetScrollRange error %d\n", GetLastError());
4031     if (sequence->message != WmGetScrollRangeSeq[0].message)
4032         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4033     /* values of min and max are undefined */
4034     flush_sequence();
4035
4036     si.cbSize = sizeof(si);
4037     si.fMask = SIF_RANGE;
4038     si.nMin = 20;
4039     si.nMax = 160;
4040     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4041     if (sequence->message != WmSetScrollRangeSeq[0].message)
4042         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4043     flush_sequence();
4044
4045     si.fMask = SIF_PAGE;
4046     si.nPage = 10;
4047     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4048     if (sequence->message != WmSetScrollRangeSeq[0].message)
4049         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4050     flush_sequence();
4051
4052     si.fMask = SIF_POS;
4053     si.nPos = 20;
4054     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4055     if (sequence->message != WmSetScrollRangeSeq[0].message)
4056         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4057     flush_sequence();
4058
4059     si.fMask = SIF_RANGE;
4060     si.nMin = 0xdeadbeef;
4061     si.nMax = 0xdeadbeef;
4062     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4063     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4064     if (sequence->message != WmGetScrollInfoSeq[0].message)
4065         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4066     /* values of min and max are undefined */
4067     flush_sequence();
4068
4069     /* set WS_HSCROLL */
4070     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4071     /* clear WS_HSCROLL */
4072     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4073
4074     /* set WS_HSCROLL */
4075     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4076     /* clear WS_HSCROLL */
4077     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4078
4079     /* set WS_VSCROLL */
4080     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4081     /* clear WS_VSCROLL */
4082     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4083
4084     /* set WS_VSCROLL */
4085     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4086     /* clear WS_VSCROLL */
4087     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4088 }
4089
4090 static void test_showwindow(void)
4091 {
4092     HWND hwnd, hchild;
4093     RECT rc;
4094
4095     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4096                            100, 100, 200, 200, 0, 0, 0, NULL);
4097     ok (hwnd != 0, "Failed to create overlapped window\n");
4098     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4099                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4100     ok (hchild != 0, "Failed to create child\n");
4101     flush_sequence();
4102
4103     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4104     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4105     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4106     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4107
4108     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4109     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4110     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4111     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4112     /* back to invisible */
4113     ShowWindow(hchild, SW_HIDE);
4114     ShowWindow(hwnd, SW_HIDE);
4115     flush_sequence();
4116     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4117     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4118     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4119     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4120     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4121     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4122     flush_sequence();
4123     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4124     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4125     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4126     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4127     ShowWindow( hwnd, SW_SHOW);
4128     flush_sequence();
4129     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4130     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4131     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4132
4133     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4134     ShowWindow( hchild, SW_HIDE);
4135     flush_sequence();
4136     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4137     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4138     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4139
4140     SetCapture(hchild);
4141     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4142     DestroyWindow(hchild);
4143     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4144
4145     DestroyWindow(hwnd);
4146     flush_sequence();
4147
4148     /* Popup windows */
4149     /* Test 1:
4150      * 1. Create invisible maximized popup window.
4151      * 2. Move and resize it.
4152      * 3. Show it maximized.
4153      */
4154     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4155     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4156                            100, 100, 200, 200, 0, 0, 0, NULL);
4157     ok (hwnd != 0, "Failed to create popup window\n");
4158     ok(IsZoomed(hwnd), "window should be maximized\n");
4159     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4160
4161     GetWindowRect(hwnd, &rc);
4162     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4163         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4164         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4165         rc.left, rc.top, rc.right, rc.bottom);
4166     /* Reset window's size & position */
4167     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4168     ok(IsZoomed(hwnd), "window should be maximized\n");
4169     flush_sequence();
4170
4171     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4172     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4173     ok(IsZoomed(hwnd), "window should be maximized\n");
4174     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4175
4176     GetWindowRect(hwnd, &rc);
4177     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4178         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4179         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4180         rc.left, rc.top, rc.right, rc.bottom);
4181     DestroyWindow(hwnd);
4182     flush_sequence();
4183
4184     /* Test 2:
4185      * 1. Create invisible maximized popup window.
4186      * 2. Show it maximized.
4187      */
4188     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4189     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4190                            100, 100, 200, 200, 0, 0, 0, NULL);
4191     ok (hwnd != 0, "Failed to create popup window\n");
4192     ok(IsZoomed(hwnd), "window should be maximized\n");
4193     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
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(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4199     DestroyWindow(hwnd);
4200     flush_sequence();
4201
4202     /* Test 3:
4203      * 1. Create visible maximized popup window.
4204      */
4205     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4206     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4207                            100, 100, 200, 200, 0, 0, 0, NULL);
4208     ok (hwnd != 0, "Failed to create popup window\n");
4209     ok(IsZoomed(hwnd), "window should be maximized\n");
4210     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4211     DestroyWindow(hwnd);
4212     flush_sequence();
4213
4214     /* Test 4:
4215      * 1. Create visible popup window.
4216      * 2. Maximize it.
4217      */
4218     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4219     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4220                            100, 100, 200, 200, 0, 0, 0, NULL);
4221     ok (hwnd != 0, "Failed to create popup window\n");
4222     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4223     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4224
4225     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4226     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4227     ok(IsZoomed(hwnd), "window should be maximized\n");
4228     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4229     DestroyWindow(hwnd);
4230     flush_sequence();
4231 }
4232
4233 static void test_sys_menu(void)
4234 {
4235     HWND hwnd;
4236     HMENU hmenu;
4237     UINT state;
4238
4239     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4240                            100, 100, 200, 200, 0, 0, 0, NULL);
4241     ok (hwnd != 0, "Failed to create overlapped window\n");
4242
4243     flush_sequence();
4244
4245     /* test existing window without CS_NOCLOSE style */
4246     hmenu = GetSystemMenu(hwnd, FALSE);
4247     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4248
4249     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4250     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4251     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4252
4253     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4254     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4255
4256     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4257     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4258     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4259
4260     EnableMenuItem(hmenu, SC_CLOSE, 0);
4261     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4262
4263     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4264     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4265     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4266
4267     /* test whether removing WS_SYSMENU destroys a system menu */
4268     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4269     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4270     flush_sequence();
4271     hmenu = GetSystemMenu(hwnd, FALSE);
4272     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4273
4274     DestroyWindow(hwnd);
4275
4276     /* test new window with CS_NOCLOSE style */
4277     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4278                            100, 100, 200, 200, 0, 0, 0, NULL);
4279     ok (hwnd != 0, "Failed to create overlapped window\n");
4280
4281     hmenu = GetSystemMenu(hwnd, FALSE);
4282     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4283
4284     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4285     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4286
4287     DestroyWindow(hwnd);
4288
4289     /* test new window without WS_SYSMENU style */
4290     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4291                            100, 100, 200, 200, 0, 0, 0, NULL);
4292     ok(hwnd != 0, "Failed to create overlapped window\n");
4293
4294     hmenu = GetSystemMenu(hwnd, FALSE);
4295     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4296
4297     DestroyWindow(hwnd);
4298 }
4299
4300 /* For shown WS_OVERLAPPEDWINDOW */
4301 static const struct message WmSetIcon_1[] = {
4302     { WM_SETICON, sent },
4303     { 0x00AE, sent|defwinproc|optional }, /* XP */
4304     { WM_GETTEXT, sent|defwinproc|optional },
4305     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4306     { 0 }
4307 };
4308
4309 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4310 static const struct message WmSetIcon_2[] = {
4311     { WM_SETICON, sent },
4312     { 0 }
4313 };
4314
4315 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4316 static const struct message WmInitEndSession[] = {
4317     { 0x003B, sent },
4318     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4319     { 0 }
4320 };
4321
4322 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4323 static const struct message WmInitEndSession_2[] = {
4324     { 0x003B, sent },
4325     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4326     { 0 }
4327 };
4328
4329 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4330 static const struct message WmInitEndSession_3[] = {
4331     { 0x003B, sent },
4332     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4333     { 0 }
4334 };
4335
4336 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4337 static const struct message WmInitEndSession_4[] = {
4338     { 0x003B, sent },
4339     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4340     { 0 }
4341 };
4342
4343 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4344 static const struct message WmInitEndSession_5[] = {
4345     { 0x003B, sent },
4346     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4347     { 0 }
4348 };
4349
4350 static const struct message WmOptionalPaint[] = {
4351     { WM_PAINT, sent|optional },
4352     { WM_NCPAINT, sent|beginpaint|optional },
4353     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4354     { WM_ERASEBKGND, sent|beginpaint|optional },
4355     { 0 }
4356 };
4357
4358 static const struct message WmZOrder[] = {
4359     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4360     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4361     { HCBT_ACTIVATE, hook },
4362     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4363     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4364     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4365     { WM_GETTEXT, sent|optional },
4366     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4367     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4368     { WM_NCACTIVATE, sent|lparam, 1, 0 },
4369     { WM_GETTEXT, sent|defwinproc|optional },
4370     { WM_GETTEXT, sent|defwinproc|optional },
4371     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4372     { HCBT_SETFOCUS, hook },
4373     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4374     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4375     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4376     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4377     { WM_GETTEXT, sent|optional },
4378     { WM_NCCALCSIZE, sent|optional },
4379     { 0 }
4380 };
4381
4382 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4383 {
4384     DWORD ret;
4385     MSG msg;
4386
4387     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4388     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4389
4390     PostMessageA(hwnd, WM_USER, 0, 0);
4391
4392     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4393     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4394
4395     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4396     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4397
4398     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4399     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4400
4401     PostMessageA(hwnd, WM_USER, 0, 0);
4402
4403     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4404     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4405
4406     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4407     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4408
4409     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4410     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4411     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4412
4413     PostMessageA(hwnd, WM_USER, 0, 0);
4414
4415     /* new incoming message causes it to become signaled again */
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     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4422     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4423 }
4424
4425 /* test if we receive the right sequence of messages */
4426 static void test_messages(void)
4427 {
4428     HWND hwnd, hparent, hchild;
4429     HWND hchild2, hbutton;
4430     HMENU hmenu;
4431     MSG msg;
4432     LRESULT res;
4433
4434     flush_sequence();
4435
4436     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4437                            100, 100, 200, 200, 0, 0, 0, NULL);
4438     ok (hwnd != 0, "Failed to create overlapped window\n");
4439     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4440
4441     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4442     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4443     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4444
4445     /* test WM_SETREDRAW on a not visible top level window */
4446     test_WM_SETREDRAW(hwnd);
4447
4448     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4449     flush_events();
4450     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4451     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4452
4453     ok(GetActiveWindow() == hwnd, "window should be active\n");
4454     ok(GetFocus() == hwnd, "window should have input focus\n");
4455     ShowWindow(hwnd, SW_HIDE);
4456     flush_events();
4457     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4458
4459     ShowWindow(hwnd, SW_SHOW);
4460     flush_events();
4461     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4462
4463     ShowWindow(hwnd, SW_HIDE);
4464     flush_events();
4465     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4466
4467     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4468     flush_events();
4469     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4470     flush_sequence();
4471
4472     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4473     {
4474         ShowWindow(hwnd, SW_RESTORE);
4475         flush_events();
4476         ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4477         flush_sequence();
4478     }
4479
4480     ShowWindow(hwnd, SW_MINIMIZE);
4481     flush_events();
4482     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4483     flush_sequence();
4484
4485     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4486     {
4487         ShowWindow(hwnd, SW_RESTORE);
4488         flush_events();
4489         ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4490         flush_sequence();
4491     }
4492
4493     ShowWindow(hwnd, SW_SHOW);
4494     flush_events();
4495     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4496
4497     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4498     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4499     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4500     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4501
4502     /* test WM_SETREDRAW on a visible top level window */
4503     ShowWindow(hwnd, SW_SHOW);
4504     flush_events();
4505     test_WM_SETREDRAW(hwnd);
4506
4507     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4508     test_scroll_messages(hwnd);
4509
4510     /* test resizing and moving */
4511     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4512     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4513     flush_events();
4514     flush_sequence();
4515     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4516     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4517     flush_events();
4518     flush_sequence();
4519     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4520     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4521     flush_events();
4522     flush_sequence();
4523
4524     /* popups don't get WM_GETMINMAXINFO */
4525     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4526     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4527     flush_sequence();
4528     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4529     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4530
4531     DestroyWindow(hwnd);
4532     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4533
4534     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4535                               100, 100, 200, 200, 0, 0, 0, NULL);
4536     ok (hparent != 0, "Failed to create parent window\n");
4537     flush_sequence();
4538
4539     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4540                              0, 0, 10, 10, hparent, 0, 0, NULL);
4541     ok (hchild != 0, "Failed to create child window\n");
4542     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4543     DestroyWindow(hchild);
4544     flush_sequence();
4545
4546     /* visible child window with a caption */
4547     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4548                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4549                              0, 0, 10, 10, hparent, 0, 0, NULL);
4550     ok (hchild != 0, "Failed to create child window\n");
4551     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4552
4553     trace("testing scroll APIs on a visible child window %p\n", hchild);
4554     test_scroll_messages(hchild);
4555
4556     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4557     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4558
4559     DestroyWindow(hchild);
4560     flush_sequence();
4561
4562     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4563                              0, 0, 10, 10, hparent, 0, 0, NULL);
4564     ok (hchild != 0, "Failed to create child window\n");
4565     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4566     
4567     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4568                                100, 100, 50, 50, hparent, 0, 0, NULL);
4569     ok (hchild2 != 0, "Failed to create child2 window\n");
4570     flush_sequence();
4571
4572     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4573                               0, 100, 50, 50, hchild, 0, 0, NULL);
4574     ok (hbutton != 0, "Failed to create button window\n");
4575
4576     /* test WM_SETREDRAW on a not visible child window */
4577     test_WM_SETREDRAW(hchild);
4578
4579     ShowWindow(hchild, SW_SHOW);
4580     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4581
4582     /* check parent messages too */
4583     log_all_parent_messages++;
4584     ShowWindow(hchild, SW_HIDE);
4585     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4586     log_all_parent_messages--;
4587
4588     ShowWindow(hchild, SW_SHOW);
4589     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4590
4591     ShowWindow(hchild, SW_HIDE);
4592     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4593
4594     ShowWindow(hchild, SW_SHOW);
4595     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4596
4597     /* test WM_SETREDRAW on a visible child window */
4598     test_WM_SETREDRAW(hchild);
4599
4600     log_all_parent_messages++;
4601     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4602     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4603     log_all_parent_messages--;
4604
4605     ShowWindow(hchild, SW_HIDE);
4606     flush_sequence();
4607     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4608     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4609
4610     ShowWindow(hchild, SW_HIDE);
4611     flush_sequence();
4612     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4613     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4614
4615     /* DestroyWindow sequence below expects that a child has focus */
4616     SetFocus(hchild);
4617     flush_sequence();
4618
4619     DestroyWindow(hchild);
4620     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4621     DestroyWindow(hchild2);
4622     DestroyWindow(hbutton);
4623
4624     flush_sequence();
4625     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4626                              0, 0, 100, 100, hparent, 0, 0, NULL);
4627     ok (hchild != 0, "Failed to create child popup window\n");
4628     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4629     DestroyWindow(hchild);
4630
4631     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4632     flush_sequence();
4633     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4634                              0, 0, 100, 100, hparent, 0, 0, NULL);
4635     ok (hchild != 0, "Failed to create popup window\n");
4636     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4637     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4638     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4639     flush_sequence();
4640     ShowWindow(hchild, SW_SHOW);
4641     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4642     flush_sequence();
4643     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4644     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4645     flush_sequence();
4646     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4647     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4648     DestroyWindow(hchild);
4649
4650     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4651      * changes nothing in message sequences.
4652      */
4653     flush_sequence();
4654     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4655                              0, 0, 100, 100, hparent, 0, 0, NULL);
4656     ok (hchild != 0, "Failed to create popup window\n");
4657     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4658     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4659     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4660     flush_sequence();
4661     ShowWindow(hchild, SW_SHOW);
4662     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4663     flush_sequence();
4664     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4665     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4666     DestroyWindow(hchild);
4667
4668     flush_sequence();
4669     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4670                            0, 0, 100, 100, hparent, 0, 0, NULL);
4671     ok(hwnd != 0, "Failed to create custom dialog window\n");
4672     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4673
4674     /*
4675     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4676     test_scroll_messages(hwnd);
4677     */
4678
4679     flush_sequence();
4680
4681     test_def_id = 1;
4682     SendMessage(hwnd, WM_NULL, 0, 0);
4683
4684     flush_sequence();
4685     after_end_dialog = 1;
4686     EndDialog( hwnd, 0 );
4687     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4688
4689     DestroyWindow(hwnd);
4690     after_end_dialog = 0;
4691     test_def_id = 0;
4692
4693     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4694                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4695     ok(hwnd != 0, "Failed to create custom dialog window\n");
4696     flush_sequence();
4697     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4698     ShowWindow(hwnd, SW_SHOW);
4699     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4700     DestroyWindow(hwnd);
4701
4702     flush_sequence();
4703     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4704     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4705
4706     DestroyWindow(hparent);
4707     flush_sequence();
4708
4709     /* Message sequence for SetMenu */
4710     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4711     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4712
4713     hmenu = CreateMenu();
4714     ok (hmenu != 0, "Failed to create menu\n");
4715     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4716     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4717                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4718     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4719     ok (SetMenu(hwnd, 0), "SetMenu\n");
4720     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4721     ok (SetMenu(hwnd, 0), "SetMenu\n");
4722     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4723     ShowWindow(hwnd, SW_SHOW);
4724     UpdateWindow( hwnd );
4725     flush_events();
4726     flush_sequence();
4727     ok (SetMenu(hwnd, 0), "SetMenu\n");
4728     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4729     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4730     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4731
4732     UpdateWindow( hwnd );
4733     flush_events();
4734     flush_sequence();
4735     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4736     flush_events();
4737     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4738
4739     DestroyWindow(hwnd);
4740     flush_sequence();
4741
4742     /* Message sequence for EnableWindow */
4743     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4744                               100, 100, 200, 200, 0, 0, 0, NULL);
4745     ok (hparent != 0, "Failed to create parent window\n");
4746     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4747                              0, 0, 10, 10, hparent, 0, 0, NULL);
4748     ok (hchild != 0, "Failed to create child window\n");
4749
4750     SetFocus(hchild);
4751     flush_events();
4752     flush_sequence();
4753
4754     EnableWindow(hparent, FALSE);
4755     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4756
4757     EnableWindow(hparent, TRUE);
4758     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4759
4760     flush_events();
4761     flush_sequence();
4762
4763     test_MsgWaitForMultipleObjects(hparent);
4764
4765     /* the following test causes an exception in user.exe under win9x */
4766     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4767     {
4768         DestroyWindow(hparent);
4769         flush_sequence();
4770         return;
4771     }
4772     PostMessageW( hparent, WM_USER+1, 0, 0 );
4773     /* PeekMessage(NULL) fails, but still removes the message */
4774     SetLastError(0xdeadbeef);
4775     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4776     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4777         GetLastError() == 0xdeadbeef, /* NT4 */
4778         "last error is %d\n", GetLastError() );
4779     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4780     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4781
4782     DestroyWindow(hchild);
4783     DestroyWindow(hparent);
4784     flush_sequence();
4785
4786     /* Message sequences for WM_SETICON */
4787     trace("testing WM_SETICON\n");
4788     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4789                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4790                            NULL, NULL, 0);
4791     ShowWindow(hwnd, SW_SHOW);
4792     UpdateWindow(hwnd);
4793     flush_events();
4794     flush_sequence();
4795     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4796     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4797
4798     ShowWindow(hwnd, SW_HIDE);
4799     flush_events();
4800     flush_sequence();
4801     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4802     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4803     DestroyWindow(hwnd);
4804     flush_sequence();
4805
4806     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4807                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4808                            NULL, NULL, 0);
4809     ShowWindow(hwnd, SW_SHOW);
4810     UpdateWindow(hwnd);
4811     flush_events();
4812     flush_sequence();
4813     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4814     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4815
4816     ShowWindow(hwnd, SW_HIDE);
4817     flush_events();
4818     flush_sequence();
4819     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4820     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4821
4822     flush_sequence();
4823     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4824     if (!res)
4825     {
4826         todo_wine win_skip( "Message 0x3b not supported\n" );
4827         goto done;
4828     }
4829     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4830     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4831     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4832     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4833     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4834     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4835     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4836     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4837
4838     flush_sequence();
4839     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4840     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4841     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4842     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4843     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4844     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4845
4846     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4847     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4848     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4849
4850     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4851     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4852     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4853
4854 done:
4855     DestroyWindow(hwnd);
4856     flush_sequence();
4857 }
4858
4859 static void test_setwindowpos(void)
4860 {
4861     HWND hwnd;
4862     RECT rc;
4863     LRESULT res;
4864     const INT winX = 100;
4865     const INT winY = 100;
4866     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4867
4868     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4869                            0, 0, winX, winY, 0,
4870                            NULL, NULL, 0);
4871
4872     GetWindowRect(hwnd, &rc);
4873     expect(sysX, rc.right);
4874     expect(winY, rc.bottom);
4875
4876     flush_events();
4877     flush_sequence();
4878     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4879     ok_sequence(WmZOrder, "Z-Order", TRUE);
4880     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4881
4882     GetWindowRect(hwnd, &rc);
4883     expect(sysX, rc.right);
4884     expect(winY, rc.bottom);
4885     DestroyWindow(hwnd);
4886 }
4887
4888 static void invisible_parent_tests(void)
4889 {
4890     HWND hparent, hchild;
4891
4892     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4893                               100, 100, 200, 200, 0, 0, 0, NULL);
4894     ok (hparent != 0, "Failed to create parent window\n");
4895     flush_sequence();
4896
4897     /* test showing child with hidden parent */
4898
4899     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4900                              0, 0, 10, 10, hparent, 0, 0, NULL);
4901     ok (hchild != 0, "Failed to create child window\n");
4902     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4903
4904     ShowWindow( hchild, SW_MINIMIZE );
4905     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4906     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4907     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4908
4909     /* repeat */
4910     flush_events();
4911     flush_sequence();
4912     ShowWindow( hchild, SW_MINIMIZE );
4913     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4914
4915     DestroyWindow(hchild);
4916     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4917                              0, 0, 10, 10, hparent, 0, 0, NULL);
4918     flush_sequence();
4919
4920     ShowWindow( hchild, SW_MAXIMIZE );
4921     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4922     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4923     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4924
4925     /* repeat */
4926     flush_events();
4927     flush_sequence();
4928     ShowWindow( hchild, SW_MAXIMIZE );
4929     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4930
4931     DestroyWindow(hchild);
4932     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4933                              0, 0, 10, 10, hparent, 0, 0, NULL);
4934     flush_sequence();
4935
4936     ShowWindow( hchild, SW_RESTORE );
4937     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4938     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4939     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4940
4941     DestroyWindow(hchild);
4942     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4943                              0, 0, 10, 10, hparent, 0, 0, NULL);
4944     flush_sequence();
4945
4946     ShowWindow( hchild, SW_SHOWMINIMIZED );
4947     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4948     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4949     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4950
4951     /* repeat */
4952     flush_events();
4953     flush_sequence();
4954     ShowWindow( hchild, SW_SHOWMINIMIZED );
4955     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4956
4957     DestroyWindow(hchild);
4958     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4959                              0, 0, 10, 10, hparent, 0, 0, NULL);
4960     flush_sequence();
4961
4962     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4963     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4964     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4965     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4966     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4967
4968     DestroyWindow(hchild);
4969     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4970                              0, 0, 10, 10, hparent, 0, 0, NULL);
4971     flush_sequence();
4972
4973     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4974     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4975     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4976     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4977
4978     /* repeat */
4979     flush_events();
4980     flush_sequence();
4981     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4982     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4983
4984     DestroyWindow(hchild);
4985     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4986                              0, 0, 10, 10, hparent, 0, 0, NULL);
4987     flush_sequence();
4988
4989     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4990     ShowWindow( hchild, SW_FORCEMINIMIZE );
4991     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4992 todo_wine {
4993     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4994 }
4995     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4996
4997     DestroyWindow(hchild);
4998     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4999                              0, 0, 10, 10, hparent, 0, 0, NULL);
5000     flush_sequence();
5001
5002     ShowWindow( hchild, SW_SHOWNA );
5003     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5004     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5005     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5006
5007     /* repeat */
5008     flush_events();
5009     flush_sequence();
5010     ShowWindow( hchild, SW_SHOWNA );
5011     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5012
5013     DestroyWindow(hchild);
5014     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5015                              0, 0, 10, 10, hparent, 0, 0, NULL);
5016     flush_sequence();
5017
5018     ShowWindow( hchild, SW_SHOW );
5019     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5020     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5021     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5022
5023     /* repeat */
5024     flush_events();
5025     flush_sequence();
5026     ShowWindow( hchild, SW_SHOW );
5027     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5028
5029     ShowWindow( hchild, SW_HIDE );
5030     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5031     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5032     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5033
5034     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5035     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5036     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5037     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5038
5039     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5040     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5041     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5042     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5043
5044     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5045     flush_sequence();
5046     DestroyWindow(hchild);
5047     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5048
5049     DestroyWindow(hparent);
5050     flush_sequence();
5051 }
5052
5053 /****************** button message test *************************/
5054 static const struct message WmSetFocusButtonSeq[] =
5055 {
5056     { HCBT_SETFOCUS, hook },
5057     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5058     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5059     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5060     { WM_SETFOCUS, sent|wparam, 0 },
5061     { WM_CTLCOLORBTN, sent|defwinproc },
5062     { 0 }
5063 };
5064 static const struct message WmKillFocusButtonSeq[] =
5065 {
5066     { HCBT_SETFOCUS, hook },
5067     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5068     { WM_KILLFOCUS, sent|wparam, 0 },
5069     { WM_CTLCOLORBTN, sent|defwinproc },
5070     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5071     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5072     { 0 }
5073 };
5074 static const struct message WmSetFocusStaticSeq[] =
5075 {
5076     { HCBT_SETFOCUS, hook },
5077     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5078     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5079     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5080     { WM_SETFOCUS, sent|wparam, 0 },
5081     { WM_CTLCOLORSTATIC, sent|defwinproc },
5082     { 0 }
5083 };
5084 static const struct message WmKillFocusStaticSeq[] =
5085 {
5086     { HCBT_SETFOCUS, hook },
5087     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5088     { WM_KILLFOCUS, sent|wparam, 0 },
5089     { WM_CTLCOLORSTATIC, sent|defwinproc },
5090     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5091     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5092     { 0 }
5093 };
5094 static const struct message WmLButtonDownSeq[] =
5095 {
5096     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5097     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5098     { HCBT_SETFOCUS, hook },
5099     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5100     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5101     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5102     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5103     { WM_CTLCOLORBTN, sent|defwinproc },
5104     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5105     { WM_CTLCOLORBTN, sent|defwinproc },
5106     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5107     { 0 }
5108 };
5109 static const struct message WmLButtonUpSeq[] =
5110 {
5111     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5112     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5113     { WM_CTLCOLORBTN, sent|defwinproc },
5114     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5115     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5116     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5117     { 0 }
5118 };
5119 static const struct message WmSetFontButtonSeq[] =
5120 {
5121     { WM_SETFONT, sent },
5122     { WM_PAINT, sent },
5123     { WM_ERASEBKGND, sent|defwinproc|optional },
5124     { WM_CTLCOLORBTN, sent|defwinproc },
5125     { 0 }
5126 };
5127
5128 static WNDPROC old_button_proc;
5129
5130 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5131 {
5132     static long defwndproc_counter = 0;
5133     LRESULT ret;
5134     struct recvd_message msg;
5135
5136     switch (message)
5137     {
5138     case WM_GETICON:
5139     case WM_GETOBJECT:
5140         return 0;  /* ignore them */
5141     case WM_SYNCPAINT:
5142         break;
5143     case BM_SETSTATE:
5144         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5145         /* fall through */
5146     default:
5147         msg.hwnd = hwnd;
5148         msg.message = message;
5149         msg.flags = sent|wparam|lparam;
5150         if (defwndproc_counter) msg.flags |= defwinproc;
5151         msg.wParam = wParam;
5152         msg.lParam = lParam;
5153         msg.descr = "button";
5154         add_message(&msg);
5155     }
5156
5157     defwndproc_counter++;
5158     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5159     defwndproc_counter--;
5160
5161     return ret;
5162 }
5163
5164 static void subclass_button(void)
5165 {
5166     WNDCLASSA cls;
5167
5168     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5169
5170     old_button_proc = cls.lpfnWndProc;
5171
5172     cls.hInstance = GetModuleHandle(0);
5173     cls.lpfnWndProc = button_hook_proc;
5174     cls.lpszClassName = "my_button_class";
5175     UnregisterClass(cls.lpszClassName, cls.hInstance);
5176     if (!RegisterClassA(&cls)) assert(0);
5177 }
5178
5179 static void test_button_messages(void)
5180 {
5181     static const struct
5182     {
5183         DWORD style;
5184         DWORD dlg_code;
5185         const struct message *setfocus;
5186         const struct message *killfocus;
5187     } button[] = {
5188         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5189           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5190         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5191           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5192         { BS_CHECKBOX, DLGC_BUTTON,
5193           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5194         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5195           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5196         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5197           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5198         { BS_3STATE, DLGC_BUTTON,
5199           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5200         { BS_AUTO3STATE, DLGC_BUTTON,
5201           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5202         { BS_GROUPBOX, DLGC_STATIC,
5203           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5204         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5205           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5206         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5207           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5208         { BS_OWNERDRAW, DLGC_BUTTON,
5209           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5210     };
5211     unsigned int i;
5212     HWND hwnd;
5213     DWORD dlg_code;
5214     HFONT zfont;
5215
5216     /* selection with VK_SPACE should capture button window */
5217     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5218                            0, 0, 50, 14, 0, 0, 0, NULL);
5219     ok(hwnd != 0, "Failed to create button window\n");
5220     ReleaseCapture();
5221     SetFocus(hwnd);
5222     SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5223     ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5224     SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5225     DestroyWindow(hwnd);
5226
5227     subclass_button();
5228
5229     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5230     {
5231         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5232                                0, 0, 50, 14, 0, 0, 0, NULL);
5233         ok(hwnd != 0, "Failed to create button window\n");
5234
5235         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5236         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5237
5238         ShowWindow(hwnd, SW_SHOW);
5239         UpdateWindow(hwnd);
5240         SetFocus(0);
5241         flush_sequence();
5242
5243         trace("button style %08x\n", button[i].style);
5244         SetFocus(hwnd);
5245         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5246
5247         SetFocus(0);
5248         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5249
5250         DestroyWindow(hwnd);
5251     }
5252
5253     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5254                            0, 0, 50, 14, 0, 0, 0, NULL);
5255     ok(hwnd != 0, "Failed to create button window\n");
5256
5257     SetForegroundWindow(hwnd);
5258     flush_events();
5259
5260     SetActiveWindow(hwnd);
5261     SetFocus(0);
5262     flush_sequence();
5263
5264     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5265     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5266
5267     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5268     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5269
5270     flush_sequence();
5271     zfont = GetStockObject(SYSTEM_FONT);
5272     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5273     UpdateWindow(hwnd);
5274     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5275
5276     DestroyWindow(hwnd);
5277 }
5278
5279 /****************** static message test *************************/
5280 static const struct message WmSetFontStaticSeq[] =
5281 {
5282     { WM_SETFONT, sent },
5283     { WM_PAINT, sent|defwinproc|optional },
5284     { WM_ERASEBKGND, sent|defwinproc|optional },
5285     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5286     { 0 }
5287 };
5288
5289 static WNDPROC old_static_proc;
5290
5291 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5292 {
5293     static long defwndproc_counter = 0;
5294     LRESULT ret;
5295     struct recvd_message msg;
5296
5297     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5298
5299     msg.hwnd = hwnd;
5300     msg.message = message;
5301     msg.flags = sent|wparam|lparam;
5302     if (defwndproc_counter) msg.flags |= defwinproc;
5303     msg.wParam = wParam;
5304     msg.lParam = lParam;
5305     msg.descr = "static";
5306     add_message(&msg);
5307
5308     defwndproc_counter++;
5309     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5310     defwndproc_counter--;
5311
5312     return ret;
5313 }
5314
5315 static void subclass_static(void)
5316 {
5317     WNDCLASSA cls;
5318
5319     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5320
5321     old_static_proc = cls.lpfnWndProc;
5322
5323     cls.hInstance = GetModuleHandle(0);
5324     cls.lpfnWndProc = static_hook_proc;
5325     cls.lpszClassName = "my_static_class";
5326     UnregisterClass(cls.lpszClassName, cls.hInstance);
5327     if (!RegisterClassA(&cls)) assert(0);
5328 }
5329
5330 static void test_static_messages(void)
5331 {
5332     /* FIXME: make as comprehensive as the button message test */
5333     static const struct
5334     {
5335         DWORD style;
5336         DWORD dlg_code;
5337         const struct message *setfont;
5338     } static_ctrl[] = {
5339         { SS_LEFT, DLGC_STATIC,
5340           WmSetFontStaticSeq }
5341     };
5342     unsigned int i;
5343     HWND hwnd;
5344     DWORD dlg_code;
5345
5346     subclass_static();
5347
5348     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5349     {
5350         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5351                                0, 0, 50, 14, 0, 0, 0, NULL);
5352         ok(hwnd != 0, "Failed to create static window\n");
5353
5354         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5355         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5356
5357         ShowWindow(hwnd, SW_SHOW);
5358         UpdateWindow(hwnd);
5359         SetFocus(0);
5360         flush_sequence();
5361
5362         trace("static style %08x\n", static_ctrl[i].style);
5363         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5364         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5365
5366         DestroyWindow(hwnd);
5367     }
5368 }
5369
5370 /****************** ComboBox message test *************************/
5371 #define ID_COMBOBOX 0x000f
5372
5373 static const struct message WmKeyDownComboSeq[] =
5374 {
5375     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5376     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5377     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5378     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5379     { WM_CTLCOLOREDIT, sent|parent },
5380     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5381     { 0 }
5382 };
5383
5384 static WNDPROC old_combobox_proc;
5385
5386 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5387 {
5388     static long defwndproc_counter = 0;
5389     LRESULT ret;
5390     struct recvd_message msg;
5391
5392     /* do not log painting messages */
5393     if (message != WM_PAINT &&
5394         message != WM_NCPAINT &&
5395         message != WM_SYNCPAINT &&
5396         message != WM_ERASEBKGND &&
5397         message != WM_NCHITTEST &&
5398         message != WM_GETTEXT &&
5399         message != WM_GETICON &&
5400         message != WM_GETOBJECT &&
5401         message != WM_DEVICECHANGE)
5402     {
5403         msg.hwnd = hwnd;
5404         msg.message = message;
5405         msg.flags = sent|wparam|lparam;
5406         if (defwndproc_counter) msg.flags |= defwinproc;
5407         msg.wParam = wParam;
5408         msg.lParam = lParam;
5409         msg.descr = "combo";
5410         add_message(&msg);
5411     }
5412
5413     defwndproc_counter++;
5414     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5415     defwndproc_counter--;
5416
5417     return ret;
5418 }
5419
5420 static void subclass_combobox(void)
5421 {
5422     WNDCLASSA cls;
5423
5424     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5425
5426     old_combobox_proc = cls.lpfnWndProc;
5427
5428     cls.hInstance = GetModuleHandle(0);
5429     cls.lpfnWndProc = combobox_hook_proc;
5430     cls.lpszClassName = "my_combobox_class";
5431     UnregisterClass(cls.lpszClassName, cls.hInstance);
5432     if (!RegisterClassA(&cls)) assert(0);
5433 }
5434
5435 static void test_combobox_messages(void)
5436 {
5437     HWND parent, combo;
5438     LRESULT ret;
5439
5440     subclass_combobox();
5441
5442     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5443                              100, 100, 200, 200, 0, 0, 0, NULL);
5444     ok(parent != 0, "Failed to create parent window\n");
5445     flush_sequence();
5446
5447     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5448                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5449     ok(combo != 0, "Failed to create combobox window\n");
5450
5451     UpdateWindow(combo);
5452
5453     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5454     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5455
5456     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5457     ok(ret == 0, "expected 0, got %ld\n", ret);
5458     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5459     ok(ret == 1, "expected 1, got %ld\n", ret);
5460     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5461     ok(ret == 2, "expected 2, got %ld\n", ret);
5462
5463     SendMessage(combo, CB_SETCURSEL, 0, 0);
5464     SetFocus(combo);
5465     flush_sequence();
5466
5467     log_all_parent_messages++;
5468     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5469     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5470     log_all_parent_messages--;
5471     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5472
5473     DestroyWindow(combo);
5474     DestroyWindow(parent);
5475 }
5476
5477 /****************** WM_IME_KEYDOWN message test *******************/
5478
5479 static const struct message WmImeKeydownMsgSeq_0[] =
5480 {
5481     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5482     { WM_CHAR, wparam, 'A' },
5483     { 0 }
5484 };
5485
5486 static const struct message WmImeKeydownMsgSeq_1[] =
5487 {
5488     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5489     { WM_CHAR,    optional|wparam, VK_RETURN },
5490     { 0 }
5491 };
5492
5493 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5494 {
5495     struct recvd_message msg;
5496
5497     msg.hwnd = hwnd;
5498     msg.message = message;
5499     msg.flags = wparam|lparam;
5500     msg.wParam = wParam;
5501     msg.lParam = lParam;
5502     msg.descr = "wmime_keydown";
5503     add_message(&msg);
5504
5505     return DefWindowProcA(hwnd, message, wParam, lParam);
5506 }
5507
5508 static void register_wmime_keydown_class(void)
5509 {
5510     WNDCLASSA cls;
5511
5512     ZeroMemory(&cls, sizeof(WNDCLASSA));
5513     cls.lpfnWndProc = wmime_keydown_procA;
5514     cls.hInstance = GetModuleHandleA(0);
5515     cls.lpszClassName = "wmime_keydown_class";
5516     if (!RegisterClassA(&cls)) assert(0);
5517 }
5518
5519 static void test_wmime_keydown_message(void)
5520 {
5521     HWND hwnd;
5522     MSG msg;
5523
5524     trace("Message sequences by WM_IME_KEYDOWN\n");
5525
5526     register_wmime_keydown_class();
5527     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5528                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5529                            NULL, NULL, 0);
5530     flush_events();
5531     flush_sequence();
5532
5533     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5534     SendMessage(hwnd, WM_CHAR, 'A', 1);
5535     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5536
5537     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5538     {
5539         TranslateMessage(&msg);
5540         DispatchMessage(&msg);
5541     }
5542     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5543
5544     DestroyWindow(hwnd);
5545 }
5546
5547 /************* painting message test ********************/
5548
5549 void dump_region(HRGN hrgn)
5550 {
5551     DWORD i, size;
5552     RGNDATA *data = NULL;
5553     RECT *rect;
5554
5555     if (!hrgn)
5556     {
5557         printf( "null region\n" );
5558         return;
5559     }
5560     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5561     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5562     GetRegionData( hrgn, size, data );
5563     printf("%d rects:", data->rdh.nCount );
5564     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5565         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5566     printf("\n");
5567     HeapFree( GetProcessHeap(), 0, data );
5568 }
5569
5570 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5571 {
5572     INT ret;
5573     RECT r1, r2;
5574     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5575     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5576
5577     ret = GetUpdateRgn( hwnd, update, FALSE );
5578     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5579     if (ret == NULLREGION)
5580     {
5581         ok( !hrgn, "Update region shouldn't be empty\n" );
5582     }
5583     else
5584     {
5585         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5586         {
5587             ok( 0, "Regions are different\n" );
5588             if (winetest_debug > 0)
5589             {
5590                 printf( "Update region: " );
5591                 dump_region( update );
5592                 printf( "Wanted region: " );
5593                 dump_region( hrgn );
5594             }
5595         }
5596     }
5597     GetRgnBox( update, &r1 );
5598     GetUpdateRect( hwnd, &r2, FALSE );
5599     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5600         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5601         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5602
5603     DeleteObject( tmp );
5604     DeleteObject( update );
5605 }
5606
5607 static const struct message WmInvalidateRgn[] = {
5608     { WM_NCPAINT, sent },
5609     { WM_GETTEXT, sent|defwinproc|optional },
5610     { 0 }
5611 };
5612
5613 static const struct message WmGetUpdateRect[] = {
5614     { WM_NCPAINT, sent },
5615     { WM_GETTEXT, sent|defwinproc|optional },
5616     { WM_PAINT, sent },
5617     { 0 }
5618 };
5619
5620 static const struct message WmInvalidateFull[] = {
5621     { WM_NCPAINT, sent|wparam, 1 },
5622     { WM_GETTEXT, sent|defwinproc|optional },
5623     { 0 }
5624 };
5625
5626 static const struct message WmInvalidateErase[] = {
5627     { WM_NCPAINT, sent|wparam, 1 },
5628     { WM_GETTEXT, sent|defwinproc|optional },
5629     { WM_ERASEBKGND, sent },
5630     { 0 }
5631 };
5632
5633 static const struct message WmInvalidatePaint[] = {
5634     { WM_PAINT, sent },
5635     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5636     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5637     { 0 }
5638 };
5639
5640 static const struct message WmInvalidateErasePaint[] = {
5641     { WM_PAINT, sent },
5642     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5643     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5644     { WM_ERASEBKGND, sent|beginpaint|optional },
5645     { 0 }
5646 };
5647
5648 static const struct message WmInvalidateErasePaint2[] = {
5649     { WM_PAINT, sent },
5650     { WM_NCPAINT, sent|beginpaint },
5651     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5652     { WM_ERASEBKGND, sent|beginpaint|optional },
5653     { 0 }
5654 };
5655
5656 static const struct message WmErase[] = {
5657     { WM_ERASEBKGND, sent },
5658     { 0 }
5659 };
5660
5661 static const struct message WmPaint[] = {
5662     { WM_PAINT, sent },
5663     { 0 }
5664 };
5665
5666 static const struct message WmParentOnlyPaint[] = {
5667     { WM_PAINT, sent|parent },
5668     { 0 }
5669 };
5670
5671 static const struct message WmInvalidateParent[] = {
5672     { WM_NCPAINT, sent|parent },
5673     { WM_GETTEXT, sent|defwinproc|parent|optional },
5674     { WM_ERASEBKGND, sent|parent },
5675     { 0 }
5676 };
5677
5678 static const struct message WmInvalidateParentChild[] = {
5679     { WM_NCPAINT, sent|parent },
5680     { WM_GETTEXT, sent|defwinproc|parent|optional },
5681     { WM_ERASEBKGND, sent|parent },
5682     { WM_NCPAINT, sent },
5683     { WM_GETTEXT, sent|defwinproc|optional },
5684     { WM_ERASEBKGND, sent },
5685     { 0 }
5686 };
5687
5688 static const struct message WmInvalidateParentChild2[] = {
5689     { WM_ERASEBKGND, sent|parent },
5690     { WM_NCPAINT, sent },
5691     { WM_GETTEXT, sent|defwinproc|optional },
5692     { WM_ERASEBKGND, sent },
5693     { 0 }
5694 };
5695
5696 static const struct message WmParentPaint[] = {
5697     { WM_PAINT, sent|parent },
5698     { WM_PAINT, sent },
5699     { 0 }
5700 };
5701
5702 static const struct message WmParentPaintNc[] = {
5703     { WM_PAINT, sent|parent },
5704     { WM_PAINT, sent },
5705     { WM_NCPAINT, sent|beginpaint },
5706     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5707     { WM_ERASEBKGND, sent|beginpaint|optional },
5708     { 0 }
5709 };
5710
5711 static const struct message WmChildPaintNc[] = {
5712     { WM_PAINT, sent },
5713     { WM_NCPAINT, sent|beginpaint },
5714     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5715     { WM_ERASEBKGND, sent|beginpaint|optional },
5716     { 0 }
5717 };
5718
5719 static const struct message WmParentErasePaint[] = {
5720     { WM_PAINT, sent|parent },
5721     { WM_NCPAINT, sent|parent|beginpaint },
5722     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5723     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5724     { WM_PAINT, sent },
5725     { WM_NCPAINT, sent|beginpaint },
5726     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5727     { WM_ERASEBKGND, sent|beginpaint|optional },
5728     { 0 }
5729 };
5730
5731 static const struct message WmParentOnlyNcPaint[] = {
5732     { WM_PAINT, sent|parent },
5733     { WM_NCPAINT, sent|parent|beginpaint },
5734     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5735     { 0 }
5736 };
5737
5738 static const struct message WmSetParentStyle[] = {
5739     { WM_STYLECHANGING, sent|parent },
5740     { WM_STYLECHANGED, sent|parent },
5741     { 0 }
5742 };
5743
5744 static void test_paint_messages(void)
5745 {
5746     BOOL ret;
5747     RECT rect;
5748     POINT pt;
5749     MSG msg;
5750     HWND hparent, hchild;
5751     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5752     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5753     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5754                                 100, 100, 200, 200, 0, 0, 0, NULL);
5755     ok (hwnd != 0, "Failed to create overlapped window\n");
5756
5757     ShowWindow( hwnd, SW_SHOW );
5758     UpdateWindow( hwnd );
5759     flush_events();
5760     flush_sequence();
5761
5762     check_update_rgn( hwnd, 0 );
5763     SetRectRgn( hrgn, 10, 10, 20, 20 );
5764     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5765     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5766     check_update_rgn( hwnd, hrgn );
5767     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5768     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5769     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5770     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5771     check_update_rgn( hwnd, hrgn );
5772     /* validate everything */
5773     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5774     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5775     check_update_rgn( hwnd, 0 );
5776
5777     /* test empty region */
5778     SetRectRgn( hrgn, 10, 10, 10, 15 );
5779     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5780     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5781     check_update_rgn( hwnd, 0 );
5782     /* test empty rect */
5783     SetRect( &rect, 10, 10, 10, 15 );
5784     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5785     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5786     check_update_rgn( hwnd, 0 );
5787
5788     /* flush pending messages */
5789     flush_events();
5790     flush_sequence();
5791
5792     GetClientRect( hwnd, &rect );
5793     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5794     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5795      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5796      */
5797     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5798     SetRectEmpty( &rect );
5799     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5800     check_update_rgn( hwnd, hrgn );
5801     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5802     flush_events();
5803     ok_sequence( WmPaint, "Paint", FALSE );
5804     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5805     check_update_rgn( hwnd, 0 );
5806
5807     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5808      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5809      */
5810     trace("testing ValidateRect(0, NULL)\n");
5811     SetRectEmpty( &rect );
5812     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5813     {
5814         check_update_rgn( hwnd, hrgn );
5815         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5816         flush_events();
5817         ok_sequence( WmPaint, "Paint", FALSE );
5818         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5819         check_update_rgn( hwnd, 0 );
5820     }
5821
5822     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5823     SetLastError(0xdeadbeef);
5824     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5825     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5826        "wrong error code %d\n", GetLastError());
5827     check_update_rgn( hwnd, 0 );
5828     flush_events();
5829     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5830
5831     trace("testing ValidateRgn(0, NULL)\n");
5832     SetLastError(0xdeadbeef);
5833     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5834     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5835        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5836        "wrong error code %d\n", GetLastError());
5837     check_update_rgn( hwnd, 0 );
5838     flush_events();
5839     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5840
5841     /* now with frame */
5842     SetRectRgn( hrgn, -5, -5, 20, 20 );
5843
5844     /* flush pending messages */
5845     flush_events();
5846     flush_sequence();
5847     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5848     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5849
5850     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5851     check_update_rgn( hwnd, hrgn );
5852
5853     flush_sequence();
5854     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5855     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5856
5857     flush_sequence();
5858     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5859     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5860
5861     GetClientRect( hwnd, &rect );
5862     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5863     check_update_rgn( hwnd, hrgn );
5864
5865     flush_sequence();
5866     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5867     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5868
5869     flush_sequence();
5870     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5871     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5872     check_update_rgn( hwnd, 0 );
5873
5874     flush_sequence();
5875     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5876     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5877     check_update_rgn( hwnd, 0 );
5878
5879     flush_sequence();
5880     SetRectRgn( hrgn, 0, 0, 100, 100 );
5881     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5882     SetRectRgn( hrgn, 0, 0, 50, 100 );
5883     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5884     SetRectRgn( hrgn, 50, 0, 100, 100 );
5885     check_update_rgn( hwnd, hrgn );
5886     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5887     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5888     check_update_rgn( hwnd, 0 );
5889
5890     flush_sequence();
5891     SetRectRgn( hrgn, 0, 0, 100, 100 );
5892     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5893     SetRectRgn( hrgn, 0, 0, 100, 50 );
5894     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5895     ok_sequence( WmErase, "Erase", FALSE );
5896     SetRectRgn( hrgn, 0, 50, 100, 100 );
5897     check_update_rgn( hwnd, hrgn );
5898
5899     flush_sequence();
5900     SetRectRgn( hrgn, 0, 0, 100, 100 );
5901     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5902     SetRectRgn( hrgn, 0, 0, 50, 50 );
5903     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5904     ok_sequence( WmPaint, "Paint", FALSE );
5905
5906     flush_sequence();
5907     SetRectRgn( hrgn, -4, -4, -2, -2 );
5908     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5909     SetRectRgn( hrgn, -200, -200, -198, -198 );
5910     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5911     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5912
5913     flush_sequence();
5914     SetRectRgn( hrgn, -4, -4, -2, -2 );
5915     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5916     SetRectRgn( hrgn, -4, -4, -3, -3 );
5917     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5918     SetRectRgn( hrgn, 0, 0, 1, 1 );
5919     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5920     ok_sequence( WmPaint, "Paint", FALSE );
5921
5922     flush_sequence();
5923     SetRectRgn( hrgn, -4, -4, -1, -1 );
5924     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5925     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5926     /* make sure no WM_PAINT was generated */
5927     flush_events();
5928     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5929
5930     flush_sequence();
5931     SetRectRgn( hrgn, -4, -4, -1, -1 );
5932     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5933     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5934     {
5935         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5936         {
5937             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5938             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5939             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5940             ret = GetUpdateRect( hwnd, &rect, FALSE );
5941             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5942             /* this will send WM_NCPAINT and validate the non client area */
5943             ret = GetUpdateRect( hwnd, &rect, TRUE );
5944             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5945         }
5946         DispatchMessage( &msg );
5947     }
5948     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5949
5950     DestroyWindow( hwnd );
5951
5952     /* now test with a child window */
5953
5954     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5955                               100, 100, 200, 200, 0, 0, 0, NULL);
5956     ok (hparent != 0, "Failed to create parent window\n");
5957
5958     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5959                            10, 10, 100, 100, hparent, 0, 0, NULL);
5960     ok (hchild != 0, "Failed to create child window\n");
5961
5962     ShowWindow( hparent, SW_SHOW );
5963     UpdateWindow( hparent );
5964     UpdateWindow( hchild );
5965     flush_events();
5966     flush_sequence();
5967     log_all_parent_messages++;
5968
5969     SetRect( &rect, 0, 0, 50, 50 );
5970     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5971     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5972     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5973
5974     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5975     pt.x = pt.y = 0;
5976     MapWindowPoints( hchild, hparent, &pt, 1 );
5977     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5978     check_update_rgn( hchild, hrgn );
5979     SetRectRgn( hrgn, 0, 0, 50, 50 );
5980     check_update_rgn( hparent, hrgn );
5981     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5982     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5983     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5984     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5985
5986     flush_events();
5987     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5988
5989     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5990     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5991     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5992     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5993     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5994
5995     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5996     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5997     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5998
5999     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6000     flush_sequence();
6001     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6002     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6003     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6004
6005     /* flush all paint messages */
6006     flush_events();
6007     flush_sequence();
6008
6009     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6010     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6011     SetRectRgn( hrgn, 0, 0, 50, 50 );
6012     check_update_rgn( hparent, hrgn );
6013     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6014     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6015     SetRectRgn( hrgn, 0, 0, 50, 50 );
6016     check_update_rgn( hparent, hrgn );
6017
6018     /* flush all paint messages */
6019     flush_events();
6020     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6021     flush_sequence();
6022
6023     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6024     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6025     SetRectRgn( hrgn, 0, 0, 50, 50 );
6026     check_update_rgn( hparent, hrgn );
6027     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6028     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6029     SetRectRgn( hrgn2, 10, 10, 50, 50 );
6030     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6031     check_update_rgn( hparent, hrgn );
6032     /* flush all paint messages */
6033     flush_events();
6034     flush_sequence();
6035
6036     /* same as above but parent gets completely validated */
6037     SetRect( &rect, 20, 20, 30, 30 );
6038     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6039     SetRectRgn( hrgn, 20, 20, 30, 30 );
6040     check_update_rgn( hparent, hrgn );
6041     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6042     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6043     check_update_rgn( hparent, 0 );  /* no update region */
6044     flush_events();
6045     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
6046
6047     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6048     flush_sequence();
6049     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6050     SetRectRgn( hrgn, 20, 20, 30, 30 );
6051     check_update_rgn( hparent, hrgn );
6052     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6053     SetRectRgn( hrgn, 20, 20, 30, 30 );
6054     check_update_rgn( hparent, hrgn );
6055
6056     /* same as above but normal WM_PAINT doesn't validate parent */
6057     flush_sequence();
6058     SetRect( &rect, 20, 20, 30, 30 );
6059     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6060     SetRectRgn( hrgn, 20, 20, 30, 30 );
6061     check_update_rgn( hparent, hrgn );
6062     /* no WM_PAINT in child while parent still pending */
6063     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6064     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6065     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6066     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6067
6068     flush_sequence();
6069     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6070     /* no WM_PAINT in child while parent still pending */
6071     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6072     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6073     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6074     /* now that parent is valid child should get WM_PAINT */
6075     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6076     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6077     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6078     ok_sequence( WmEmptySeq, "No other message", FALSE );
6079
6080     /* same thing with WS_CLIPCHILDREN in parent */
6081     flush_sequence();
6082     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6083     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6084     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6085     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6086     ok_sequence( WmEmptySeq, "No message", FALSE );
6087     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6088     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6089
6090     flush_sequence();
6091     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6092     SetRectRgn( hrgn, 20, 20, 30, 30 );
6093     check_update_rgn( hparent, hrgn );
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     /* WM_PAINT in parent first */
6098     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6099     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6100
6101     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6102     flush_sequence();
6103     SetRect( &rect, 0, 0, 30, 30 );
6104     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6105     SetRectRgn( hrgn, 0, 0, 30, 30 );
6106     check_update_rgn( hparent, hrgn );
6107     flush_events();
6108     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6109
6110     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6111     flush_sequence();
6112     SetRect( &rect, -10, 0, 30, 30 );
6113     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6114     SetRect( &rect, 0, 0, 20, 20 );
6115     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6116     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6117     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6118
6119     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6120     flush_sequence();
6121     SetRect( &rect, -10, 0, 30, 30 );
6122     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6123     SetRect( &rect, 0, 0, 100, 100 );
6124     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6125     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6126     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6127     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6128     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6129
6130     /* test RDW_INTERNALPAINT behavior */
6131
6132     flush_sequence();
6133     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6134     flush_events();
6135     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6136
6137     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6138     flush_events();
6139     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6140
6141     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6142     flush_events();
6143     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6144
6145     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6146     UpdateWindow( hparent );
6147     flush_events();
6148     flush_sequence();
6149     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6150     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6151     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6152                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6153     flush_events();
6154     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6155
6156     UpdateWindow( hparent );
6157     flush_events();
6158     flush_sequence();
6159     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6160     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6161     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6162                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6163     flush_events();
6164     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6165
6166     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6167     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6168     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6169     flush_events();
6170     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6171
6172     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6173     UpdateWindow( hparent );
6174     flush_events();
6175     flush_sequence();
6176     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6177     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6178     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6179                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6180     flush_events();
6181     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6182
6183     UpdateWindow( hparent );
6184     flush_events();
6185     flush_sequence();
6186     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6187     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6188     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6189                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6190     flush_events();
6191     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6192
6193     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6194     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6195
6196     UpdateWindow( hparent );
6197     flush_events();
6198     flush_sequence();
6199     trace("testing SetWindowPos(-10000, -10000) on child\n");
6200     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6201     check_update_rgn( hchild, 0 );
6202     flush_events();
6203
6204 #if 0 /* this one doesn't pass under Wine yet */
6205     UpdateWindow( hparent );
6206     flush_events();
6207     flush_sequence();
6208     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6209     ShowWindow( hchild, SW_MINIMIZE );
6210     check_update_rgn( hchild, 0 );
6211     flush_events();
6212 #endif
6213
6214     UpdateWindow( hparent );
6215     flush_events();
6216     flush_sequence();
6217     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6218     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6219     check_update_rgn( hparent, 0 );
6220     flush_events();
6221
6222     log_all_parent_messages--;
6223     DestroyWindow( hparent );
6224     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6225
6226     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6227
6228     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6229                               100, 100, 200, 200, 0, 0, 0, NULL);
6230     ok (hparent != 0, "Failed to create parent window\n");
6231
6232     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6233                            10, 10, 100, 100, hparent, 0, 0, NULL);
6234     ok (hchild != 0, "Failed to create child window\n");
6235
6236     ShowWindow( hparent, SW_SHOW );
6237     UpdateWindow( hparent );
6238     UpdateWindow( hchild );
6239     flush_events();
6240     flush_sequence();
6241
6242     /* moving child outside of parent boundaries changes update region */
6243     SetRect( &rect, 0, 0, 40, 40 );
6244     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6245     SetRectRgn( hrgn, 0, 0, 40, 40 );
6246     check_update_rgn( hchild, hrgn );
6247     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6248     SetRectRgn( hrgn, 10, 0, 40, 40 );
6249     check_update_rgn( hchild, hrgn );
6250     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6251     SetRectRgn( hrgn, 10, 10, 40, 40 );
6252     check_update_rgn( hchild, hrgn );
6253
6254     /* moving parent off-screen does too */
6255     SetRect( &rect, 0, 0, 100, 100 );
6256     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6257     SetRectRgn( hrgn, 0, 0, 100, 100 );
6258     check_update_rgn( hparent, hrgn );
6259     SetRectRgn( hrgn, 10, 10, 40, 40 );
6260     check_update_rgn( hchild, hrgn );
6261     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6262     SetRectRgn( hrgn, 20, 20, 100, 100 );
6263     check_update_rgn( hparent, hrgn );
6264     SetRectRgn( hrgn, 30, 30, 40, 40 );
6265     check_update_rgn( hchild, hrgn );
6266
6267     /* invalidated region is cropped by the parent rects */
6268     SetRect( &rect, 0, 0, 50, 50 );
6269     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6270     SetRectRgn( hrgn, 30, 30, 50, 50 );
6271     check_update_rgn( hchild, hrgn );
6272
6273     DestroyWindow( hparent );
6274     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6275     flush_sequence();
6276
6277     DeleteObject( hrgn );
6278     DeleteObject( hrgn2 );
6279 }
6280
6281 struct wnd_event
6282 {
6283     HWND hwnd;
6284     HANDLE event;
6285 };
6286
6287 static DWORD WINAPI thread_proc(void *param)
6288 {
6289     MSG msg;
6290     struct wnd_event *wnd_event = param;
6291
6292     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6293                                       100, 100, 200, 200, 0, 0, 0, NULL);
6294     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6295
6296     SetEvent(wnd_event->event);
6297
6298     while (GetMessage(&msg, 0, 0, 0))
6299     {
6300         TranslateMessage(&msg);
6301         DispatchMessage(&msg);
6302     }
6303
6304     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6305
6306     return 0;
6307 }
6308
6309 static void test_interthread_messages(void)
6310 {
6311     HANDLE hThread;
6312     DWORD tid;
6313     WNDPROC proc;
6314     MSG msg;
6315     char buf[256];
6316     int len, expected_len;
6317     struct wnd_event wnd_event;
6318     BOOL ret;
6319
6320     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6321     if (!wnd_event.event)
6322     {
6323         win_skip("skipping interthread message test under win9x\n");
6324         return;
6325     }
6326
6327     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6328     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6329
6330     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6331
6332     CloseHandle(wnd_event.event);
6333
6334     SetLastError(0xdeadbeef);
6335     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6336     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6337        "wrong error code %d\n", GetLastError());
6338
6339     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6340     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6341
6342     expected_len = lstrlenA("window caption text");
6343     memset(buf, 0, sizeof(buf));
6344     SetLastError(0xdeadbeef);
6345     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6346     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6347     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6348
6349     msg.hwnd = wnd_event.hwnd;
6350     msg.message = WM_GETTEXT;
6351     msg.wParam = sizeof(buf);
6352     msg.lParam = (LPARAM)buf;
6353     memset(buf, 0, sizeof(buf));
6354     SetLastError(0xdeadbeef);
6355     len = DispatchMessageA(&msg);
6356     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6357        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6358
6359     /* the following test causes an exception in user.exe under win9x */
6360     msg.hwnd = wnd_event.hwnd;
6361     msg.message = WM_TIMER;
6362     msg.wParam = 0;
6363     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6364     SetLastError(0xdeadbeef);
6365     len = DispatchMessageA(&msg);
6366     ok(!len && GetLastError() == 0xdeadbeef,
6367        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6368
6369     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6370     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6371
6372     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6373     CloseHandle(hThread);
6374
6375     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6376 }
6377
6378
6379 static const struct message WmVkN[] = {
6380     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6381     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6382     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6383     { WM_CHAR, wparam|lparam, 'n', 1 },
6384     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6385     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6386     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6387     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6388     { 0 }
6389 };
6390 static const struct message WmShiftVkN[] = {
6391     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6392     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6393     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6394     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6395     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6396     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6397     { WM_CHAR, wparam|lparam, 'N', 1 },
6398     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6399     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6400     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6401     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6402     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6403     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6404     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6405     { 0 }
6406 };
6407 static const struct message WmCtrlVkN[] = {
6408     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6409     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6410     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6411     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6412     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6413     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6414     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6415     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6416     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6417     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6418     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6419     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6420     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6421     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6422     { 0 }
6423 };
6424 static const struct message WmCtrlVkN_2[] = {
6425     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6426     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6427     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6428     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6429     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6430     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6431     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6432     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6433     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6434     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6435     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6436     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6437     { 0 }
6438 };
6439 static const struct message WmAltVkN[] = {
6440     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6441     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6442     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6443     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6444     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6445     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6446     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6447     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6448     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6449     { HCBT_SYSCOMMAND, hook },
6450     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6451     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6452     { 0x00AE, sent|defwinproc|optional }, /* XP */
6453     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6454     { WM_INITMENU, sent|defwinproc },
6455     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6456     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6457     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6458     { WM_CAPTURECHANGED, sent|defwinproc },
6459     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6460     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6461     { WM_EXITMENULOOP, sent|defwinproc },
6462     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6463     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6464     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6465     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6466     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6467     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6468     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6469     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6470     { 0 }
6471 };
6472 static const struct message WmAltVkN_2[] = {
6473     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6474     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6475     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6476     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6477     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6478     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6479     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6480     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6481     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6482     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6483     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6484     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6485     { 0 }
6486 };
6487 static const struct message WmCtrlAltVkN[] = {
6488     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6489     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6490     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6491     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6492     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6493     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6494     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6495     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6496     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6497     { WM_CHAR, optional },
6498     { WM_CHAR, sent|optional },
6499     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6500     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6501     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6502     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6503     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6504     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6505     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6506     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6507     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6508     { 0 }
6509 };
6510 static const struct message WmCtrlShiftVkN[] = {
6511     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6512     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6513     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6514     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6515     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6516     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6517     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6518     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6519     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6520     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6521     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6522     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6523     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6524     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6525     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6526     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6527     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6528     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6529     { 0 }
6530 };
6531 static const struct message WmCtrlAltShiftVkN[] = {
6532     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6533     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6534     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6535     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6536     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6537     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6538     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6539     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6540     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6541     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6542     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6543     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6544     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6545     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6546     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6547     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6548     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6549     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6550     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6551     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6552     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6553     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6554     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6555     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6556     { 0 }
6557 };
6558 static const struct message WmAltPressRelease[] = {
6559     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6560     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6561     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6562     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6563     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6564     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6565     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6566     { HCBT_SYSCOMMAND, hook },
6567     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6568     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6569     { WM_INITMENU, sent|defwinproc },
6570     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6571     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6572     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6573
6574     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6575
6576     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6577     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6578     { WM_CAPTURECHANGED, sent|defwinproc },
6579     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6580     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6581     { WM_EXITMENULOOP, sent|defwinproc },
6582     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6583     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6584     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6585     { 0 }
6586 };
6587 static const struct message WmShiftMouseButton[] = {
6588     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6589     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6590     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6591     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6592     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6593     { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6594     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6595     { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6596     { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6597     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6598     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6599     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6600     { 0 }
6601 };
6602 static const struct message WmF1Seq[] = {
6603     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6604     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6605     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6606     { WM_KEYF1, wparam|lparam, 0, 0 },
6607     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6608     { WM_HELP, sent|defwinproc },
6609     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6610     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6611     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6612     { 0 }
6613 };
6614 static const struct message WmVkAppsSeq[] = {
6615     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6616     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6617     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6618     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6619     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6620     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6621     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6622     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6623     { 0 }
6624 };
6625
6626 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6627 {
6628     MSG msg;
6629
6630     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6631     {
6632         struct recvd_message log_msg;
6633
6634         /* ignore some unwanted messages */
6635         if (msg.message == WM_MOUSEMOVE ||
6636             msg.message == WM_GETICON ||
6637             msg.message == WM_GETOBJECT ||
6638             msg.message == WM_TIMER ||
6639             msg.message == WM_DEVICECHANGE)
6640             continue;
6641
6642         log_msg.hwnd = msg.hwnd;
6643         log_msg.message = msg.message;
6644         log_msg.flags = wparam|lparam;
6645         log_msg.wParam = msg.wParam;
6646         log_msg.lParam = msg.lParam;
6647         log_msg.descr = "accel";
6648         add_message(&log_msg);
6649
6650         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6651         {
6652             TranslateMessage(&msg);
6653             DispatchMessage(&msg);
6654         }
6655     }
6656 }
6657
6658 static void test_accelerators(void)
6659 {
6660     RECT rc;
6661     POINT pt;
6662     SHORT state;
6663     HACCEL hAccel;
6664     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6665                                 100, 100, 200, 200, 0, 0, 0, NULL);
6666     BOOL ret;
6667
6668     assert(hwnd != 0);
6669     UpdateWindow(hwnd);
6670     flush_events();
6671     flush_sequence();
6672
6673     SetFocus(hwnd);
6674     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6675
6676     state = GetKeyState(VK_SHIFT);
6677     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6678     state = GetKeyState(VK_CAPITAL);
6679     ok(state == 0, "wrong CapsLock state %04x\n", state);
6680
6681     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6682     assert(hAccel != 0);
6683
6684     flush_events();
6685     pump_msg_loop(hwnd, 0);
6686     flush_sequence();
6687
6688     trace("testing VK_N press/release\n");
6689     flush_sequence();
6690     keybd_event('N', 0, 0, 0);
6691     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6692     pump_msg_loop(hwnd, hAccel);
6693     if (!sequence_cnt)  /* we didn't get any message */
6694     {
6695         skip( "queuing key events not supported\n" );
6696         goto done;
6697     }
6698     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6699
6700     trace("testing Shift+VK_N press/release\n");
6701     flush_sequence();
6702     keybd_event(VK_SHIFT, 0, 0, 0);
6703     keybd_event('N', 0, 0, 0);
6704     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6705     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6706     pump_msg_loop(hwnd, hAccel);
6707     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6708
6709     trace("testing Ctrl+VK_N press/release\n");
6710     flush_sequence();
6711     keybd_event(VK_CONTROL, 0, 0, 0);
6712     keybd_event('N', 0, 0, 0);
6713     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6714     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6715     pump_msg_loop(hwnd, hAccel);
6716     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6717
6718     trace("testing Alt+VK_N press/release\n");
6719     flush_sequence();
6720     keybd_event(VK_MENU, 0, 0, 0);
6721     keybd_event('N', 0, 0, 0);
6722     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6723     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6724     pump_msg_loop(hwnd, hAccel);
6725     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6726
6727     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6728     flush_sequence();
6729     keybd_event(VK_CONTROL, 0, 0, 0);
6730     keybd_event(VK_MENU, 0, 0, 0);
6731     keybd_event('N', 0, 0, 0);
6732     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6733     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6734     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6735     pump_msg_loop(hwnd, hAccel);
6736     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6737
6738     ret = DestroyAcceleratorTable(hAccel);
6739     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6740
6741     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6742     assert(hAccel != 0);
6743
6744     trace("testing VK_N press/release\n");
6745     flush_sequence();
6746     keybd_event('N', 0, 0, 0);
6747     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6748     pump_msg_loop(hwnd, hAccel);
6749     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6750
6751     trace("testing Shift+VK_N press/release\n");
6752     flush_sequence();
6753     keybd_event(VK_SHIFT, 0, 0, 0);
6754     keybd_event('N', 0, 0, 0);
6755     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6756     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6757     pump_msg_loop(hwnd, hAccel);
6758     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6759
6760     trace("testing Ctrl+VK_N press/release 2\n");
6761     flush_sequence();
6762     keybd_event(VK_CONTROL, 0, 0, 0);
6763     keybd_event('N', 0, 0, 0);
6764     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6765     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6766     pump_msg_loop(hwnd, hAccel);
6767     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6768
6769     trace("testing Alt+VK_N press/release 2\n");
6770     flush_sequence();
6771     keybd_event(VK_MENU, 0, 0, 0);
6772     keybd_event('N', 0, 0, 0);
6773     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6774     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6775     pump_msg_loop(hwnd, hAccel);
6776     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6777
6778     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6779     flush_sequence();
6780     keybd_event(VK_CONTROL, 0, 0, 0);
6781     keybd_event(VK_MENU, 0, 0, 0);
6782     keybd_event('N', 0, 0, 0);
6783     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6784     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6785     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6786     pump_msg_loop(hwnd, hAccel);
6787     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6788
6789     trace("testing Ctrl+Shift+VK_N press/release\n");
6790     flush_sequence();
6791     keybd_event(VK_CONTROL, 0, 0, 0);
6792     keybd_event(VK_SHIFT, 0, 0, 0);
6793     keybd_event('N', 0, 0, 0);
6794     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6795     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6796     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6797     pump_msg_loop(hwnd, hAccel);
6798     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6799
6800     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6801     flush_sequence();
6802     keybd_event(VK_CONTROL, 0, 0, 0);
6803     keybd_event(VK_MENU, 0, 0, 0);
6804     keybd_event(VK_SHIFT, 0, 0, 0);
6805     keybd_event('N', 0, 0, 0);
6806     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6807     keybd_event(VK_SHIFT, 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(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6812
6813     ret = DestroyAcceleratorTable(hAccel);
6814     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6815     hAccel = 0;
6816
6817     trace("testing Alt press/release\n");
6818     flush_sequence();
6819     keybd_event(VK_MENU, 0, 0, 0);
6820     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6821     keybd_event(VK_MENU, 0, 0, 0);
6822     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6823     pump_msg_loop(hwnd, 0);
6824     /* this test doesn't pass in Wine for managed windows */
6825     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6826
6827     trace("testing VK_F1 press/release\n");
6828     keybd_event(VK_F1, 0, 0, 0);
6829     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6830     pump_msg_loop(hwnd, 0);
6831     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6832
6833     trace("testing VK_APPS press/release\n");
6834     keybd_event(VK_APPS, 0, 0, 0);
6835     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6836     pump_msg_loop(hwnd, 0);
6837     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6838
6839     trace("testing Shift+MouseButton press/release\n");
6840     /* first, move mouse pointer inside of the window client area */
6841     GetClientRect(hwnd, &rc);
6842     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6843     rc.left += (rc.right - rc.left)/2;
6844     rc.top += (rc.bottom - rc.top)/2;
6845     SetCursorPos(rc.left, rc.top);
6846     SetActiveWindow(hwnd);
6847
6848     flush_events();
6849     flush_sequence();
6850     GetCursorPos(&pt);
6851     if (pt.x == rc.left && pt.y == rc.top)
6852     {
6853         int i;
6854         keybd_event(VK_SHIFT, 0, 0, 0);
6855         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6856         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6857         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6858         pump_msg_loop(hwnd, 0);
6859         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
6860         if (i < sequence_cnt)
6861             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
6862         else
6863             skip( "Shift+MouseButton event didn't get to the window\n" );
6864     }
6865
6866 done:
6867     if (hAccel) DestroyAcceleratorTable(hAccel);
6868     DestroyWindow(hwnd);
6869 }
6870
6871 /************* window procedures ********************/
6872
6873 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6874                              WPARAM wParam, LPARAM lParam)
6875 {
6876     static long defwndproc_counter = 0;
6877     static long beginpaint_counter = 0;
6878     LRESULT ret;
6879     struct recvd_message msg;
6880
6881     /* ignore registered messages */
6882     if (message >= 0xc000) return 0;
6883
6884     switch (message)
6885     {
6886         case WM_ENABLE:
6887         {
6888             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6889             ok((BOOL)wParam == !(style & WS_DISABLED),
6890                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6891             break;
6892         }
6893
6894         case WM_CAPTURECHANGED:
6895             if (test_DestroyWindow_flag)
6896             {
6897                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6898                 if (style & WS_CHILD)
6899                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6900                 else if (style & WS_POPUP)
6901                     lParam = WND_POPUP_ID;
6902                 else
6903                     lParam = WND_PARENT_ID;
6904             }
6905             break;
6906
6907         case WM_NCDESTROY:
6908         {
6909             HWND capture;
6910
6911             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6912             capture = GetCapture();
6913             if (capture)
6914             {
6915                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6916                 trace("current capture %p, releasing...\n", capture);
6917                 ReleaseCapture();
6918             }
6919         }
6920         /* fall through */
6921         case WM_DESTROY:
6922             if (pGetAncestor)
6923                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6924             if (test_DestroyWindow_flag)
6925             {
6926                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6927                 if (style & WS_CHILD)
6928                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6929                 else if (style & WS_POPUP)
6930                     lParam = WND_POPUP_ID;
6931                 else
6932                     lParam = WND_PARENT_ID;
6933             }
6934             break;
6935
6936         /* test_accelerators() depends on this */
6937         case WM_NCHITTEST:
6938             return HTCLIENT;
6939
6940         /* ignore */
6941         case WM_MOUSEMOVE:
6942         case WM_MOUSEACTIVATE:
6943         case WM_NCMOUSEMOVE:
6944         case WM_SETCURSOR:
6945         case WM_GETICON:
6946         case WM_GETOBJECT:
6947         case WM_DEVICECHANGE:
6948         case WM_IME_SELECT:
6949             return 0;
6950     }
6951
6952     msg.hwnd = hwnd;
6953     msg.message = message;
6954     msg.flags = sent|wparam|lparam;
6955     if (defwndproc_counter) msg.flags |= defwinproc;
6956     if (beginpaint_counter) msg.flags |= beginpaint;
6957     msg.wParam = wParam;
6958     msg.lParam = lParam;
6959     msg.descr = "MsgCheckProc";
6960     add_message(&msg);
6961
6962     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6963     {
6964         HWND parent = GetParent(hwnd);
6965         RECT rc;
6966         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6967
6968         GetClientRect(parent, &rc);
6969         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6970         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6971               minmax->ptReserved.x, minmax->ptReserved.y,
6972               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6973               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6974               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6975               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6976
6977         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6978            minmax->ptMaxSize.x, rc.right);
6979         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6980            minmax->ptMaxSize.y, rc.bottom);
6981     }
6982
6983     if (message == WM_PAINT)
6984     {
6985         PAINTSTRUCT ps;
6986         beginpaint_counter++;
6987         BeginPaint( hwnd, &ps );
6988         beginpaint_counter--;
6989         EndPaint( hwnd, &ps );
6990         return 0;
6991     }
6992
6993     defwndproc_counter++;
6994     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6995                   : DefWindowProcA(hwnd, message, wParam, lParam);
6996     defwndproc_counter--;
6997
6998     return ret;
6999 }
7000
7001 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7002 {
7003     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7004 }
7005
7006 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7007 {
7008     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7009 }
7010
7011 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7012 {
7013     static long defwndproc_counter = 0;
7014     LRESULT ret;
7015     struct recvd_message msg;
7016
7017     switch (message)
7018     {
7019     case WM_GETICON:
7020     case WM_GETOBJECT:
7021         return 0;  /* ignore them */
7022     case WM_QUERYENDSESSION:
7023     case WM_ENDSESSION:
7024         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7025         break;
7026     }
7027
7028     msg.hwnd = hwnd;
7029     msg.message = message;
7030     msg.flags = sent|wparam|lparam;
7031     if (defwndproc_counter) msg.flags |= defwinproc;
7032     msg.wParam = wParam;
7033     msg.lParam = lParam;
7034     msg.descr = "popup";
7035     add_message(&msg);
7036
7037     if (message == WM_CREATE)
7038     {
7039         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7040         SetWindowLongA(hwnd, GWL_STYLE, style);
7041     }
7042
7043     defwndproc_counter++;
7044     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7045     defwndproc_counter--;
7046
7047     return ret;
7048 }
7049
7050 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7051 {
7052     static long defwndproc_counter = 0;
7053     static long beginpaint_counter = 0;
7054     LRESULT ret;
7055     struct recvd_message msg;
7056
7057     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7058
7059     /* ignore registered messages */
7060     if (message >= 0xc000) return 0;
7061
7062     if (log_all_parent_messages ||
7063         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7064         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7065         message == WM_ENABLE || message == WM_ENTERIDLE ||
7066         message == WM_DRAWITEM ||
7067         message == WM_IME_SETCONTEXT)
7068     {
7069         switch (message)
7070         {
7071             /* ignore */
7072             case WM_NCHITTEST:
7073                 return HTCLIENT;
7074             case WM_SETCURSOR:
7075             case WM_MOUSEMOVE:
7076             case WM_NCMOUSEMOVE:
7077                 return 0;
7078
7079             case WM_ERASEBKGND:
7080             {
7081                 RECT rc;
7082                 INT ret = GetClipBox((HDC)wParam, &rc);
7083
7084                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7085                        ret, rc.left, rc.top, rc.right, rc.bottom);
7086                 break;
7087             }
7088         }
7089
7090         msg.hwnd = hwnd;
7091         msg.message = message;
7092         msg.flags = sent|parent|wparam|lparam;
7093         if (defwndproc_counter) msg.flags |= defwinproc;
7094         if (beginpaint_counter) msg.flags |= beginpaint;
7095         msg.wParam = wParam;
7096         msg.lParam = lParam;
7097         msg.descr = "parent";
7098         add_message(&msg);
7099     }
7100
7101     if (message == WM_PAINT)
7102     {
7103         PAINTSTRUCT ps;
7104         beginpaint_counter++;
7105         BeginPaint( hwnd, &ps );
7106         beginpaint_counter--;
7107         EndPaint( hwnd, &ps );
7108         return 0;
7109     }
7110
7111     defwndproc_counter++;
7112     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7113     defwndproc_counter--;
7114
7115     return ret;
7116 }
7117
7118 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7119 {
7120     static long defwndproc_counter = 0;
7121     LRESULT ret;
7122     struct recvd_message msg;
7123
7124     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7125
7126     if (test_def_id)
7127     {
7128         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7129         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7130         if (after_end_dialog)
7131             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7132         else
7133             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7134     }
7135
7136     msg.hwnd = hwnd;
7137     msg.message = message;
7138     msg.flags = sent|wparam|lparam;
7139     if (defwndproc_counter) msg.flags |= defwinproc;
7140     msg.wParam = wParam;
7141     msg.lParam = lParam;
7142     msg.descr = "dialog";
7143     add_message(&msg);
7144
7145     defwndproc_counter++;
7146     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7147     defwndproc_counter--;
7148
7149     return ret;
7150 }
7151
7152 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7153 {
7154     static long defwndproc_counter = 0;
7155     LRESULT ret;
7156     struct recvd_message msg;
7157
7158     /* log only specific messages we are interested in */
7159     switch (message)
7160     {
7161 #if 0 /* probably log these as well */
7162     case WM_ACTIVATE:
7163     case WM_SETFOCUS:
7164     case WM_KILLFOCUS:
7165 #endif
7166     case WM_SHOWWINDOW:
7167     case WM_SIZE:
7168     case WM_MOVE:
7169     case WM_GETMINMAXINFO:
7170     case WM_WINDOWPOSCHANGING:
7171     case WM_WINDOWPOSCHANGED:
7172         break;
7173
7174     default: /* ignore */
7175         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7176         return DefWindowProcA(hwnd, message, wParam, lParam);
7177     }
7178
7179     msg.hwnd = hwnd;
7180     msg.message = message;
7181     msg.flags = sent|wparam|lparam;
7182     if (defwndproc_counter) msg.flags |= defwinproc;
7183     msg.wParam = wParam;
7184     msg.lParam = lParam;
7185     msg.descr = "show";
7186     add_message(&msg);
7187
7188     defwndproc_counter++;
7189     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7190     defwndproc_counter--;
7191
7192     return ret;
7193 }
7194
7195 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7196 {
7197     switch (msg)
7198     {
7199         case WM_CREATE: return 0;
7200         case WM_PAINT:
7201         {
7202             MSG msg2;
7203             static int i = 0;
7204
7205             if (i < 256)
7206             {
7207                 i++;
7208                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7209                 {
7210                     TranslateMessage(&msg2);
7211                     DispatchMessage(&msg2);
7212                 }
7213                 i--;
7214             }
7215             else ok(broken(1), "infinite loop\n");
7216             if ( i == 0)
7217                 paint_loop_done = 1;
7218             return DefWindowProcA(hWnd,msg,wParam,lParam);
7219         }
7220     }
7221     return DefWindowProcA(hWnd,msg,wParam,lParam);
7222 }
7223
7224 static BOOL RegisterWindowClasses(void)
7225 {
7226     WNDCLASSA cls;
7227     WNDCLASSW clsW;
7228
7229     cls.style = 0;
7230     cls.lpfnWndProc = MsgCheckProcA;
7231     cls.cbClsExtra = 0;
7232     cls.cbWndExtra = 0;
7233     cls.hInstance = GetModuleHandleA(0);
7234     cls.hIcon = 0;
7235     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7236     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7237     cls.lpszMenuName = NULL;
7238     cls.lpszClassName = "TestWindowClass";
7239     if(!RegisterClassA(&cls)) return FALSE;
7240
7241     cls.lpfnWndProc = ShowWindowProcA;
7242     cls.lpszClassName = "ShowWindowClass";
7243     if(!RegisterClassA(&cls)) return FALSE;
7244
7245     cls.lpfnWndProc = PopupMsgCheckProcA;
7246     cls.lpszClassName = "TestPopupClass";
7247     if(!RegisterClassA(&cls)) return FALSE;
7248
7249     cls.lpfnWndProc = ParentMsgCheckProcA;
7250     cls.lpszClassName = "TestParentClass";
7251     if(!RegisterClassA(&cls)) return FALSE;
7252
7253     cls.lpfnWndProc = DefWindowProcA;
7254     cls.lpszClassName = "SimpleWindowClass";
7255     if(!RegisterClassA(&cls)) return FALSE;
7256
7257     cls.lpfnWndProc = PaintLoopProcA;
7258     cls.lpszClassName = "PaintLoopWindowClass";
7259     if(!RegisterClassA(&cls)) return FALSE;
7260
7261     cls.style = CS_NOCLOSE;
7262     cls.lpszClassName = "NoCloseWindowClass";
7263     if(!RegisterClassA(&cls)) return FALSE;
7264
7265     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7266     cls.style = 0;
7267     cls.hInstance = GetModuleHandleA(0);
7268     cls.hbrBackground = 0;
7269     cls.lpfnWndProc = TestDlgProcA;
7270     cls.lpszClassName = "TestDialogClass";
7271     if(!RegisterClassA(&cls)) return FALSE;
7272
7273     clsW.style = 0;
7274     clsW.lpfnWndProc = MsgCheckProcW;
7275     clsW.cbClsExtra = 0;
7276     clsW.cbWndExtra = 0;
7277     clsW.hInstance = GetModuleHandleW(0);
7278     clsW.hIcon = 0;
7279     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7280     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7281     clsW.lpszMenuName = NULL;
7282     clsW.lpszClassName = testWindowClassW;
7283     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7284
7285     return TRUE;
7286 }
7287
7288 static BOOL is_our_logged_class(HWND hwnd)
7289 {
7290     char buf[256];
7291
7292     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7293     {
7294         if (!lstrcmpiA(buf, "TestWindowClass") ||
7295             !lstrcmpiA(buf, "ShowWindowClass") ||
7296             !lstrcmpiA(buf, "TestParentClass") ||
7297             !lstrcmpiA(buf, "TestPopupClass") ||
7298             !lstrcmpiA(buf, "SimpleWindowClass") ||
7299             !lstrcmpiA(buf, "TestDialogClass") ||
7300             !lstrcmpiA(buf, "MDI_frame_class") ||
7301             !lstrcmpiA(buf, "MDI_client_class") ||
7302             !lstrcmpiA(buf, "MDI_child_class") ||
7303             !lstrcmpiA(buf, "my_button_class") ||
7304             !lstrcmpiA(buf, "my_edit_class") ||
7305             !lstrcmpiA(buf, "static") ||
7306             !lstrcmpiA(buf, "ListBox") ||
7307             !lstrcmpiA(buf, "ComboBox") ||
7308             !lstrcmpiA(buf, "MyDialogClass") ||
7309             !lstrcmpiA(buf, "#32770") ||
7310             !lstrcmpiA(buf, "#32768"))
7311         return TRUE;
7312     }
7313     return FALSE;
7314 }
7315
7316 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7317
7318     HWND hwnd;
7319
7320     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7321
7322     if (nCode == HCBT_CLICKSKIPPED)
7323     {
7324         /* ignore this event, XP sends it a lot when switching focus between windows */
7325         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7326     }
7327
7328     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7329     {
7330         struct recvd_message msg;
7331
7332         msg.hwnd = 0;
7333         msg.message = nCode;
7334         msg.flags = hook|wparam|lparam;
7335         msg.wParam = wParam;
7336         msg.lParam = lParam;
7337         msg.descr = "CBT";
7338         add_message(&msg);
7339
7340         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7341     }
7342
7343     if (nCode == HCBT_DESTROYWND)
7344     {
7345         if (test_DestroyWindow_flag)
7346         {
7347             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7348             if (style & WS_CHILD)
7349                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7350             else if (style & WS_POPUP)
7351                 lParam = WND_POPUP_ID;
7352             else
7353                 lParam = WND_PARENT_ID;
7354         }
7355     }
7356
7357     /* Log also SetFocus(0) calls */
7358     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7359
7360     if (is_our_logged_class(hwnd))
7361     {
7362         struct recvd_message msg;
7363
7364         msg.hwnd = hwnd;
7365         msg.message = nCode;
7366         msg.flags = hook|wparam|lparam;
7367         msg.wParam = wParam;
7368         msg.lParam = lParam;
7369         msg.descr = "CBT";
7370         add_message(&msg);
7371     }
7372     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7373 }
7374
7375 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7376                                     DWORD event,
7377                                     HWND hwnd,
7378                                     LONG object_id,
7379                                     LONG child_id,
7380                                     DWORD thread_id,
7381                                     DWORD event_time)
7382 {
7383     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7384
7385     /* ignore mouse cursor events */
7386     if (object_id == OBJID_CURSOR) return;
7387
7388     if (!hwnd || is_our_logged_class(hwnd))
7389     {
7390         struct recvd_message msg;
7391
7392         msg.hwnd = hwnd;
7393         msg.message = event;
7394         msg.flags = winevent_hook|wparam|lparam;
7395         msg.wParam = object_id;
7396         msg.lParam = child_id;
7397         msg.descr = "WEH";
7398         add_message(&msg);
7399     }
7400 }
7401
7402 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7403 static const WCHAR wszAnsi[] = {'U',0};
7404
7405 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7406 {
7407     switch (uMsg)
7408     {
7409     case CB_FINDSTRINGEXACT:
7410         trace("String: %p\n", (LPCWSTR)lParam);
7411         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7412             return 1;
7413         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7414             return 0;
7415         return -1;
7416     }
7417     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7418 }
7419
7420 static const struct message WmGetTextLengthAfromW[] = {
7421     { WM_GETTEXTLENGTH, sent },
7422     { WM_GETTEXT, sent|optional },
7423     { 0 }
7424 };
7425
7426 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7427
7428 /* dummy window proc for WM_GETTEXTLENGTH test */
7429 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7430 {
7431     switch(msg)
7432     {
7433     case WM_GETTEXTLENGTH:
7434         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7435     case WM_GETTEXT:
7436         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7437         return lstrlenW( (LPWSTR)lp );
7438     default:
7439         return DefWindowProcW( hwnd, msg, wp, lp );
7440     }
7441 }
7442
7443 static void test_message_conversion(void)
7444 {
7445     static const WCHAR wszMsgConversionClass[] =
7446         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7447     WNDCLASSW cls;
7448     LRESULT lRes;
7449     HWND hwnd;
7450     WNDPROC wndproc, newproc;
7451     BOOL ret;
7452
7453     cls.style = 0;
7454     cls.lpfnWndProc = MsgConversionProcW;
7455     cls.cbClsExtra = 0;
7456     cls.cbWndExtra = 0;
7457     cls.hInstance = GetModuleHandleW(NULL);
7458     cls.hIcon = NULL;
7459     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7460     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7461     cls.lpszMenuName = NULL;
7462     cls.lpszClassName = wszMsgConversionClass;
7463     /* this call will fail on Win9x, but that doesn't matter as this test is
7464      * meaningless on those platforms */
7465     if(!RegisterClassW(&cls)) return;
7466
7467     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7468                            100, 100, 200, 200, 0, 0, 0, NULL);
7469     ok(hwnd != NULL, "Window creation failed\n");
7470
7471     /* {W, A} -> A */
7472
7473     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7474     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7475     ok(lRes == 0, "String should have been converted\n");
7476     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7477     ok(lRes == 1, "String shouldn't have been converted\n");
7478
7479     /* {W, A} -> W */
7480
7481     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7482     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7483     ok(lRes == 1, "String shouldn't have been converted\n");
7484     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7485     ok(lRes == 1, "String shouldn't have been converted\n");
7486
7487     /* Synchronous messages */
7488
7489     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7490     ok(lRes == 0, "String should have been converted\n");
7491     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7492     ok(lRes == 1, "String shouldn't have been converted\n");
7493
7494     /* Asynchronous messages */
7495
7496     SetLastError(0);
7497     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7498     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7499         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7500     SetLastError(0);
7501     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7502     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7503         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7504     SetLastError(0);
7505     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7506     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7507         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7508     SetLastError(0);
7509     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7510     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7511         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7512     SetLastError(0);
7513     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7514     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7515         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7516     SetLastError(0);
7517     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7518     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7519         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7520     SetLastError(0);
7521     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7522     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7523         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7524     SetLastError(0);
7525     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7526     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7527         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7528
7529     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7530
7531     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7532                           WS_OVERLAPPEDWINDOW,
7533                           100, 100, 200, 200, 0, 0, 0, NULL);
7534     assert(hwnd);
7535     flush_sequence();
7536     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7537     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7538     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7539         "got bad length %ld\n", lRes );
7540
7541     flush_sequence();
7542     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7543                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7544     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7545     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7546         "got bad length %ld\n", lRes );
7547
7548     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7549     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7550     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7551     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7552                                      NULL, 0, NULL, NULL ) ||
7553         broken(lRes == lstrlenW(dummy_window_text) + 37),
7554         "got bad length %ld\n", lRes );
7555
7556     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7557     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7558     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7559                                      NULL, 0, NULL, NULL ) ||
7560         broken(lRes == lstrlenW(dummy_window_text) + 37),
7561         "got bad length %ld\n", lRes );
7562
7563     ret = DestroyWindow(hwnd);
7564     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7565 }
7566
7567 struct timer_info
7568 {
7569     HWND hWnd;
7570     HANDLE handles[2];
7571     DWORD id;
7572 };
7573
7574 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7575 {
7576 }
7577
7578 #define TIMER_ID  0x19
7579
7580 static DWORD WINAPI timer_thread_proc(LPVOID x)
7581 {
7582     struct timer_info *info = x;
7583     DWORD r;
7584
7585     r = KillTimer(info->hWnd, 0x19);
7586     ok(r,"KillTimer failed in thread\n");
7587     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7588     ok(r,"SetTimer failed in thread\n");
7589     ok(r==TIMER_ID,"SetTimer id different\n");
7590     r = SetEvent(info->handles[0]);
7591     ok(r,"SetEvent failed in thread\n");
7592     return 0;
7593 }
7594
7595 static void test_timers(void)
7596 {
7597     struct timer_info info;
7598     DWORD id;
7599
7600     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7601        WS_OVERLAPPEDWINDOW ,
7602        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7603        NULL, NULL, 0);
7604
7605     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7606     ok(info.id, "SetTimer failed\n");
7607     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7608     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7609     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7610
7611     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7612
7613     WaitForSingleObject(info.handles[1], INFINITE);
7614
7615     CloseHandle(info.handles[0]);
7616     CloseHandle(info.handles[1]);
7617
7618     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7619
7620     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7621 }
7622
7623 static int count = 0;
7624 static VOID CALLBACK callback_count(
7625     HWND hwnd,
7626     UINT uMsg,
7627     UINT_PTR idEvent,
7628     DWORD dwTime
7629 )
7630 {
7631     count++;
7632 }
7633
7634 static void test_timers_no_wnd(void)
7635 {
7636     UINT_PTR id, id2;
7637     MSG msg;
7638
7639     count = 0;
7640     id = SetTimer(NULL, 0, 100, callback_count);
7641     ok(id != 0, "did not get id from SetTimer.\n");
7642     id2 = SetTimer(NULL, id, 200, callback_count);
7643     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7644     Sleep(150);
7645     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7646     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7647     Sleep(150);
7648     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7649     ok(count == 1, "did not get one count as expected (%i).\n", count);
7650     KillTimer(NULL, id);
7651     Sleep(250);
7652     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7653     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7654 }
7655
7656 /* Various win events with arbitrary parameters */
7657 static const struct message WmWinEventsSeq[] = {
7658     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7659     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7660     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7661     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7662     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7663     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7664     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7665     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7666     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7667     /* our win event hook ignores OBJID_CURSOR events */
7668     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7669     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7670     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7671     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7672     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7673     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7674     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7675     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7676     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7677     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7678     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7679     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7680     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7681     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7682     { 0 }
7683 };
7684 static const struct message WmWinEventCaretSeq[] = {
7685     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7686     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7687     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7688     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7689     { 0 }
7690 };
7691 static const struct message WmWinEventCaretSeq_2[] = {
7692     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7693     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7694     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7695     { 0 }
7696 };
7697 static const struct message WmWinEventAlertSeq[] = {
7698     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7699     { 0 }
7700 };
7701 static const struct message WmWinEventAlertSeq_2[] = {
7702     /* create window in the thread proc */
7703     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7704     /* our test event */
7705     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7706     { 0 }
7707 };
7708 static const struct message WmGlobalHookSeq_1[] = {
7709     /* create window in the thread proc */
7710     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7711     /* our test events */
7712     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7713     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7714     { 0 }
7715 };
7716 static const struct message WmGlobalHookSeq_2[] = {
7717     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7718     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7719     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7720     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7721     { 0 }
7722 };
7723
7724 static const struct message WmMouseLLHookSeq[] = {
7725     { WM_MOUSEMOVE, hook },
7726     { WM_LBUTTONUP, hook },
7727     { WM_MOUSEMOVE, hook },
7728     { 0 }
7729 };
7730
7731 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7732                                          DWORD event,
7733                                          HWND hwnd,
7734                                          LONG object_id,
7735                                          LONG child_id,
7736                                          DWORD thread_id,
7737                                          DWORD event_time)
7738 {
7739     char buf[256];
7740
7741     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7742     {
7743         if (!lstrcmpiA(buf, "TestWindowClass") ||
7744             !lstrcmpiA(buf, "static"))
7745         {
7746             struct recvd_message msg;
7747
7748             msg.hwnd = hwnd;
7749             msg.message = event;
7750             msg.flags = winevent_hook|wparam|lparam;
7751             msg.wParam = object_id;
7752             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7753             msg.descr = "WEH_2";
7754             add_message(&msg);
7755         }
7756     }
7757 }
7758
7759 static HHOOK hCBT_global_hook;
7760 static DWORD cbt_global_hook_thread_id;
7761
7762 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7763
7764     HWND hwnd;
7765     char buf[256];
7766
7767     if (nCode == HCBT_SYSCOMMAND)
7768     {
7769         struct recvd_message msg;
7770
7771         msg.hwnd = 0;
7772         msg.message = nCode;
7773         msg.flags = hook|wparam|lparam;
7774         msg.wParam = wParam;
7775         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7776         msg.descr = "CBT_2";
7777         add_message(&msg);
7778
7779         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7780     }
7781     /* WH_MOUSE_LL hook */
7782     if (nCode == HC_ACTION)
7783     {
7784         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7785
7786         /* we can't test for real mouse events */
7787         if (mhll->flags & LLMHF_INJECTED)
7788         {
7789             struct recvd_message msg;
7790
7791             memset (&msg, 0, sizeof (msg));
7792             msg.message = wParam;
7793             msg.flags = hook;
7794             msg.descr = "CBT_2";
7795             add_message(&msg);
7796         }
7797         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7798     }
7799
7800     /* Log also SetFocus(0) calls */
7801     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7802
7803     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7804     {
7805         if (!lstrcmpiA(buf, "TestWindowClass") ||
7806             !lstrcmpiA(buf, "static"))
7807         {
7808             struct recvd_message msg;
7809
7810             msg.hwnd = hwnd;
7811             msg.message = nCode;
7812             msg.flags = hook|wparam|lparam;
7813             msg.wParam = wParam;
7814             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7815             msg.descr = "CBT_2";
7816             add_message(&msg);
7817         }
7818     }
7819     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7820 }
7821
7822 static DWORD WINAPI win_event_global_thread_proc(void *param)
7823 {
7824     HWND hwnd;
7825     MSG msg;
7826     HANDLE hevent = *(HANDLE *)param;
7827
7828     assert(pNotifyWinEvent);
7829
7830     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7831     assert(hwnd);
7832     trace("created thread window %p\n", hwnd);
7833
7834     *(HWND *)param = hwnd;
7835
7836     flush_sequence();
7837     /* this event should be received only by our new hook proc,
7838      * an old one does not expect an event from another thread.
7839      */
7840     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7841     SetEvent(hevent);
7842
7843     while (GetMessage(&msg, 0, 0, 0))
7844     {
7845         TranslateMessage(&msg);
7846         DispatchMessage(&msg);
7847     }
7848     return 0;
7849 }
7850
7851 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7852 {
7853     HWND hwnd;
7854     MSG msg;
7855     HANDLE hevent = *(HANDLE *)param;
7856
7857     flush_sequence();
7858     /* these events should be received only by our new hook proc,
7859      * an old one does not expect an event from another thread.
7860      */
7861
7862     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7863     assert(hwnd);
7864     trace("created thread window %p\n", hwnd);
7865
7866     *(HWND *)param = hwnd;
7867
7868     /* Windows doesn't like when a thread plays games with the focus,
7869        that leads to all kinds of misbehaviours and failures to activate
7870        a window. So, better keep next lines commented out.
7871     SetFocus(0);
7872     SetFocus(hwnd);*/
7873
7874     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7875     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7876
7877     SetEvent(hevent);
7878
7879     while (GetMessage(&msg, 0, 0, 0))
7880     {
7881         TranslateMessage(&msg);
7882         DispatchMessage(&msg);
7883     }
7884     return 0;
7885 }
7886
7887 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7888 {
7889     HWND hwnd;
7890     MSG msg;
7891     HANDLE hevent = *(HANDLE *)param;
7892
7893     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7894     assert(hwnd);
7895     trace("created thread window %p\n", hwnd);
7896
7897     *(HWND *)param = hwnd;
7898
7899     flush_sequence();
7900
7901     /* Windows doesn't like when a thread plays games with the focus,
7902      * that leads to all kinds of misbehaviours and failures to activate
7903      * a window. So, better don't generate a mouse click message below.
7904      */
7905     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7906     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7907     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7908
7909     SetEvent(hevent);
7910     while (GetMessage(&msg, 0, 0, 0))
7911     {
7912         TranslateMessage(&msg);
7913         DispatchMessage(&msg);
7914     }
7915     return 0;
7916 }
7917
7918 static void test_winevents(void)
7919 {
7920     BOOL ret;
7921     MSG msg;
7922     HWND hwnd, hwnd2;
7923     UINT i;
7924     HANDLE hthread, hevent;
7925     DWORD tid;
7926     HWINEVENTHOOK hhook;
7927     const struct message *events = WmWinEventsSeq;
7928
7929     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7930                            WS_OVERLAPPEDWINDOW,
7931                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7932                            NULL, NULL, 0);
7933     assert(hwnd);
7934
7935     /****** start of global hook test *************/
7936     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7937     if (!hCBT_global_hook)
7938     {
7939         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7940         skip( "cannot set global hook\n" );
7941         return;
7942     }
7943
7944     hevent = CreateEventA(NULL, 0, 0, NULL);
7945     assert(hevent);
7946     hwnd2 = hevent;
7947
7948     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7949     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7950
7951     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7952
7953     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7954
7955     flush_sequence();
7956     /* this one should be received only by old hook proc */
7957     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7958     /* this one should be received only by old hook proc */
7959     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7960
7961     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7962
7963     ret = UnhookWindowsHookEx(hCBT_global_hook);
7964     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7965
7966     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7967     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7968     CloseHandle(hthread);
7969     CloseHandle(hevent);
7970     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7971     /****** end of global hook test *************/
7972
7973     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7974     {
7975         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7976         return;
7977     }
7978
7979     flush_sequence();
7980
7981     if (0)
7982     {
7983     /* this test doesn't pass under Win9x */
7984     /* win2k ignores events with hwnd == 0 */
7985     SetLastError(0xdeadbeef);
7986     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7987     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7988        GetLastError() == 0xdeadbeef, /* Win9x */
7989        "unexpected error %d\n", GetLastError());
7990     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7991     }
7992
7993     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7994         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7995
7996     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7997
7998     /****** start of event filtering test *************/
7999     hhook = pSetWinEventHook(
8000         EVENT_OBJECT_SHOW, /* 0x8002 */
8001         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8002         GetModuleHandleA(0), win_event_global_hook_proc,
8003         GetCurrentProcessId(), 0,
8004         WINEVENT_INCONTEXT);
8005     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8006
8007     hevent = CreateEventA(NULL, 0, 0, NULL);
8008     assert(hevent);
8009     hwnd2 = hevent;
8010
8011     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8012     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8013
8014     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8015
8016     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8017
8018     flush_sequence();
8019     /* this one should be received only by old hook proc */
8020     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8021     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8022     /* this one should be received only by old hook proc */
8023     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8024
8025     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8026
8027     ret = pUnhookWinEvent(hhook);
8028     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8029
8030     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8031     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8032     CloseHandle(hthread);
8033     CloseHandle(hevent);
8034     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8035     /****** end of event filtering test *************/
8036
8037     /****** start of out of context event test *************/
8038     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8039         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8040         WINEVENT_OUTOFCONTEXT);
8041     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8042
8043     hevent = CreateEventA(NULL, 0, 0, NULL);
8044     assert(hevent);
8045     hwnd2 = hevent;
8046
8047     flush_sequence();
8048
8049     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8050     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8051
8052     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8053
8054     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8055     /* process pending winevent messages */
8056     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8057     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8058
8059     flush_sequence();
8060     /* this one should be received only by old hook proc */
8061     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8062     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8063     /* this one should be received only by old hook proc */
8064     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8065
8066     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8067     /* process pending winevent messages */
8068     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8069     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8070
8071     ret = pUnhookWinEvent(hhook);
8072     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8073
8074     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8075     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8076     CloseHandle(hthread);
8077     CloseHandle(hevent);
8078     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8079     /****** end of out of context event test *************/
8080
8081     /****** start of MOUSE_LL hook test *************/
8082     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8083     /* WH_MOUSE_LL is not supported on Win9x platforms */
8084     if (!hCBT_global_hook)
8085     {
8086         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8087         goto skip_mouse_ll_hook_test;
8088     }
8089
8090     hevent = CreateEventA(NULL, 0, 0, NULL);
8091     assert(hevent);
8092     hwnd2 = hevent;
8093
8094     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8095     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8096
8097     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8098         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8099
8100     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8101     flush_sequence();
8102
8103     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8104     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8105     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8106
8107     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8108
8109     ret = UnhookWindowsHookEx(hCBT_global_hook);
8110     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8111
8112     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8113     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8114     CloseHandle(hthread);
8115     CloseHandle(hevent);
8116     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8117     /****** end of MOUSE_LL hook test *************/
8118 skip_mouse_ll_hook_test:
8119
8120     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8121 }
8122
8123 static void test_set_hook(void)
8124 {
8125     BOOL ret;
8126     HHOOK hhook;
8127     HWINEVENTHOOK hwinevent_hook;
8128
8129     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8130     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8131     UnhookWindowsHookEx(hhook);
8132
8133     if (0)
8134     {
8135     /* this test doesn't pass under Win9x: BUG! */
8136     SetLastError(0xdeadbeef);
8137     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8138     ok(!hhook, "global hook requires hModule != 0\n");
8139     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8140     }
8141
8142     SetLastError(0xdeadbeef);
8143     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8144     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8145     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8146        GetLastError() == 0xdeadbeef, /* Win9x */
8147        "unexpected error %d\n", GetLastError());
8148
8149     SetLastError(0xdeadbeef);
8150     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8151     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8152        GetLastError() == 0xdeadbeef, /* Win9x */
8153        "unexpected error %d\n", GetLastError());
8154
8155     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8156
8157     /* even process local incontext hooks require hmodule */
8158     SetLastError(0xdeadbeef);
8159     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8160         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8161     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8162     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8163        GetLastError() == 0xdeadbeef, /* Win9x */
8164        "unexpected error %d\n", GetLastError());
8165
8166     /* even thread local incontext hooks require hmodule */
8167     SetLastError(0xdeadbeef);
8168     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8169         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8170     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8171     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8172        GetLastError() == 0xdeadbeef, /* Win9x */
8173        "unexpected error %d\n", GetLastError());
8174
8175     if (0)
8176     {
8177     /* these 3 tests don't pass under Win9x */
8178     SetLastError(0xdeadbeef);
8179     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8180         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8181     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8182     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8183
8184     SetLastError(0xdeadbeef);
8185     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8186         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8187     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8188     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8189
8190     SetLastError(0xdeadbeef);
8191     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8192         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8193     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8194     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8195     }
8196
8197     SetLastError(0xdeadbeef);
8198     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8199         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8200     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8201     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8202     ret = pUnhookWinEvent(hwinevent_hook);
8203     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8204
8205 todo_wine {
8206     /* This call succeeds under win2k SP4, but fails under Wine.
8207        Does win2k test/use passed process id? */
8208     SetLastError(0xdeadbeef);
8209     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8210         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8211     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8212     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8213     ret = pUnhookWinEvent(hwinevent_hook);
8214     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8215 }
8216
8217     SetLastError(0xdeadbeef);
8218     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8219     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8220         GetLastError() == 0xdeadbeef, /* Win9x */
8221         "unexpected error %d\n", GetLastError());
8222 }
8223
8224 static const struct message ScrollWindowPaint1[] = {
8225     { WM_PAINT, sent },
8226     { WM_ERASEBKGND, sent|beginpaint },
8227     { WM_GETTEXTLENGTH, sent|optional },
8228     { WM_PAINT, sent|optional },
8229     { WM_NCPAINT, sent|beginpaint|optional },
8230     { WM_GETTEXT, sent|beginpaint|optional },
8231     { WM_GETTEXT, sent|beginpaint|optional },
8232     { WM_ERASEBKGND, sent|beginpaint|optional },
8233     { 0 }
8234 };
8235
8236 static const struct message ScrollWindowPaint2[] = {
8237     { WM_PAINT, sent },
8238     { 0 }
8239 };
8240
8241 static void test_scrollwindowex(void)
8242 {
8243     HWND hwnd, hchild;
8244     RECT rect={0,0,130,130};
8245
8246     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8247             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8248             100, 100, 200, 200, 0, 0, 0, NULL);
8249     ok (hwnd != 0, "Failed to create overlapped window\n");
8250     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8251             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8252             10, 10, 150, 150, hwnd, 0, 0, NULL);
8253     ok (hchild != 0, "Failed to create child\n");
8254     UpdateWindow(hwnd);
8255     flush_events();
8256     flush_sequence();
8257
8258     /* scroll without the child window */
8259     trace("start scroll\n");
8260     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8261             SW_ERASE|SW_INVALIDATE);
8262     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8263     trace("end scroll\n");
8264     flush_sequence();
8265     flush_events();
8266     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8267     flush_events();
8268     flush_sequence();
8269
8270     /* Now without the SW_ERASE flag */
8271     trace("start scroll\n");
8272     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8273     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8274     trace("end scroll\n");
8275     flush_sequence();
8276     flush_events();
8277     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8278     flush_events();
8279     flush_sequence();
8280
8281     /* now scroll the child window as well */
8282     trace("start scroll\n");
8283     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8284             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8285     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8286     /* windows sometimes a WM_MOVE */
8287     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
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 scroll with ScrollWindow() */
8296     trace("start scroll with ScrollWindow\n");
8297     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8298     trace("end scroll\n");
8299     flush_sequence();
8300     flush_events();
8301     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8302
8303     ok(DestroyWindow(hchild), "failed to destroy window\n");
8304     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8305     flush_sequence();
8306 }
8307
8308 static const struct message destroy_window_with_children[] = {
8309     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8310     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8311     { 0x0090, sent|optional },
8312     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8313     { 0x0090, sent|optional },
8314     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8315     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8316     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8317     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8318     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8319     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8320     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8321     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8322     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8323     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8324     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8325     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8326     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8327     { 0 }
8328 };
8329
8330 static void test_DestroyWindow(void)
8331 {
8332     BOOL ret;
8333     HWND parent, child1, child2, child3, child4, test;
8334     UINT_PTR child_id = WND_CHILD_ID + 1;
8335
8336     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8337                              100, 100, 200, 200, 0, 0, 0, NULL);
8338     assert(parent != 0);
8339     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8340                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8341     assert(child1 != 0);
8342     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8343                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8344     assert(child2 != 0);
8345     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8346                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8347     assert(child3 != 0);
8348     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8349                              0, 0, 50, 50, parent, 0, 0, NULL);
8350     assert(child4 != 0);
8351
8352     /* test owner/parent of child2 */
8353     test = GetParent(child2);
8354     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8355     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8356     if(pGetAncestor) {
8357         test = pGetAncestor(child2, GA_PARENT);
8358         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8359     }
8360     test = GetWindow(child2, GW_OWNER);
8361     ok(!test, "wrong owner %p\n", test);
8362
8363     test = SetParent(child2, parent);
8364     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8365
8366     /* test owner/parent of the parent */
8367     test = GetParent(parent);
8368     ok(!test, "wrong parent %p\n", test);
8369     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8370     if(pGetAncestor) {
8371         test = pGetAncestor(parent, GA_PARENT);
8372         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8373     }
8374     test = GetWindow(parent, GW_OWNER);
8375     ok(!test, "wrong owner %p\n", test);
8376
8377     /* test owner/parent of child1 */
8378     test = GetParent(child1);
8379     ok(test == parent, "wrong parent %p\n", test);
8380     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8381     if(pGetAncestor) {
8382         test = pGetAncestor(child1, GA_PARENT);
8383         ok(test == parent, "wrong parent %p\n", test);
8384     }
8385     test = GetWindow(child1, GW_OWNER);
8386     ok(!test, "wrong owner %p\n", test);
8387
8388     /* test owner/parent of child2 */
8389     test = GetParent(child2);
8390     ok(test == parent, "wrong parent %p\n", test);
8391     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8392     if(pGetAncestor) {
8393         test = pGetAncestor(child2, GA_PARENT);
8394         ok(test == parent, "wrong parent %p\n", test);
8395     }
8396     test = GetWindow(child2, GW_OWNER);
8397     ok(!test, "wrong owner %p\n", test);
8398
8399     /* test owner/parent of child3 */
8400     test = GetParent(child3);
8401     ok(test == child1, "wrong parent %p\n", test);
8402     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8403     if(pGetAncestor) {
8404         test = pGetAncestor(child3, GA_PARENT);
8405         ok(test == child1, "wrong parent %p\n", test);
8406     }
8407     test = GetWindow(child3, GW_OWNER);
8408     ok(!test, "wrong owner %p\n", test);
8409
8410     /* test owner/parent of child4 */
8411     test = GetParent(child4);
8412     ok(test == parent, "wrong parent %p\n", test);
8413     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8414     if(pGetAncestor) {
8415         test = pGetAncestor(child4, GA_PARENT);
8416         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8417     }
8418     test = GetWindow(child4, GW_OWNER);
8419     ok(test == parent, "wrong owner %p\n", test);
8420
8421     flush_sequence();
8422
8423     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8424            parent, child1, child2, child3, child4);
8425
8426     SetCapture(child4);
8427     test = GetCapture();
8428     ok(test == child4, "wrong capture window %p\n", test);
8429
8430     test_DestroyWindow_flag = TRUE;
8431     ret = DestroyWindow(parent);
8432     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8433     test_DestroyWindow_flag = FALSE;
8434     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8435
8436     ok(!IsWindow(parent), "parent still exists\n");
8437     ok(!IsWindow(child1), "child1 still exists\n");
8438     ok(!IsWindow(child2), "child2 still exists\n");
8439     ok(!IsWindow(child3), "child3 still exists\n");
8440     ok(!IsWindow(child4), "child4 still exists\n");
8441
8442     test = GetCapture();
8443     ok(!test, "wrong capture window %p\n", test);
8444 }
8445
8446
8447 static const struct message WmDispatchPaint[] = {
8448     { WM_NCPAINT, sent },
8449     { WM_GETTEXT, sent|defwinproc|optional },
8450     { WM_GETTEXT, sent|defwinproc|optional },
8451     { WM_ERASEBKGND, sent },
8452     { 0 }
8453 };
8454
8455 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8456 {
8457     if (message == WM_PAINT) return 0;
8458     return MsgCheckProcA( hwnd, message, wParam, lParam );
8459 }
8460
8461 static void test_DispatchMessage(void)
8462 {
8463     RECT rect;
8464     MSG msg;
8465     int count;
8466     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8467                                100, 100, 200, 200, 0, 0, 0, NULL);
8468     ShowWindow( hwnd, SW_SHOW );
8469     UpdateWindow( hwnd );
8470     flush_events();
8471     flush_sequence();
8472     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8473
8474     SetRect( &rect, -5, -5, 5, 5 );
8475     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8476     count = 0;
8477     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8478     {
8479         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8480         else
8481         {
8482             flush_sequence();
8483             DispatchMessage( &msg );
8484             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8485             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8486             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8487             if (++count > 10) break;
8488         }
8489     }
8490     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8491
8492     trace("now without DispatchMessage\n");
8493     flush_sequence();
8494     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8495     count = 0;
8496     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8497     {
8498         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8499         else
8500         {
8501             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8502             flush_sequence();
8503             /* this will send WM_NCCPAINT just like DispatchMessage does */
8504             GetUpdateRgn( hwnd, hrgn, TRUE );
8505             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8506             DeleteObject( hrgn );
8507             GetClientRect( hwnd, &rect );
8508             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8509             ok( !count, "Got multiple WM_PAINTs\n" );
8510             if (++count > 10) break;
8511         }
8512     }
8513     DestroyWindow(hwnd);
8514 }
8515
8516
8517 static const struct message WmUser[] = {
8518     { WM_USER, sent },
8519     { 0 }
8520 };
8521
8522 struct sendmsg_info
8523 {
8524     HWND  hwnd;
8525     DWORD timeout;
8526     DWORD ret;
8527 };
8528
8529 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8530 {
8531     struct sendmsg_info *info = arg;
8532     SetLastError( 0xdeadbeef );
8533     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8534     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8535                         broken(GetLastError() == 0),  /* win9x */
8536                         "unexpected error %d\n", GetLastError());
8537     return 0;
8538 }
8539
8540 static void wait_for_thread( HANDLE thread )
8541 {
8542     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8543     {
8544         MSG msg;
8545         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8546     }
8547 }
8548
8549 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8550 {
8551     if (message == WM_USER) Sleep(200);
8552     return MsgCheckProcA( hwnd, message, wParam, lParam );
8553 }
8554
8555 static void test_SendMessageTimeout(void)
8556 {
8557     HANDLE thread;
8558     struct sendmsg_info info;
8559     DWORD tid;
8560     BOOL is_win9x;
8561
8562     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8563                                100, 100, 200, 200, 0, 0, 0, NULL);
8564     flush_events();
8565     flush_sequence();
8566
8567     info.timeout = 1000;
8568     info.ret = 0xdeadbeef;
8569     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8570     wait_for_thread( thread );
8571     CloseHandle( thread );
8572     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8573     ok_sequence( WmUser, "WmUser", FALSE );
8574
8575     info.timeout = 1;
8576     info.ret = 0xdeadbeef;
8577     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8578     Sleep(100);  /* SendMessageTimeout should time out here */
8579     wait_for_thread( thread );
8580     CloseHandle( thread );
8581     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8582     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8583
8584     /* 0 means infinite timeout (but not on win9x) */
8585     info.timeout = 0;
8586     info.ret = 0xdeadbeef;
8587     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8588     Sleep(100);
8589     wait_for_thread( thread );
8590     CloseHandle( thread );
8591     is_win9x = !info.ret;
8592     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8593     else ok_sequence( WmUser, "WmUser", FALSE );
8594
8595     /* timeout is treated as signed despite the prototype (but not on win9x) */
8596     info.timeout = 0x7fffffff;
8597     info.ret = 0xdeadbeef;
8598     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8599     Sleep(100);
8600     wait_for_thread( thread );
8601     CloseHandle( thread );
8602     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8603     ok_sequence( WmUser, "WmUser", FALSE );
8604
8605     info.timeout = 0x80000000;
8606     info.ret = 0xdeadbeef;
8607     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8608     Sleep(100);
8609     wait_for_thread( thread );
8610     CloseHandle( thread );
8611     if (is_win9x)
8612     {
8613         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8614         ok_sequence( WmUser, "WmUser", FALSE );
8615     }
8616     else
8617     {
8618         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8619         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8620     }
8621
8622     /* now check for timeout during message processing */
8623     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8624     info.timeout = 100;
8625     info.ret = 0xdeadbeef;
8626     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8627     wait_for_thread( thread );
8628     CloseHandle( thread );
8629     /* we should time out but still get the message */
8630     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8631     ok_sequence( WmUser, "WmUser", FALSE );
8632
8633     DestroyWindow( info.hwnd );
8634 }
8635
8636
8637 /****************** edit message test *************************/
8638 #define ID_EDIT 0x1234
8639 static const struct message sl_edit_setfocus[] =
8640 {
8641     { HCBT_SETFOCUS, hook },
8642     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8643     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8644     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8645     { WM_SETFOCUS, sent|wparam, 0 },
8646     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8647     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8648     { WM_CTLCOLOREDIT, sent|parent },
8649     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8650     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8651     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8652     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8653     { 0 }
8654 };
8655 static const struct message ml_edit_setfocus[] =
8656 {
8657     { HCBT_SETFOCUS, hook },
8658     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8659     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8660     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8661     { WM_SETFOCUS, sent|wparam, 0 },
8662     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8663     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8664     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8665     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8666     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8667     { 0 }
8668 };
8669 static const struct message sl_edit_killfocus[] =
8670 {
8671     { HCBT_SETFOCUS, hook },
8672     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8673     { WM_KILLFOCUS, sent|wparam, 0 },
8674     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8675     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8676     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8677     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8678     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8679     { 0 }
8680 };
8681 static const struct message sl_edit_lbutton_dblclk[] =
8682 {
8683     { WM_LBUTTONDBLCLK, sent },
8684     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8685     { 0 }
8686 };
8687 static const struct message sl_edit_lbutton_down[] =
8688 {
8689     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8690     { HCBT_SETFOCUS, hook },
8691     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8692     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8693     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8694     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8695     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8696     { WM_CTLCOLOREDIT, sent|parent },
8697     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8698     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8699     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8700     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8701     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8702     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8703     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8704     { WM_CTLCOLOREDIT, sent|parent|optional },
8705     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8706     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8707     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8708     { 0 }
8709 };
8710 static const struct message ml_edit_lbutton_down[] =
8711 {
8712     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8713     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8714     { HCBT_SETFOCUS, hook },
8715     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8716     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8717     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8718     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8719     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8720     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8721     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8722     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8723     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8724     { 0 }
8725 };
8726 static const struct message sl_edit_lbutton_up[] =
8727 {
8728     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8729     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8730     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8731     { WM_CAPTURECHANGED, sent|defwinproc },
8732     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8733     { 0 }
8734 };
8735 static const struct message ml_edit_lbutton_up[] =
8736 {
8737     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8738     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8739     { WM_CAPTURECHANGED, sent|defwinproc },
8740     { 0 }
8741 };
8742
8743 static WNDPROC old_edit_proc;
8744
8745 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8746 {
8747     static long defwndproc_counter = 0;
8748     LRESULT ret;
8749     struct recvd_message msg;
8750
8751     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8752
8753     msg.hwnd = hwnd;
8754     msg.message = message;
8755     msg.flags = sent|wparam|lparam;
8756     if (defwndproc_counter) msg.flags |= defwinproc;
8757     msg.wParam = wParam;
8758     msg.lParam = lParam;
8759     msg.descr = "edit";
8760     add_message(&msg);
8761
8762     defwndproc_counter++;
8763     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8764     defwndproc_counter--;
8765
8766     return ret;
8767 }
8768
8769 static void subclass_edit(void)
8770 {
8771     WNDCLASSA cls;
8772
8773     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8774
8775     old_edit_proc = cls.lpfnWndProc;
8776
8777     cls.hInstance = GetModuleHandle(0);
8778     cls.lpfnWndProc = edit_hook_proc;
8779     cls.lpszClassName = "my_edit_class";
8780     UnregisterClass(cls.lpszClassName, cls.hInstance);
8781     if (!RegisterClassA(&cls)) assert(0);
8782 }
8783
8784 static void test_edit_messages(void)
8785 {
8786     HWND hwnd, parent;
8787     DWORD dlg_code;
8788
8789     subclass_edit();
8790     log_all_parent_messages++;
8791
8792     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8793                              100, 100, 200, 200, 0, 0, 0, NULL);
8794     ok (parent != 0, "Failed to create parent window\n");
8795
8796     /* test single line edit */
8797     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8798                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8799     ok(hwnd != 0, "Failed to create edit window\n");
8800
8801     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8802     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8803
8804     ShowWindow(hwnd, SW_SHOW);
8805     UpdateWindow(hwnd);
8806     SetFocus(0);
8807     flush_sequence();
8808
8809     SetFocus(hwnd);
8810     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8811
8812     SetFocus(0);
8813     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8814
8815     SetFocus(0);
8816     ReleaseCapture();
8817     flush_sequence();
8818
8819     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8820     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8821
8822     SetFocus(0);
8823     ReleaseCapture();
8824     flush_sequence();
8825
8826     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8827     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8828
8829     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8830     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8831
8832     DestroyWindow(hwnd);
8833
8834     /* test multiline edit */
8835     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8836                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8837     ok(hwnd != 0, "Failed to create edit window\n");
8838
8839     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8840     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8841        "wrong dlg_code %08x\n", dlg_code);
8842
8843     ShowWindow(hwnd, SW_SHOW);
8844     UpdateWindow(hwnd);
8845     SetFocus(0);
8846     flush_sequence();
8847
8848     SetFocus(hwnd);
8849     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8850
8851     SetFocus(0);
8852     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8853
8854     SetFocus(0);
8855     ReleaseCapture();
8856     flush_sequence();
8857
8858     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8859     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8860
8861     SetFocus(0);
8862     ReleaseCapture();
8863     flush_sequence();
8864
8865     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8866     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8867
8868     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8869     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8870
8871     DestroyWindow(hwnd);
8872     DestroyWindow(parent);
8873
8874     log_all_parent_messages--;
8875 }
8876
8877 /**************************** End of Edit test ******************************/
8878
8879 static const struct message WmKeyDownSkippedSeq[] =
8880 {
8881     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8882     { 0 }
8883 };
8884 static const struct message WmKeyDownWasDownSkippedSeq[] =
8885 {
8886     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8887     { 0 }
8888 };
8889 static const struct message WmKeyUpSkippedSeq[] =
8890 {
8891     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8892     { 0 }
8893 };
8894 static const struct message WmUserKeyUpSkippedSeq[] =
8895 {
8896     { WM_USER, sent },
8897     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8898     { 0 }
8899 };
8900
8901 #define EV_STOP 0
8902 #define EV_SENDMSG 1
8903 #define EV_ACK 2
8904
8905 struct peekmsg_info
8906 {
8907     HWND  hwnd;
8908     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8909 };
8910
8911 static DWORD CALLBACK send_msg_thread_2(void *param)
8912 {
8913     DWORD ret;
8914     struct peekmsg_info *info = param;
8915
8916     trace("thread: looping\n");
8917     SetEvent(info->hevent[EV_ACK]);
8918
8919     while (1)
8920     {
8921         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8922
8923         switch (ret)
8924         {
8925         case WAIT_OBJECT_0 + EV_STOP:
8926             trace("thread: exiting\n");
8927             return 0;
8928
8929         case WAIT_OBJECT_0 + EV_SENDMSG:
8930             trace("thread: sending message\n");
8931             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8932                 "SendNotifyMessageA failed error %u\n", GetLastError());
8933             SetEvent(info->hevent[EV_ACK]);
8934             break;
8935
8936         default:
8937             trace("unexpected return: %04x\n", ret);
8938             assert(0);
8939             break;
8940         }
8941     }
8942     return 0;
8943 }
8944
8945 static void test_PeekMessage(void)
8946 {
8947     MSG msg;
8948     HANDLE hthread;
8949     DWORD tid, qstatus;
8950     UINT qs_all_input = QS_ALLINPUT;
8951     UINT qs_input = QS_INPUT;
8952     BOOL ret;
8953     struct peekmsg_info info;
8954
8955     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8956                               100, 100, 200, 200, 0, 0, 0, NULL);
8957     assert(info.hwnd);
8958     ShowWindow(info.hwnd, SW_SHOW);
8959     UpdateWindow(info.hwnd);
8960     SetFocus(info.hwnd);
8961
8962     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8963     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8964     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8965
8966     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8967     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8968
8969     flush_events();
8970     flush_sequence();
8971
8972     SetLastError(0xdeadbeef);
8973     qstatus = GetQueueStatus(qs_all_input);
8974     if (GetLastError() == ERROR_INVALID_FLAGS)
8975     {
8976         trace("QS_RAWINPUT not supported on this platform\n");
8977         qs_all_input &= ~QS_RAWINPUT;
8978         qs_input &= ~QS_RAWINPUT;
8979     }
8980     if (qstatus & QS_POSTMESSAGE)
8981     {
8982         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8983         qstatus = GetQueueStatus(qs_all_input);
8984     }
8985     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8986
8987     trace("signalling to send message\n");
8988     SetEvent(info.hevent[EV_SENDMSG]);
8989     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8990
8991     /* pass invalid QS_xxxx flags */
8992     SetLastError(0xdeadbeef);
8993     qstatus = GetQueueStatus(0xffffffff);
8994     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8995     if (!qstatus)
8996     {
8997         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8998         qstatus = GetQueueStatus(qs_all_input);
8999     }
9000     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9001     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9002        "wrong qstatus %08x\n", qstatus);
9003
9004     msg.message = 0;
9005     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9006     ok(!ret,
9007        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9008         msg.message);
9009     ok_sequence(WmUser, "WmUser", FALSE);
9010
9011     qstatus = GetQueueStatus(qs_all_input);
9012     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9013
9014     keybd_event('N', 0, 0, 0);
9015     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9016     qstatus = GetQueueStatus(qs_all_input);
9017     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9018     {
9019         skip( "queuing key events not supported\n" );
9020         goto done;
9021     }
9022     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
9023        "wrong qstatus %08x\n", qstatus);
9024
9025     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9026     qstatus = GetQueueStatus(qs_all_input);
9027     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9028        "wrong qstatus %08x\n", qstatus);
9029
9030     InvalidateRect(info.hwnd, NULL, FALSE);
9031     qstatus = GetQueueStatus(qs_all_input);
9032     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9033        "wrong qstatus %08x\n", qstatus);
9034
9035     trace("signalling to send message\n");
9036     SetEvent(info.hevent[EV_SENDMSG]);
9037     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9038
9039     qstatus = GetQueueStatus(qs_all_input);
9040     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9041        "wrong qstatus %08x\n", qstatus);
9042
9043     msg.message = 0;
9044     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9045     if (ret && msg.message == WM_CHAR)
9046     {
9047         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9048         goto done;
9049     }
9050     ok(!ret,
9051        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9052         msg.message);
9053     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9054     {
9055         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9056         goto done;
9057     }
9058     ok_sequence(WmUser, "WmUser", FALSE);
9059
9060     qstatus = GetQueueStatus(qs_all_input);
9061     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9062        "wrong qstatus %08x\n", qstatus);
9063
9064     trace("signalling to send message\n");
9065     SetEvent(info.hevent[EV_SENDMSG]);
9066     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9067
9068     qstatus = GetQueueStatus(qs_all_input);
9069     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9070        "wrong qstatus %08x\n", qstatus);
9071
9072     msg.message = 0;
9073     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9074     ok(!ret,
9075        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9076         msg.message);
9077     ok_sequence(WmUser, "WmUser", FALSE);
9078
9079     qstatus = GetQueueStatus(qs_all_input);
9080     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9081        "wrong qstatus %08x\n", qstatus);
9082
9083     msg.message = 0;
9084     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9085     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9086        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9087        ret, msg.message, msg.wParam);
9088     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9089
9090     qstatus = GetQueueStatus(qs_all_input);
9091     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9092        "wrong qstatus %08x\n", qstatus);
9093
9094     msg.message = 0;
9095     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9096     ok(!ret,
9097        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9098         msg.message);
9099     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9100
9101     qstatus = GetQueueStatus(qs_all_input);
9102     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9103        "wrong qstatus %08x\n", qstatus);
9104
9105     msg.message = 0;
9106     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9107     ok(ret && msg.message == WM_PAINT,
9108        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9109     DispatchMessageA(&msg);
9110     ok_sequence(WmPaint, "WmPaint", FALSE);
9111
9112     qstatus = GetQueueStatus(qs_all_input);
9113     ok(qstatus == MAKELONG(0, QS_KEY),
9114        "wrong qstatus %08x\n", qstatus);
9115
9116     msg.message = 0;
9117     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9118     ok(!ret,
9119        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9120         msg.message);
9121     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9122
9123     qstatus = GetQueueStatus(qs_all_input);
9124     ok(qstatus == MAKELONG(0, QS_KEY),
9125        "wrong qstatus %08x\n", qstatus);
9126
9127     trace("signalling to send message\n");
9128     SetEvent(info.hevent[EV_SENDMSG]);
9129     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9130
9131     qstatus = GetQueueStatus(qs_all_input);
9132     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9133        "wrong qstatus %08x\n", qstatus);
9134
9135     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9136
9137     qstatus = GetQueueStatus(qs_all_input);
9138     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9139        "wrong qstatus %08x\n", qstatus);
9140
9141     msg.message = 0;
9142     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9143     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9144        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9145        ret, msg.message, msg.wParam);
9146     ok_sequence(WmUser, "WmUser", FALSE);
9147
9148     qstatus = GetQueueStatus(qs_all_input);
9149     ok(qstatus == MAKELONG(0, QS_KEY),
9150        "wrong qstatus %08x\n", qstatus);
9151
9152     msg.message = 0;
9153     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9154     ok(!ret,
9155        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9156         msg.message);
9157     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9158
9159     qstatus = GetQueueStatus(qs_all_input);
9160     ok(qstatus == MAKELONG(0, QS_KEY),
9161        "wrong qstatus %08x\n", qstatus);
9162
9163     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9164
9165     qstatus = GetQueueStatus(qs_all_input);
9166     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9167        "wrong qstatus %08x\n", qstatus);
9168
9169     trace("signalling to send message\n");
9170     SetEvent(info.hevent[EV_SENDMSG]);
9171     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9172
9173     qstatus = GetQueueStatus(qs_all_input);
9174     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9175        "wrong qstatus %08x\n", qstatus);
9176
9177     msg.message = 0;
9178     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9179     ok(!ret,
9180        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9181         msg.message);
9182     ok_sequence(WmUser, "WmUser", FALSE);
9183
9184     qstatus = GetQueueStatus(qs_all_input);
9185     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9186        "wrong qstatus %08x\n", qstatus);
9187
9188     msg.message = 0;
9189     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9190         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9191     else /* workaround for a missing QS_RAWINPUT support */
9192         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9193     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9194        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9195        ret, msg.message, msg.wParam);
9196     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9197
9198     qstatus = GetQueueStatus(qs_all_input);
9199     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9200        "wrong qstatus %08x\n", qstatus);
9201
9202     msg.message = 0;
9203     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9204         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9205     else /* workaround for a missing QS_RAWINPUT support */
9206         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9207     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9208        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9209        ret, msg.message, msg.wParam);
9210     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9211
9212     qstatus = GetQueueStatus(qs_all_input);
9213     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9214        "wrong qstatus %08x\n", qstatus);
9215
9216     msg.message = 0;
9217     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9218     ok(!ret,
9219        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9220         msg.message);
9221     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9222
9223     qstatus = GetQueueStatus(qs_all_input);
9224     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9225        "wrong qstatus %08x\n", qstatus);
9226
9227     msg.message = 0;
9228     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9229     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9230        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9231        ret, msg.message, msg.wParam);
9232     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9233
9234     qstatus = GetQueueStatus(qs_all_input);
9235     ok(qstatus == 0,
9236        "wrong qstatus %08x\n", qstatus);
9237
9238     msg.message = 0;
9239     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9240     ok(!ret,
9241        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9242         msg.message);
9243     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9244
9245     qstatus = GetQueueStatus(qs_all_input);
9246     ok(qstatus == 0,
9247        "wrong qstatus %08x\n", qstatus);
9248
9249     /* test whether presence of the quit flag in the queue affects
9250      * the queue state
9251      */
9252     PostQuitMessage(0x1234abcd);
9253
9254     qstatus = GetQueueStatus(qs_all_input);
9255     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9256        "wrong qstatus %08x\n", qstatus);
9257
9258     PostMessageA(info.hwnd, WM_USER, 0, 0);
9259
9260     qstatus = GetQueueStatus(qs_all_input);
9261     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9262        "wrong qstatus %08x\n", qstatus);
9263
9264     msg.message = 0;
9265     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9266     ok(ret && msg.message == WM_USER,
9267        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9268     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9269
9270     qstatus = GetQueueStatus(qs_all_input);
9271     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9272        "wrong qstatus %08x\n", qstatus);
9273
9274     msg.message = 0;
9275     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9276     ok(ret && msg.message == WM_QUIT,
9277        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9278     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9279     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9280     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9281
9282     qstatus = GetQueueStatus(qs_all_input);
9283 todo_wine {
9284     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9285        "wrong qstatus %08x\n", qstatus);
9286 }
9287
9288     msg.message = 0;
9289     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9290     ok(!ret,
9291        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9292         msg.message);
9293     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9294
9295     qstatus = GetQueueStatus(qs_all_input);
9296     ok(qstatus == 0,
9297        "wrong qstatus %08x\n", qstatus);
9298
9299     /* some GetMessage tests */
9300
9301     keybd_event('N', 0, 0, 0);
9302     qstatus = GetQueueStatus(qs_all_input);
9303     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9304
9305     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9306     qstatus = GetQueueStatus(qs_all_input);
9307     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9308
9309     if (qstatus)
9310     {
9311         ret = GetMessageA( &msg, 0, 0, 0 );
9312         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9313            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9314            ret, msg.message, msg.wParam);
9315         qstatus = GetQueueStatus(qs_all_input);
9316         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9317     }
9318
9319     if (qstatus)
9320     {
9321         ret = GetMessageA( &msg, 0, 0, 0 );
9322         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9323            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9324            ret, msg.message, msg.wParam);
9325         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9326         qstatus = GetQueueStatus(qs_all_input);
9327         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9328     }
9329
9330     keybd_event('N', 0, 0, 0);
9331     qstatus = GetQueueStatus(qs_all_input);
9332     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9333
9334     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9335     qstatus = GetQueueStatus(qs_all_input);
9336     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9337
9338     if (qstatus & (QS_KEY << 16))
9339     {
9340         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9341         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9342            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9343            ret, msg.message, msg.wParam);
9344         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9345         qstatus = GetQueueStatus(qs_all_input);
9346         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9347     }
9348
9349     if (qstatus)
9350     {
9351         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9352         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9353            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9354            ret, msg.message, msg.wParam);
9355         qstatus = GetQueueStatus(qs_all_input);
9356         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9357     }
9358
9359     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9360     qstatus = GetQueueStatus(qs_all_input);
9361     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9362
9363     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9364     qstatus = GetQueueStatus(qs_all_input);
9365     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9366
9367     trace("signalling to send message\n");
9368     SetEvent(info.hevent[EV_SENDMSG]);
9369     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9370     qstatus = GetQueueStatus(qs_all_input);
9371     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9372        "wrong qstatus %08x\n", qstatus);
9373
9374     if (qstatus & (QS_KEY << 16))
9375     {
9376         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9377         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9378            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9379            ret, msg.message, msg.wParam);
9380         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9381         qstatus = GetQueueStatus(qs_all_input);
9382         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9383     }
9384
9385     if (qstatus)
9386     {
9387         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9388         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9389            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9390            ret, msg.message, msg.wParam);
9391         qstatus = GetQueueStatus(qs_all_input);
9392         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9393     }
9394 done:
9395     trace("signalling to exit\n");
9396     SetEvent(info.hevent[EV_STOP]);
9397
9398     WaitForSingleObject(hthread, INFINITE);
9399
9400     CloseHandle(hthread);
9401     CloseHandle(info.hevent[0]);
9402     CloseHandle(info.hevent[1]);
9403     CloseHandle(info.hevent[2]);
9404
9405     DestroyWindow(info.hwnd);
9406 }
9407
9408 static void wait_move_event(HWND hwnd, int x, int y)
9409 {
9410     MSG msg;
9411     DWORD time;
9412     BOOL  ret;
9413     int go = 0;
9414
9415     time = GetTickCount();
9416     while (GetTickCount() - time < 200 && !go) {
9417         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9418         go  = ret && msg.pt.x > x && msg.pt.y > y;
9419         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9420     }
9421 }
9422
9423 #define STEP 5
9424 static void test_PeekMessage2(void)
9425 {
9426     HWND hwnd;
9427     BOOL ret;
9428     MSG msg;
9429     UINT message;
9430     DWORD time1, time2, time3;
9431     int x1, y1, x2, y2, x3, y3;
9432     POINT pos;
9433
9434     time1 = time2 = time3 = 0;
9435     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9436
9437     /* Initialise window and make sure it is ready for events */
9438     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9439                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9440     assert(hwnd);
9441     trace("Window for test_PeekMessage2 %p\n", hwnd);
9442     ShowWindow(hwnd, SW_SHOW);
9443     UpdateWindow(hwnd);
9444     SetFocus(hwnd);
9445     GetCursorPos(&pos);
9446     SetCursorPos(100, 100);
9447     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9448     flush_events();
9449
9450     /* Do initial mousemove, wait until we can see it
9451        and then do our test peek with PM_NOREMOVE. */
9452     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9453     wait_move_event(hwnd, 100-STEP, 100-STEP);
9454
9455     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9456     if (!ret)
9457     {
9458         skip( "queuing mouse events not supported\n" );
9459         goto done;
9460     }
9461     else
9462     {
9463         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9464         message = msg.message;
9465         time1 = msg.time;
9466         x1 = msg.pt.x;
9467         y1 = msg.pt.y;
9468         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9469     }
9470
9471     /* Allow time to advance a bit, and then simulate the user moving their
9472      * mouse around. After that we peek again with PM_NOREMOVE.
9473      * Although the previous mousemove message was never removed, the
9474      * mousemove we now peek should reflect the recent mouse movements
9475      * because the input queue will merge the move events. */
9476     Sleep(100);
9477     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9478     wait_move_event(hwnd, x1, y1);
9479
9480     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9481     ok(ret, "no message available\n");
9482     if (ret) {
9483         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9484         message = msg.message;
9485         time2 = msg.time;
9486         x2 = msg.pt.x;
9487         y2 = msg.pt.y;
9488         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9489         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9490         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9491     }
9492
9493     /* Have another go, to drive the point home */
9494     Sleep(100);
9495     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9496     wait_move_event(hwnd, x2, y2);
9497
9498     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9499     ok(ret, "no message available\n");
9500     if (ret) {
9501         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9502         message = msg.message;
9503         time3 = msg.time;
9504         x3 = msg.pt.x;
9505         y3 = msg.pt.y;
9506         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9507         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9508         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9509     }
9510
9511 done:
9512     DestroyWindow(hwnd);
9513     SetCursorPos(pos.x, pos.y);
9514     flush_events();
9515 }
9516
9517 static void test_quit_message(void)
9518 {
9519     MSG msg;
9520     BOOL ret;
9521
9522     /* test using PostQuitMessage */
9523     flush_events();
9524     PostQuitMessage(0xbeef);
9525
9526     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9527     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9528     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9529     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9530
9531     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9532     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9533
9534     ret = GetMessage(&msg, NULL, 0, 0);
9535     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9536     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9537
9538     /* note: WM_QUIT message received after WM_USER message */
9539     ret = GetMessage(&msg, NULL, 0, 0);
9540     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9541     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9542     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9543
9544     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9545     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9546
9547     /* now test with PostThreadMessage - different behaviour! */
9548     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9549
9550     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9551     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9552     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9553     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9554
9555     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9556     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9557
9558     /* note: we receive the WM_QUIT message first this time */
9559     ret = GetMessage(&msg, NULL, 0, 0);
9560     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9561     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9562     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9563
9564     ret = GetMessage(&msg, NULL, 0, 0);
9565     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9566     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9567 }
9568
9569 static const struct message WmMouseHoverSeq[] = {
9570     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9571     { WM_MOUSEACTIVATE, sent|optional },
9572     { WM_TIMER, sent|optional }, /* XP sends it */
9573     { WM_SYSTIMER, sent },
9574     { WM_MOUSEHOVER, sent|wparam, 0 },
9575     { 0 }
9576 };
9577
9578 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9579 {
9580     MSG msg;
9581     DWORD start_ticks, end_ticks;
9582
9583     start_ticks = GetTickCount();
9584     /* add some deviation (50%) to cover not expected delays */
9585     start_ticks += timeout / 2;
9586
9587     do
9588     {
9589         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9590         {
9591             /* Timer proc messages are not dispatched to the window proc,
9592              * and therefore not logged.
9593              */
9594             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9595             {
9596                 struct recvd_message s_msg;
9597
9598                 s_msg.hwnd = msg.hwnd;
9599                 s_msg.message = msg.message;
9600                 s_msg.flags = sent|wparam|lparam;
9601                 s_msg.wParam = msg.wParam;
9602                 s_msg.lParam = msg.lParam;
9603                 s_msg.descr = "msg_loop";
9604                 add_message(&s_msg);
9605             }
9606             DispatchMessage(&msg);
9607         }
9608
9609         end_ticks = GetTickCount();
9610
9611         /* inject WM_MOUSEMOVE to see how it changes tracking */
9612         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9613         {
9614             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9615             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9616
9617             inject_mouse_move = FALSE;
9618         }
9619     } while (start_ticks + timeout >= end_ticks);
9620 }
9621
9622 static void test_TrackMouseEvent(void)
9623 {
9624     TRACKMOUSEEVENT tme;
9625     BOOL ret;
9626     HWND hwnd, hchild;
9627     RECT rc_parent, rc_child;
9628     UINT default_hover_time, hover_width = 0, hover_height = 0;
9629
9630 #define track_hover(track_hwnd, track_hover_time) \
9631     tme.cbSize = sizeof(tme); \
9632     tme.dwFlags = TME_HOVER; \
9633     tme.hwndTrack = track_hwnd; \
9634     tme.dwHoverTime = track_hover_time; \
9635     SetLastError(0xdeadbeef); \
9636     ret = pTrackMouseEvent(&tme); \
9637     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9638
9639 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9640     tme.cbSize = sizeof(tme); \
9641     tme.dwFlags = TME_QUERY; \
9642     tme.hwndTrack = (HWND)0xdeadbeef; \
9643     tme.dwHoverTime = 0xdeadbeef; \
9644     SetLastError(0xdeadbeef); \
9645     ret = pTrackMouseEvent(&tme); \
9646     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9647     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9648     ok(tme.dwFlags == (expected_track_flags), \
9649        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9650     ok(tme.hwndTrack == (expected_track_hwnd), \
9651        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9652     ok(tme.dwHoverTime == (expected_hover_time), \
9653        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9654
9655 #define track_hover_cancel(track_hwnd) \
9656     tme.cbSize = sizeof(tme); \
9657     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9658     tme.hwndTrack = track_hwnd; \
9659     tme.dwHoverTime = 0xdeadbeef; \
9660     SetLastError(0xdeadbeef); \
9661     ret = pTrackMouseEvent(&tme); \
9662     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9663
9664     default_hover_time = 0xdeadbeef;
9665     SetLastError(0xdeadbeef);
9666     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9667     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9668        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9669     if (!ret) default_hover_time = 400;
9670     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9671
9672     SetLastError(0xdeadbeef);
9673     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9674     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9675        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9676     if (!ret) hover_width = 4;
9677     SetLastError(0xdeadbeef);
9678     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9679     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9680        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9681     if (!ret) hover_height = 4;
9682     trace("hover rect is %u x %d\n", hover_width, hover_height);
9683
9684     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9685                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9686                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9687                           NULL, NULL, 0);
9688     assert(hwnd);
9689
9690     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9691                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9692                           50, 50, 200, 200, hwnd,
9693                           NULL, NULL, 0);
9694     assert(hchild);
9695
9696     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9697     flush_events();
9698     flush_sequence();
9699
9700     tme.cbSize = 0;
9701     tme.dwFlags = TME_QUERY;
9702     tme.hwndTrack = (HWND)0xdeadbeef;
9703     tme.dwHoverTime = 0xdeadbeef;
9704     SetLastError(0xdeadbeef);
9705     ret = pTrackMouseEvent(&tme);
9706     ok(!ret, "TrackMouseEvent should fail\n");
9707     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9708        "not expected error %u\n", GetLastError());
9709
9710     tme.cbSize = sizeof(tme);
9711     tme.dwFlags = TME_HOVER;
9712     tme.hwndTrack = (HWND)0xdeadbeef;
9713     tme.dwHoverTime = 0xdeadbeef;
9714     SetLastError(0xdeadbeef);
9715     ret = pTrackMouseEvent(&tme);
9716     ok(!ret, "TrackMouseEvent should fail\n");
9717     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9718        "not expected error %u\n", GetLastError());
9719
9720     tme.cbSize = sizeof(tme);
9721     tme.dwFlags = TME_HOVER | TME_CANCEL;
9722     tme.hwndTrack = (HWND)0xdeadbeef;
9723     tme.dwHoverTime = 0xdeadbeef;
9724     SetLastError(0xdeadbeef);
9725     ret = pTrackMouseEvent(&tme);
9726     ok(!ret, "TrackMouseEvent should fail\n");
9727     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9728        "not expected error %u\n", GetLastError());
9729
9730     GetWindowRect(hwnd, &rc_parent);
9731     GetWindowRect(hchild, &rc_child);
9732     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9733
9734     /* Process messages so that the system updates its internal current
9735      * window and hittest, otherwise TrackMouseEvent calls don't have any
9736      * effect.
9737      */
9738     flush_events();
9739     flush_sequence();
9740
9741     track_query(0, NULL, 0);
9742     track_hover(hchild, 0);
9743     track_query(0, NULL, 0);
9744
9745     flush_events();
9746     flush_sequence();
9747
9748     track_hover(hwnd, 0);
9749     tme.cbSize = sizeof(tme);
9750     tme.dwFlags = TME_QUERY;
9751     tme.hwndTrack = (HWND)0xdeadbeef;
9752     tme.dwHoverTime = 0xdeadbeef;
9753     SetLastError(0xdeadbeef);
9754     ret = pTrackMouseEvent(&tme);
9755     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9756     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9757     if (!tme.dwFlags)
9758     {
9759         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9760         DestroyWindow( hwnd );
9761         return;
9762     }
9763     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9764     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9765     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9766        tme.dwHoverTime, default_hover_time);
9767
9768     pump_msg_loop_timeout(default_hover_time, FALSE);
9769     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9770
9771     track_query(0, NULL, 0);
9772
9773     track_hover(hwnd, HOVER_DEFAULT);
9774     track_query(TME_HOVER, hwnd, default_hover_time);
9775
9776     Sleep(default_hover_time / 2);
9777     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9778     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9779
9780     track_query(TME_HOVER, hwnd, default_hover_time);
9781
9782     pump_msg_loop_timeout(default_hover_time, FALSE);
9783     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9784
9785     track_query(0, NULL, 0);
9786
9787     track_hover(hwnd, HOVER_DEFAULT);
9788     track_query(TME_HOVER, hwnd, default_hover_time);
9789
9790     pump_msg_loop_timeout(default_hover_time, TRUE);
9791     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9792
9793     track_query(0, NULL, 0);
9794
9795     track_hover(hwnd, HOVER_DEFAULT);
9796     track_query(TME_HOVER, hwnd, default_hover_time);
9797     track_hover_cancel(hwnd);
9798
9799     DestroyWindow(hwnd);
9800
9801 #undef track_hover
9802 #undef track_query
9803 #undef track_hover_cancel
9804 }
9805
9806
9807 static const struct message WmSetWindowRgn[] = {
9808     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9809     { WM_NCCALCSIZE, sent|wparam, 1 },
9810     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9811     { WM_GETTEXT, sent|defwinproc|optional },
9812     { WM_ERASEBKGND, sent|optional },
9813     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9814     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9815     { 0 }
9816 };
9817
9818 static const struct message WmSetWindowRgn_no_redraw[] = {
9819     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9820     { WM_NCCALCSIZE, sent|wparam, 1 },
9821     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9822     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9823     { 0 }
9824 };
9825
9826 static const struct message WmSetWindowRgn_clear[] = {
9827     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9828     { WM_NCCALCSIZE, sent|wparam, 1 },
9829     { WM_NCPAINT, sent|optional },
9830     { WM_GETTEXT, sent|defwinproc|optional },
9831     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9832     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9833     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9834     { WM_NCPAINT, sent|optional },
9835     { WM_GETTEXT, sent|defwinproc|optional },
9836     { WM_ERASEBKGND, sent|optional },
9837     { WM_WINDOWPOSCHANGING, sent|optional },
9838     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9839     { WM_NCPAINT, sent|optional },
9840     { WM_GETTEXT, sent|defwinproc|optional },
9841     { WM_ERASEBKGND, sent|optional },
9842     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9843     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9844     { WM_NCPAINT, sent|optional },
9845     { WM_GETTEXT, sent|defwinproc|optional },
9846     { WM_ERASEBKGND, sent|optional },
9847     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9848     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9849     { 0 }
9850 };
9851
9852 static void test_SetWindowRgn(void)
9853 {
9854     HRGN hrgn;
9855     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9856                                 100, 100, 200, 200, 0, 0, 0, NULL);
9857     ok( hwnd != 0, "Failed to create overlapped window\n" );
9858
9859     ShowWindow( hwnd, SW_SHOW );
9860     UpdateWindow( hwnd );
9861     flush_events();
9862     flush_sequence();
9863
9864     trace("testing SetWindowRgn\n");
9865     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9866     SetWindowRgn( hwnd, hrgn, TRUE );
9867     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9868
9869     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9870     SetWindowRgn( hwnd, hrgn, FALSE );
9871     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9872
9873     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9874     SetWindowRgn( hwnd, hrgn, TRUE );
9875     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9876
9877     SetWindowRgn( hwnd, 0, TRUE );
9878     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9879
9880     DestroyWindow( hwnd );
9881 }
9882
9883 /*************************** ShowWindow() test ******************************/
9884 static const struct message WmShowNormal[] = {
9885     { WM_SHOWWINDOW, sent|wparam, 1 },
9886     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9887     { HCBT_ACTIVATE, hook },
9888     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9889     { HCBT_SETFOCUS, hook },
9890     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9891     { 0 }
9892 };
9893 static const struct message WmShow[] = {
9894     { WM_SHOWWINDOW, sent|wparam, 1 },
9895     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9896     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9897     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9898     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9899     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9900     { 0 }
9901 };
9902 static const struct message WmShowNoActivate_1[] = {
9903     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9904     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9905     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9906     { WM_MOVE, sent|defwinproc|optional },
9907     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9908     { 0 }
9909 };
9910 static const struct message WmShowNoActivate_2[] = {
9911     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9912     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9913     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9914     { WM_MOVE, sent|defwinproc },
9915     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9916     { HCBT_SETFOCUS, hook|optional },
9917     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9918     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9919     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9920     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9921     { 0 }
9922 };
9923 static const struct message WmShowNA_1[] = {
9924     { WM_SHOWWINDOW, sent|wparam, 1 },
9925     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9926     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9927     { 0 }
9928 };
9929 static const struct message WmShowNA_2[] = {
9930     { WM_SHOWWINDOW, sent|wparam, 1 },
9931     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9932     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9933     { 0 }
9934 };
9935 static const struct message WmRestore_1[] = {
9936     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9937     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9938     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9939     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9940     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9941     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9942     { WM_MOVE, sent|defwinproc },
9943     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9944     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9945     { 0 }
9946 };
9947 static const struct message WmRestore_2[] = {
9948     { WM_SHOWWINDOW, sent|wparam, 1 },
9949     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9950     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9951     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9952     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9953     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9954     { 0 }
9955 };
9956 static const struct message WmRestore_3[] = {
9957     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9958     { WM_GETMINMAXINFO, sent },
9959     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9960     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9961     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9962     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9963     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9964     { WM_MOVE, sent|defwinproc },
9965     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9966     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9967     { 0 }
9968 };
9969 static const struct message WmRestore_4[] = {
9970     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
9971     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9972     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9973     { WM_MOVE, sent|defwinproc|optional },
9974     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
9975     { 0 }
9976 };
9977 static const struct message WmRestore_5[] = {
9978     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
9979     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9980     { HCBT_ACTIVATE, hook|optional },
9981     { HCBT_SETFOCUS, hook|optional },
9982     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9983     { WM_MOVE, sent|defwinproc|optional },
9984     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
9985     { 0 }
9986 };
9987 static const struct message WmHide_1[] = {
9988     { WM_SHOWWINDOW, sent|wparam, 0 },
9989     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9990     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9991     { HCBT_ACTIVATE, hook|optional },
9992     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9993     { 0 }
9994 };
9995 static const struct message WmHide_2[] = {
9996     { WM_SHOWWINDOW, sent|wparam, 0 },
9997     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9998     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9999     { HCBT_ACTIVATE, hook|optional },
10000     { 0 }
10001 };
10002 static const struct message WmHide_3[] = {
10003     { WM_SHOWWINDOW, sent|wparam, 0 },
10004     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10005     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10006     { HCBT_SETFOCUS, hook|optional },
10007     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10008     { 0 }
10009 };
10010 static const struct message WmShowMinimized_1[] = {
10011     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10012     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10013     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10014     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10015     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10016     { WM_MOVE, sent|defwinproc },
10017     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10018     { 0 }
10019 };
10020 static const struct message WmMinimize_1[] = {
10021     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10022     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10023     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10024     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10025     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10026     { WM_MOVE, sent|defwinproc },
10027     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10028     { 0 }
10029 };
10030 static const struct message WmMinimize_2[] = {
10031     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10032     { HCBT_SETFOCUS, hook|optional },
10033     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10034     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10035     { WM_MOVE, sent|defwinproc },
10036     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10037     { 0 }
10038 };
10039 static const struct message WmMinimize_3[] = {
10040     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10041     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10042     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10043     { WM_MOVE, sent|defwinproc },
10044     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
10045     { 0 }
10046 };
10047 static const struct message WmShowMinNoActivate[] = {
10048     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10049     { WM_WINDOWPOSCHANGING, sent },
10050     { WM_WINDOWPOSCHANGED, sent },
10051     { WM_MOVE, sent|defwinproc|optional },
10052     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MINIMIZED },
10053     { 0 }
10054 };
10055 static const struct message WmMinMax_1[] = {
10056     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10057     { 0 }
10058 };
10059 static const struct message WmMinMax_2[] = {
10060     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10061     { WM_GETMINMAXINFO, sent|optional },
10062     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10063     { HCBT_ACTIVATE, hook|optional },
10064     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10065     { HCBT_SETFOCUS, hook|optional },
10066     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10067     { WM_MOVE, sent|defwinproc|optional },
10068     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10069     { HCBT_SETFOCUS, hook|optional },
10070     { 0 }
10071 };
10072 static const struct message WmMinMax_3[] = {
10073     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10074     { HCBT_SETFOCUS, hook|optional },
10075     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10076     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10077     { WM_MOVE, sent|defwinproc|optional },
10078     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MINIMIZED },
10079     { 0 }
10080 };
10081 static const struct message WmMinMax_4[] = {
10082     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10083     { 0 }
10084 };
10085 static const struct message WmShowMaximized_1[] = {
10086     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10087     { WM_GETMINMAXINFO, sent },
10088     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10089     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10090     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10091     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10092     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10093     { WM_MOVE, sent|defwinproc },
10094     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10095     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10096     { 0 }
10097 };
10098 static const struct message WmShowMaximized_2[] = {
10099     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10100     { WM_GETMINMAXINFO, sent },
10101     { WM_WINDOWPOSCHANGING, sent|optional },
10102     { HCBT_ACTIVATE, hook|optional },
10103     { WM_WINDOWPOSCHANGED, sent|optional },
10104     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10105     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10106     { WM_WINDOWPOSCHANGING, sent|optional },
10107     { HCBT_SETFOCUS, hook|optional },
10108     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10109     { WM_MOVE, sent|defwinproc },
10110     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10111     { HCBT_SETFOCUS, hook|optional },
10112     { 0 }
10113 };
10114 static const struct message WmShowMaximized_3[] = {
10115     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10116     { WM_GETMINMAXINFO, sent },
10117     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10118     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10119     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10120     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10121     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10122     { WM_MOVE, sent|defwinproc|optional },
10123     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10124     { 0 }
10125 };
10126
10127 static void test_ShowWindow(void)
10128 {
10129     /* ShowWindow commands in random order */
10130     static const struct
10131     {
10132         INT cmd; /* ShowWindow command */
10133         LPARAM ret; /* ShowWindow return value */
10134         DWORD style; /* window style after the command */
10135         const struct message *msg; /* message sequence the command produces */
10136         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10137     } sw[] =
10138     {
10139 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10140 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10141 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10142 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10143 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10144 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10145 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10146 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10147 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10148 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10149 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10150 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10151 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10152 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10153 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10154 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10155 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10156 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10157 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10158 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10159 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10160 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10161 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10162 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10163 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10164 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10165 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10166 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10167 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10168 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10169 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10170 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10171 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10172 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10173 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10174 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10175 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10176 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10177 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10178 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10179 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10180 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10181 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10182 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10183 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10184 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10185 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10186 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10187 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10188 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10189 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10190 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10191 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10192 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10193 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10194 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10195 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10196     };
10197     HWND hwnd;
10198     DWORD style;
10199     LPARAM ret;
10200     INT i;
10201
10202 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10203     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10204                           120, 120, 90, 90,
10205                           0, 0, 0, NULL);
10206     assert(hwnd);
10207
10208     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10209     ok(style == 0, "expected style 0, got %08x\n", style);
10210
10211     flush_events();
10212     flush_sequence();
10213
10214     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10215     {
10216         static const char * const sw_cmd_name[13] =
10217         {
10218             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10219             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10220             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10221             "SW_NORMALNA" /* 0xCC */
10222         };
10223         char comment[64];
10224         INT idx; /* index into the above array of names */
10225
10226         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10227
10228         style = GetWindowLong(hwnd, GWL_STYLE);
10229         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10230         ret = ShowWindow(hwnd, sw[i].cmd);
10231         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10232         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10233         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10234
10235         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10236         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10237
10238         flush_events();
10239         flush_sequence();
10240     }
10241
10242     DestroyWindow(hwnd);
10243 }
10244
10245 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10246 {
10247     struct recvd_message msg;
10248
10249     switch (message)
10250     {
10251     case WM_GETICON:
10252     case WM_GETOBJECT:
10253         return 0;  /* ignore them */
10254     }
10255
10256     msg.hwnd = hwnd;
10257     msg.message = message;
10258     msg.flags = sent|wparam|lparam;
10259     msg.wParam = wParam;
10260     msg.lParam = lParam;
10261     msg.descr = "dialog";
10262     add_message(&msg);
10263
10264     /* calling DefDlgProc leads to a recursion under XP */
10265
10266     switch (message)
10267     {
10268     case WM_INITDIALOG:
10269     case WM_GETDLGCODE:
10270         return 0;
10271     }
10272     return 1;
10273 }
10274
10275 static const struct message WmDefDlgSetFocus_1[] = {
10276     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10277     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10278     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10279     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10280     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10281     { HCBT_SETFOCUS, hook },
10282     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10283     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10284     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10285     { WM_SETFOCUS, sent|wparam, 0 },
10286     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10287     { WM_CTLCOLOREDIT, sent },
10288     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10289     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10290     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10291     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10292     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10293     { 0 }
10294 };
10295 static const struct message WmDefDlgSetFocus_2[] = {
10296     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10297     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10298     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10299     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10300     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10301     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10302     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10303     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10304     { 0 }
10305 };
10306 /* Creation of a dialog */
10307 static const struct message WmCreateDialogParamSeq_1[] = {
10308     { HCBT_CREATEWND, hook },
10309     { WM_NCCREATE, sent },
10310     { WM_NCCALCSIZE, sent|wparam, 0 },
10311     { WM_CREATE, sent },
10312     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10313     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10314     { WM_MOVE, sent },
10315     { WM_SETFONT, sent },
10316     { WM_INITDIALOG, sent },
10317     { WM_CHANGEUISTATE, sent|optional },
10318     { 0 }
10319 };
10320 /* Creation of a dialog */
10321 static const struct message WmCreateDialogParamSeq_2[] = {
10322     { HCBT_CREATEWND, hook },
10323     { WM_NCCREATE, sent },
10324     { WM_NCCALCSIZE, sent|wparam, 0 },
10325     { WM_CREATE, sent },
10326     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10327     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10328     { WM_MOVE, sent },
10329     { WM_CHANGEUISTATE, sent|optional },
10330     { 0 }
10331 };
10332
10333 static void test_dialog_messages(void)
10334 {
10335     WNDCLASS cls;
10336     HWND hdlg, hedit1, hedit2, hfocus;
10337     LRESULT ret;
10338
10339 #define set_selection(hctl, start, end) \
10340     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10341     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10342
10343 #define check_selection(hctl, start, end) \
10344     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10345     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10346
10347     subclass_edit();
10348
10349     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10350                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10351                           0, 0, 100, 100, 0, 0, 0, NULL);
10352     ok(hdlg != 0, "Failed to create custom dialog window\n");
10353
10354     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10355                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10356                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10357     ok(hedit1 != 0, "Failed to create edit control\n");
10358     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10359                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10360                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10361     ok(hedit2 != 0, "Failed to create edit control\n");
10362
10363     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10364     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10365
10366     hfocus = GetFocus();
10367     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10368
10369     SetFocus(hedit2);
10370     hfocus = GetFocus();
10371     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10372
10373     check_selection(hedit1, 0, 0);
10374     check_selection(hedit2, 0, 0);
10375
10376     set_selection(hedit2, 0, -1);
10377     check_selection(hedit2, 0, 3);
10378
10379     SetFocus(0);
10380     hfocus = GetFocus();
10381     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10382
10383     flush_sequence();
10384     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10385     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10386     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10387
10388     hfocus = GetFocus();
10389     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10390
10391     check_selection(hedit1, 0, 5);
10392     check_selection(hedit2, 0, 3);
10393
10394     flush_sequence();
10395     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10396     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10397     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10398
10399     hfocus = GetFocus();
10400     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10401
10402     check_selection(hedit1, 0, 5);
10403     check_selection(hedit2, 0, 3);
10404
10405     EndDialog(hdlg, 0);
10406     DestroyWindow(hedit1);
10407     DestroyWindow(hedit2);
10408     DestroyWindow(hdlg);
10409     flush_sequence();
10410
10411 #undef set_selection
10412 #undef check_selection
10413
10414     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10415     cls.lpszClassName = "MyDialogClass";
10416     cls.hInstance = GetModuleHandle(0);
10417     /* need a cast since a dlgproc is used as a wndproc */
10418     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10419     if (!RegisterClass(&cls)) assert(0);
10420
10421     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10422     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10423     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10424     EndDialog(hdlg, 0);
10425     DestroyWindow(hdlg);
10426     flush_sequence();
10427
10428     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10429     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10430     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10431     EndDialog(hdlg, 0);
10432     DestroyWindow(hdlg);
10433     flush_sequence();
10434
10435     UnregisterClass(cls.lpszClassName, cls.hInstance);
10436 }
10437
10438 static void test_nullCallback(void)
10439 {
10440     HWND hwnd;
10441
10442     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10443                            100, 100, 200, 200, 0, 0, 0, NULL);
10444     ok (hwnd != 0, "Failed to create overlapped window\n");
10445
10446     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10447     flush_events();
10448     DestroyWindow(hwnd);
10449 }
10450
10451 /* SetActiveWindow( 0 ) hwnd visible */
10452 static const struct message SetActiveWindowSeq0[] =
10453 {
10454     { HCBT_ACTIVATE, hook|optional },
10455     { WM_NCACTIVATE, sent|wparam, 0 },
10456     { WM_GETTEXT, sent|defwinproc|optional },
10457     { WM_ACTIVATE, sent|wparam, 0 },
10458     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10459     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10460     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10461     { WM_KILLFOCUS, sent|optional },
10462     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10463     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10464     { WM_NCACTIVATE, sent|wparam|optional, 1 },
10465     { WM_GETTEXT, sent|defwinproc|optional },
10466     { WM_ACTIVATE, sent|wparam|optional, 1 },
10467     { HCBT_SETFOCUS, hook|optional },
10468     { WM_KILLFOCUS, sent|defwinproc|optional },
10469     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10470     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10471     { WM_IME_SETCONTEXT, sent|optional },
10472     { WM_IME_SETCONTEXT, sent|optional },
10473     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10474     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10475     { WM_SETFOCUS, sent|defwinproc|optional },
10476     { WM_GETTEXT, sent|optional },
10477     { 0 }
10478 };
10479 /* SetActiveWindow( hwnd ) hwnd visible */
10480 static const struct message SetActiveWindowSeq1[] =
10481 {
10482     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10483     { 0 }
10484 };
10485 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10486 static const struct message SetActiveWindowSeq2[] =
10487 {
10488     { HCBT_ACTIVATE, hook },
10489     { WM_NCACTIVATE, sent|wparam, 0 },
10490     { WM_GETTEXT, sent|defwinproc|optional },
10491     { WM_ACTIVATE, sent|wparam, 0 },
10492     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10493     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10494     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10495     { WM_NCPAINT, sent|optional },
10496     { WM_GETTEXT, sent|defwinproc|optional },
10497     { WM_ERASEBKGND, sent|optional },
10498     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10499     { WM_NCACTIVATE, sent|wparam, 1 },
10500     { WM_GETTEXT, sent|defwinproc|optional },
10501     { WM_ACTIVATE, sent|wparam, 1 },
10502     { HCBT_SETFOCUS, hook },
10503     { WM_KILLFOCUS, sent|defwinproc },
10504     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10505     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10506     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10507     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10508     { WM_SETFOCUS, sent|defwinproc },
10509     { WM_GETTEXT, sent|optional },
10510     { 0 }
10511 };
10512
10513 /* SetActiveWindow( hwnd ) hwnd not visible */
10514 static const struct message SetActiveWindowSeq3[] =
10515 {
10516     { HCBT_ACTIVATE, hook },
10517     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10518     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10519     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10520     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10521     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10522     { WM_ACTIVATEAPP, sent|wparam, 1 },
10523     { WM_ACTIVATEAPP, sent|wparam, 1 },
10524     { WM_NCACTIVATE, sent|wparam, 1 },
10525     { WM_ACTIVATE, sent|wparam, 1 },
10526     { HCBT_SETFOCUS, hook },
10527     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10528     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10529     { WM_SETFOCUS, sent|defwinproc },
10530     { 0 }
10531 };
10532 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10533 static const struct message SetActiveWindowSeq4[] =
10534 {
10535     { HCBT_ACTIVATE, hook },
10536     { WM_NCACTIVATE, sent|wparam, 0 },
10537     { WM_GETTEXT, sent|defwinproc|optional },
10538     { WM_ACTIVATE, sent|wparam, 0 },
10539     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10540     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10541     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10542     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10543     { WM_NCACTIVATE, sent|wparam, 1 },
10544     { WM_GETTEXT, sent|defwinproc|optional },
10545     { WM_ACTIVATE, sent|wparam, 1 },
10546     { HCBT_SETFOCUS, hook },
10547     { WM_KILLFOCUS, sent|defwinproc },
10548     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10549     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10550     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10551     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10552     { WM_SETFOCUS, sent|defwinproc },
10553     { 0 }
10554 };
10555
10556
10557 static void test_SetActiveWindow(void)
10558 {
10559     HWND hwnd, popup, ret;
10560
10561     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10562                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10563                            100, 100, 200, 200, 0, 0, 0, NULL);
10564
10565     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10566                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10567                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10568
10569     ok(hwnd != 0, "Failed to create overlapped window\n");
10570     ok(popup != 0, "Failed to create popup window\n");
10571     SetForegroundWindow( popup );
10572     flush_sequence();
10573
10574     trace("SetActiveWindow(0)\n");
10575     ret = SetActiveWindow(0);
10576     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10577     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10578     flush_sequence();
10579
10580     trace("SetActiveWindow(hwnd), hwnd visible\n");
10581     ret = SetActiveWindow(hwnd);
10582     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10583     flush_sequence();
10584
10585     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10586     ret = SetActiveWindow(popup);
10587     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10588     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10589     flush_sequence();
10590
10591     ShowWindow(hwnd, SW_HIDE);
10592     ShowWindow(popup, SW_HIDE);
10593     flush_sequence();
10594
10595     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10596     ret = SetActiveWindow(hwnd);
10597     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10598     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10599     flush_sequence();
10600
10601     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10602     ret = SetActiveWindow(popup);
10603     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10604     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10605     flush_sequence();
10606
10607     trace("done\n");
10608
10609     DestroyWindow(hwnd);
10610 }
10611
10612 static const struct message SetForegroundWindowSeq[] =
10613 {
10614     { WM_NCACTIVATE, sent|wparam, 0 },
10615     { WM_GETTEXT, sent|defwinproc|optional },
10616     { WM_ACTIVATE, sent|wparam, 0 },
10617     { WM_ACTIVATEAPP, sent|wparam, 0 },
10618     { WM_KILLFOCUS, sent },
10619     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10620     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10621     { 0 }
10622 };
10623
10624 static void test_SetForegroundWindow(void)
10625 {
10626     HWND hwnd;
10627
10628     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10629                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10630                            100, 100, 200, 200, 0, 0, 0, NULL);
10631     ok (hwnd != 0, "Failed to create overlapped window\n");
10632     SetForegroundWindow( hwnd );
10633     flush_sequence();
10634
10635     trace("SetForegroundWindow( 0 )\n");
10636     SetForegroundWindow( 0 );
10637     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10638     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10639     SetForegroundWindow( GetDesktopWindow() );
10640     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10641                                         "foreground top level window", FALSE);
10642     trace("done\n");
10643
10644     DestroyWindow(hwnd);
10645 }
10646
10647 static void test_dbcs_wm_char(void)
10648 {
10649     BYTE dbch[2];
10650     WCHAR wch, bad_wch;
10651     HWND hwnd, hwnd2;
10652     MSG msg;
10653     DWORD time;
10654     POINT pt;
10655     DWORD_PTR res;
10656     CPINFOEXA cpinfo;
10657     UINT i, j, k;
10658     struct message wmCharSeq[2];
10659
10660     if (!pGetCPInfoExA)
10661     {
10662         win_skip("GetCPInfoExA is not available\n");
10663         return;
10664     }
10665
10666     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10667     if (cpinfo.MaxCharSize != 2)
10668     {
10669         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10670         return;
10671     }
10672
10673     dbch[0] = dbch[1] = 0;
10674     wch = 0;
10675     bad_wch = cpinfo.UnicodeDefaultChar;
10676     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10677         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10678             for (k = 128; k <= 255; k++)
10679             {
10680                 char str[2];
10681                 WCHAR wstr[2];
10682                 str[0] = j;
10683                 str[1] = k;
10684                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10685                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10686                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10687                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10688                 {
10689                     dbch[0] = j;
10690                     dbch[1] = k;
10691                     wch = wstr[0];
10692                     break;
10693                 }
10694             }
10695
10696     if (!wch)
10697     {
10698         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10699         return;
10700     }
10701     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10702            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10703
10704     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10705                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10706     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10707                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10708     ok (hwnd != 0, "Failed to create overlapped window\n");
10709     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10710     flush_sequence();
10711
10712     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10713     wmCharSeq[0].message = WM_CHAR;
10714     wmCharSeq[0].flags = sent|wparam;
10715     wmCharSeq[0].wParam = wch;
10716
10717     /* posted message */
10718     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10719     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10720     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10721     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10722     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10723     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10724     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10725
10726     /* posted thread message */
10727     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10728     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10729     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10730     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10731     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10732     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10733     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10734
10735     /* sent message */
10736     flush_sequence();
10737     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10738     ok_sequence( WmEmptySeq, "no messages", FALSE );
10739     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10740     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10741     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10742
10743     /* sent message with timeout */
10744     flush_sequence();
10745     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10746     ok_sequence( WmEmptySeq, "no messages", FALSE );
10747     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10748     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10749     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10750
10751     /* sent message with timeout and callback */
10752     flush_sequence();
10753     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10754     ok_sequence( WmEmptySeq, "no messages", FALSE );
10755     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10756     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10757     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10758
10759     /* sent message with callback */
10760     flush_sequence();
10761     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10762     ok_sequence( WmEmptySeq, "no messages", FALSE );
10763     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10764     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10765     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10766
10767     /* direct window proc call */
10768     flush_sequence();
10769     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10770     ok_sequence( WmEmptySeq, "no messages", FALSE );
10771     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10772     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10773
10774     /* dispatch message */
10775     msg.hwnd = hwnd;
10776     msg.message = WM_CHAR;
10777     msg.wParam = dbch[0];
10778     msg.lParam = 0;
10779     DispatchMessageA( &msg );
10780     ok_sequence( WmEmptySeq, "no messages", FALSE );
10781     msg.wParam = dbch[1];
10782     DispatchMessageA( &msg );
10783     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10784
10785     /* window handle is irrelevant */
10786     flush_sequence();
10787     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10788     ok_sequence( WmEmptySeq, "no messages", FALSE );
10789     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10790     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10791     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10792
10793     /* interleaved post and send */
10794     flush_sequence();
10795     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10796     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10797     ok_sequence( WmEmptySeq, "no messages", FALSE );
10798     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10799     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10800     ok_sequence( WmEmptySeq, "no messages", FALSE );
10801     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10802     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10803     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10804     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10805     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10806     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10807     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10808
10809     /* interleaved sent message and winproc */
10810     flush_sequence();
10811     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10812     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, 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     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10817     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10818
10819     /* interleaved winproc and dispatch */
10820     msg.hwnd = hwnd;
10821     msg.message = WM_CHAR;
10822     msg.wParam = dbch[0];
10823     msg.lParam = 0;
10824     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10825     DispatchMessageA( &msg );
10826     ok_sequence( WmEmptySeq, "no messages", FALSE );
10827     msg.wParam = dbch[1];
10828     DispatchMessageA( &msg );
10829     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10830     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10831     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10832
10833     /* interleaved sends */
10834     flush_sequence();
10835     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10836     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10837     ok_sequence( WmEmptySeq, "no messages", FALSE );
10838     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10839     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10840     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10841     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10842
10843     /* dbcs WM_CHAR */
10844     flush_sequence();
10845     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10846     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10847     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10848
10849     /* other char messages are not magic */
10850     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10851     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10852     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10853     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10854     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10855     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10856     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10857     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10858     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10859     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10860
10861     /* test retrieving messages */
10862
10863     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10864     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10865     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10866     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10867     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10868     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10869     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10870     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10871     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10872     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10873
10874     /* message filters */
10875     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10876     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10877     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10878     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10879     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10880     /* message id is filtered, hwnd is not */
10881     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10882     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10883     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10884     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10885     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10886     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10887
10888     /* mixing GetMessage and PostMessage */
10889     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10890     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10891     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10892     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10893     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10894     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10895     time = msg.time;
10896     pt = msg.pt;
10897     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10898     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10899     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10900     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10901     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10902     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10903     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10904     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 );
10905     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10906
10907     /* without PM_REMOVE */
10908     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10909     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10910     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10911     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10912     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10913     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10914     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10915     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10916     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10917     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10918     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10919     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10920     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10921     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10922     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10923     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10924     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10925     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10926
10927     DestroyWindow(hwnd);
10928 }
10929
10930 #define ID_LISTBOX 0x000f
10931
10932 static const struct message wm_lb_setcursel_0[] =
10933 {
10934     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10935     { WM_CTLCOLORLISTBOX, sent|parent },
10936     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10937     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10938     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10939     { 0 }
10940 };
10941 static const struct message wm_lb_setcursel_1[] =
10942 {
10943     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10944     { WM_CTLCOLORLISTBOX, sent|parent },
10945     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10946     { WM_CTLCOLORLISTBOX, sent|parent },
10947     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10948     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10949     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10950     { 0 }
10951 };
10952 static const struct message wm_lb_setcursel_2[] =
10953 {
10954     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10955     { WM_CTLCOLORLISTBOX, sent|parent },
10956     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10957     { WM_CTLCOLORLISTBOX, sent|parent },
10958     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10959     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10960     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10961     { 0 }
10962 };
10963 static const struct message wm_lb_click_0[] =
10964 {
10965     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10966     { HCBT_SETFOCUS, hook },
10967     { WM_KILLFOCUS, sent|parent },
10968     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10969     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10970     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10971     { WM_SETFOCUS, sent|defwinproc },
10972
10973     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10974     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10975     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10976     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10977     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10978
10979     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10980     { WM_CTLCOLORLISTBOX, sent|parent },
10981     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10982     { WM_CTLCOLORLISTBOX, sent|parent },
10983     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10984     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10985
10986     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10987     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10988
10989     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10990     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10991     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10992     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10993     { 0 }
10994 };
10995
10996 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10997
10998 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10999
11000 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11001 {
11002     static long defwndproc_counter = 0;
11003     LRESULT ret;
11004     struct recvd_message msg;
11005
11006     /* do not log painting messages */
11007     if (message != WM_PAINT &&
11008         message != WM_NCPAINT &&
11009         message != WM_SYNCPAINT &&
11010         message != WM_ERASEBKGND &&
11011         message != WM_NCHITTEST &&
11012         message != WM_GETTEXT &&
11013         message != WM_GETOBJECT &&
11014         message != WM_GETICON &&
11015         message != WM_DEVICECHANGE)
11016     {
11017         msg.hwnd = hwnd;
11018         msg.message = message;
11019         msg.flags = sent|wparam|lparam;
11020         if (defwndproc_counter) msg.flags |= defwinproc;
11021         msg.wParam = wp;
11022         msg.lParam = lp;
11023         msg.descr = "listbox";
11024         add_message(&msg);
11025     }
11026
11027     defwndproc_counter++;
11028     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11029     defwndproc_counter--;
11030
11031     return ret;
11032 }
11033
11034 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11035                                int caret_index, int top_index, int line)
11036 {
11037     LRESULT ret;
11038
11039     /* calling an orig proc helps to avoid unnecessary message logging */
11040     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11041     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11042     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11043     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11044     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11045     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
11046     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11047     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11048 }
11049
11050 static void test_listbox_messages(void)
11051 {
11052     HWND parent, listbox;
11053     LRESULT ret;
11054
11055     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11056                              100, 100, 200, 200, 0, 0, 0, NULL);
11057     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11058                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11059                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11060     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11061
11062     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11063
11064     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11065     ok(ret == 0, "expected 0, got %ld\n", ret);
11066     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11067     ok(ret == 1, "expected 1, got %ld\n", ret);
11068     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11069     ok(ret == 2, "expected 2, got %ld\n", ret);
11070
11071     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11072
11073     flush_sequence();
11074
11075     log_all_parent_messages++;
11076
11077     trace("selecting item 0\n");
11078     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11079     ok(ret == 0, "expected 0, got %ld\n", ret);
11080     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11081     check_lb_state(listbox, 3, 0, 0, 0);
11082     flush_sequence();
11083
11084     trace("selecting item 1\n");
11085     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11086     ok(ret == 1, "expected 1, got %ld\n", ret);
11087     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11088     check_lb_state(listbox, 3, 1, 1, 0);
11089
11090     trace("selecting item 2\n");
11091     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11092     ok(ret == 2, "expected 2, got %ld\n", ret);
11093     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11094     check_lb_state(listbox, 3, 2, 2, 0);
11095
11096     trace("clicking on item 0\n");
11097     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11098     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11099     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11100     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11101     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11102     check_lb_state(listbox, 3, 0, 0, 0);
11103     flush_sequence();
11104
11105     log_all_parent_messages--;
11106
11107     DestroyWindow(listbox);
11108     DestroyWindow(parent);
11109 }
11110
11111 /*************************** Menu test ******************************/
11112 static const struct message wm_popup_menu_1[] =
11113 {
11114     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11115     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11116     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11117     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11118     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11119     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11120     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11121     { WM_INITMENU, sent|lparam, 0, 0 },
11122     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11123     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11124     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11125     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11126     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11127     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11128     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11129     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11130     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11131     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11132     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11133     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11134     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11135     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11136     { 0 }
11137 };
11138 static const struct message wm_popup_menu_2[] =
11139 {
11140     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11141     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11142     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11143     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11144     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11145     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11146     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11147     { WM_INITMENU, sent|lparam, 0, 0 },
11148     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11149     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11150     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11151     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11152     { HCBT_CREATEWND, hook },
11153     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11154                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11155     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11156     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11157     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11158     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11159     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11160     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11161     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11162     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11163     { HCBT_DESTROYWND, hook },
11164     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11165     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11166     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11167     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11168     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11169     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11170     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11171     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11172     { 0 }
11173 };
11174 static const struct message wm_popup_menu_3[] =
11175 {
11176     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11177     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11178     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11179     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11180     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11181     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11182     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11183     { WM_INITMENU, sent|lparam, 0, 0 },
11184     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11185     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11186     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11187     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11188     { HCBT_CREATEWND, hook },
11189     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11190                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11191     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11192     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11193     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11194     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11195     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11196     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11197     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11198     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11199     { HCBT_DESTROYWND, hook },
11200     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11201     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11202     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11203     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11204     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11205     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11206     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11207     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11208     { 0 }
11209 };
11210
11211 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11212 {
11213     if (message == WM_ENTERIDLE ||
11214         message == WM_INITMENU ||
11215         message == WM_INITMENUPOPUP ||
11216         message == WM_MENUSELECT ||
11217         message == WM_PARENTNOTIFY ||
11218         message == WM_ENTERMENULOOP ||
11219         message == WM_EXITMENULOOP ||
11220         message == WM_UNINITMENUPOPUP ||
11221         message == WM_KEYDOWN ||
11222         message == WM_KEYUP ||
11223         message == WM_CHAR ||
11224         message == WM_SYSKEYDOWN ||
11225         message == WM_SYSKEYUP ||
11226         message == WM_SYSCHAR ||
11227         message == WM_COMMAND ||
11228         message == WM_MENUCOMMAND)
11229     {
11230         struct recvd_message msg;
11231
11232         msg.hwnd = hwnd;
11233         msg.message = message;
11234         msg.flags = sent|wparam|lparam;
11235         msg.wParam = wp;
11236         msg.lParam = lp;
11237         msg.descr = "parent_menu_proc";
11238         add_message(&msg);
11239     }
11240
11241     return DefWindowProcA(hwnd, message, wp, lp);
11242 }
11243
11244 static void set_menu_style(HMENU hmenu, DWORD style)
11245 {
11246     MENUINFO mi;
11247     BOOL ret;
11248
11249     mi.cbSize = sizeof(mi);
11250     mi.fMask = MIM_STYLE;
11251     mi.dwStyle = style;
11252     SetLastError(0xdeadbeef);
11253     ret = pSetMenuInfo(hmenu, &mi);
11254     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11255 }
11256
11257 static DWORD get_menu_style(HMENU hmenu)
11258 {
11259     MENUINFO mi;
11260     BOOL ret;
11261
11262     mi.cbSize = sizeof(mi);
11263     mi.fMask = MIM_STYLE;
11264     mi.dwStyle = 0;
11265     SetLastError(0xdeadbeef);
11266     ret = pGetMenuInfo(hmenu, &mi);
11267     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11268
11269     return mi.dwStyle;
11270 }
11271
11272 static void test_menu_messages(void)
11273 {
11274     MSG msg;
11275     WNDCLASSA cls;
11276     HMENU hmenu, hmenu_popup;
11277     HWND hwnd;
11278     DWORD style;
11279
11280     if (!pGetMenuInfo || !pSetMenuInfo)
11281     {
11282         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11283         return;
11284     }
11285     cls.style = 0;
11286     cls.lpfnWndProc = parent_menu_proc;
11287     cls.cbClsExtra = 0;
11288     cls.cbWndExtra = 0;
11289     cls.hInstance = GetModuleHandleA(0);
11290     cls.hIcon = 0;
11291     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11292     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11293     cls.lpszMenuName = NULL;
11294     cls.lpszClassName = "TestMenuClass";
11295     UnregisterClass(cls.lpszClassName, cls.hInstance);
11296     if (!RegisterClassA(&cls)) assert(0);
11297
11298     SetLastError(0xdeadbeef);
11299     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11300                            100, 100, 200, 200, 0, 0, 0, NULL);
11301     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11302
11303     SetLastError(0xdeadbeef);
11304     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11305     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11306
11307     SetMenu(hwnd, hmenu);
11308     SetForegroundWindow( hwnd );
11309
11310     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11311     style = get_menu_style(hmenu);
11312     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11313
11314     hmenu_popup = GetSubMenu(hmenu, 0);
11315     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11316     style = get_menu_style(hmenu_popup);
11317     ok(style == 0, "expected 0, got %u\n", style);
11318
11319     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11320     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11321     style = get_menu_style(hmenu_popup);
11322     ok(style == 0, "expected 0, got %u\n", style);
11323
11324     /* Alt+E, Enter */
11325     trace("testing a popup menu command\n");
11326     flush_sequence();
11327     keybd_event(VK_MENU, 0, 0, 0);
11328     keybd_event('E', 0, 0, 0);
11329     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11330     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11331     keybd_event(VK_RETURN, 0, 0, 0);
11332     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11333     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11334     {
11335         TranslateMessage(&msg);
11336         DispatchMessage(&msg);
11337     }
11338     if (!sequence_cnt)  /* we didn't get any message */
11339     {
11340         skip( "queuing key events not supported\n" );
11341         goto done;
11342     }
11343     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11344     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11345     {
11346         win_skip( "menu tracking through VK_MENU not supported\n" );
11347         goto done;
11348     }
11349     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11350
11351     /* Alt+F, Right, Enter */
11352     trace("testing submenu of a popup menu command\n");
11353     flush_sequence();
11354     keybd_event(VK_MENU, 0, 0, 0);
11355     keybd_event('F', 0, 0, 0);
11356     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11357     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11358     keybd_event(VK_RIGHT, 0, 0, 0);
11359     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11360     keybd_event(VK_RETURN, 0, 0, 0);
11361     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11362     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11363     {
11364         TranslateMessage(&msg);
11365         DispatchMessage(&msg);
11366     }
11367     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11368
11369     set_menu_style(hmenu, 0);
11370     style = get_menu_style(hmenu);
11371     ok(style == 0, "expected 0, got %u\n", style);
11372
11373     hmenu_popup = GetSubMenu(hmenu, 0);
11374     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11375     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11376     style = get_menu_style(hmenu_popup);
11377     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11378
11379     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11380     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11381     style = get_menu_style(hmenu_popup);
11382     ok(style == 0, "expected 0, got %u\n", style);
11383
11384     /* Alt+F, Right, Enter */
11385     trace("testing submenu of a popup menu command\n");
11386     flush_sequence();
11387     keybd_event(VK_MENU, 0, 0, 0);
11388     keybd_event('F', 0, 0, 0);
11389     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11390     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11391     keybd_event(VK_RIGHT, 0, 0, 0);
11392     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11393     keybd_event(VK_RETURN, 0, 0, 0);
11394     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11395     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11396     {
11397         TranslateMessage(&msg);
11398         DispatchMessage(&msg);
11399     }
11400     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11401
11402 done:
11403     DestroyWindow(hwnd);
11404     DestroyMenu(hmenu);
11405 }
11406
11407
11408 static void test_paintingloop(void)
11409 {
11410     HWND hwnd;
11411
11412     paint_loop_done = 0;
11413     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11414                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11415                                 100, 100, 100, 100, 0, 0, 0, NULL );
11416     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11417     ShowWindow(hwnd,SW_NORMAL);
11418     SetFocus(hwnd);
11419
11420     while (!paint_loop_done)
11421     {
11422         MSG msg;
11423         if (PeekMessageA(&msg, 0, 0, 0, 1))
11424         {
11425             TranslateMessage(&msg);
11426             DispatchMessage(&msg);
11427         }
11428     }
11429     DestroyWindow(hwnd);
11430 }
11431
11432 static void test_defwinproc(void)
11433 {
11434     HWND hwnd;
11435     MSG msg;
11436     int gotwmquit = FALSE;
11437     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11438     assert(hwnd);
11439     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11440     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11441         if( msg.message == WM_QUIT) gotwmquit = TRUE;
11442         DispatchMessageA( &msg );
11443     }
11444     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11445     DestroyWindow( hwnd);
11446 }
11447
11448 START_TEST(msg)
11449 {
11450     BOOL ret;
11451     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11452
11453     init_procs();
11454
11455     if (!RegisterWindowClasses()) assert(0);
11456
11457     if (pSetWinEventHook)
11458     {
11459         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11460                                        GetModuleHandleA(0), win_event_proc,
11461                                        0, GetCurrentThreadId(),
11462                                        WINEVENT_INCONTEXT);
11463         if (pIsWinEventHookInstalled && hEvent_hook)
11464         {
11465             UINT event;
11466             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11467                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11468         }
11469     }
11470     if (!hEvent_hook) win_skip( "no win event hook support\n" );
11471
11472     cbt_hook_thread_id = GetCurrentThreadId();
11473     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11474     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
11475
11476     test_winevents();
11477
11478     /* Fix message sequences before removing 4 lines below */
11479 #if 1
11480     if (pUnhookWinEvent && hEvent_hook)
11481     {
11482         ret = pUnhookWinEvent(hEvent_hook);
11483         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11484         pUnhookWinEvent = 0;
11485     }
11486     hEvent_hook = 0;
11487 #endif
11488
11489     test_ShowWindow();
11490     test_PeekMessage();
11491     test_PeekMessage2();
11492     test_scrollwindowex();
11493     test_messages();
11494     test_setwindowpos();
11495     test_showwindow();
11496     invisible_parent_tests();
11497     test_mdi_messages();
11498     test_button_messages();
11499     test_static_messages();
11500     test_listbox_messages();
11501     test_combobox_messages();
11502     test_wmime_keydown_message();
11503     test_paint_messages();
11504     test_interthread_messages();
11505     test_message_conversion();
11506     test_accelerators();
11507     test_timers();
11508     test_timers_no_wnd();
11509     if (hCBT_hook) test_set_hook();
11510     test_DestroyWindow();
11511     test_DispatchMessage();
11512     test_SendMessageTimeout();
11513     test_edit_messages();
11514     test_quit_message();
11515     test_SetActiveWindow();
11516
11517     if (!pTrackMouseEvent)
11518         win_skip("TrackMouseEvent is not available\n");
11519     else
11520         test_TrackMouseEvent();
11521
11522     test_SetWindowRgn();
11523     test_sys_menu();
11524     test_dialog_messages();
11525     test_nullCallback();
11526     test_dbcs_wm_char();
11527     test_menu_messages();
11528     test_paintingloop();
11529     test_defwinproc();
11530     /* keep it the last test, under Windows it tends to break the tests
11531      * which rely on active/foreground windows being correct.
11532      */
11533     test_SetForegroundWindow();
11534
11535     UnhookWindowsHookEx(hCBT_hook);
11536     if (pUnhookWinEvent && hEvent_hook)
11537     {
11538         ret = pUnhookWinEvent(hEvent_hook);
11539         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11540         SetLastError(0xdeadbeef);
11541         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11542         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11543            GetLastError() == 0xdeadbeef, /* Win9x */
11544            "unexpected error %d\n", GetLastError());
11545     }
11546 }