user32/tests: Fix some more msg test failures and improve message sequence tracing.
[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_PAINT, sent|optional },
184     { WM_NCPAINT, sent|beginpaint|optional },
185     { WM_ERASEBKGND, sent|beginpaint|optional },
186     { 0 }
187 };
188 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
189  * for a visible overlapped window.
190  */
191 static const struct message WmSWP_HideOverlappedSeq[] = {
192     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
193     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
194     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
195     { 0 }
196 };
197
198 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
199  * for a visible overlapped window.
200  */
201 static const struct message WmSWP_ResizeSeq[] = {
202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
203     { WM_GETMINMAXINFO, sent|defwinproc },
204     { WM_NCCALCSIZE, sent|wparam, TRUE },
205     { WM_NCPAINT, sent|optional },
206     { WM_GETTEXT, sent|defwinproc|optional },
207     { WM_ERASEBKGND, sent|optional },
208     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
209     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
210     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
211     { WM_NCPAINT, sent|optional },
212     { WM_GETTEXT, sent|defwinproc|optional },
213     { WM_ERASEBKGND, sent|optional },
214     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
215     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
216     { 0 }
217 };
218
219 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
220  * for a visible popup window.
221  */
222 static const struct message WmSWP_ResizePopupSeq[] = {
223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
224     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
225     { WM_NCCALCSIZE, sent|wparam, TRUE },
226     { WM_NCPAINT, sent|optional },
227     { WM_GETTEXT, sent|defwinproc|optional },
228     { WM_ERASEBKGND, sent|optional },
229     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
230     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
231     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
232     { WM_NCPAINT, sent|optional },
233     { WM_GETTEXT, sent|defwinproc|optional },
234     { WM_ERASEBKGND, sent|optional },
235     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
236     { 0 }
237 };
238
239 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
240  * for a visible overlapped window.
241  */
242 static const struct message WmSWP_MoveSeq[] = {
243     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
244     { WM_NCPAINT, sent|optional },
245     { WM_GETTEXT, sent|defwinproc|optional },
246     { WM_ERASEBKGND, sent|optional },
247     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
248     { WM_MOVE, sent|defwinproc|wparam, 0 },
249     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
250     { 0 }
251 };
252 /* Resize with SetWindowPos(SWP_NOZORDER)
253  * for a visible overlapped window
254  * SWP_NOZORDER is stripped by the logging code
255  */
256 static const struct message WmSWP_ResizeNoZOrder[] = {
257     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
258     { WM_GETMINMAXINFO, sent|defwinproc },
259     { WM_NCCALCSIZE, sent|wparam, 1 },
260     { WM_NCPAINT, sent },
261     { WM_GETTEXT, sent|defwinproc|optional },
262     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
263     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE },
264     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
265     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
266     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
267     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
268     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
269     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
270     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
271     { 0 }
272 };
273
274 /* Switch visible mdi children */
275 static const struct message WmSwitchChild[] = {
276     /* Switch MDI child */
277     { WM_MDIACTIVATE, sent },/* in the MDI client */
278     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
279     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
280     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
281     /* Deactivate 2nd MDI child */
282     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
283     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
284     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
285     /* Preparing for maximize and maximaze the 1st MDI child */
286     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
287     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
288     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
289     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
290     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
291     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
292     /* Lock redraw 2nd MDI child */
293     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
294     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
295     /* Restore 2nd MDI child */
296     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
297     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
298     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
299     { 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 */
300     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
301     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
302     /* Redraw 2nd MDI child */
303     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
304     /* Redraw MDI frame */
305     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
306     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
307     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
308     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
309     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
310     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
311     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
312     { HCBT_SETFOCUS, hook },
313     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
314     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
315     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
316     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
317     { WM_SETFOCUS, sent },/* in the MDI client */
318     { HCBT_SETFOCUS, hook },
319     { WM_KILLFOCUS, sent },/* in the MDI client */
320     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
321     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
322     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
323     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
324     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
325     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
326     { 0 }
327 };
328
329 /* Switch visible not maximized mdi children */
330 static const struct message WmSwitchNotMaximizedChild[] = {
331     /* Switch not maximized MDI child */
332     { WM_MDIACTIVATE, sent },/* in the MDI client */
333     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
334     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
335     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
336     /* Deactivate 1st MDI child */
337     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
338     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
339     /* Activate 2nd MDI child */
340     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
341     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
342     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
343     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
344     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
345     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
346     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
347     { HCBT_SETFOCUS, hook },
348     { WM_KILLFOCUS, sent }, /* in the  MDI client */
349     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
350     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
351     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
352     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
354     { 0 }
355 };
356
357
358 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
359                 SWP_NOZORDER|SWP_FRAMECHANGED)
360  * for a visible overlapped window with WS_CLIPCHILDREN style set.
361  */
362 static const struct message WmSWP_FrameChanged_clip[] = {
363     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
364     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
365     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
366     { WM_GETTEXT, sent|parent|defwinproc|optional },
367     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
368     { WM_NCPAINT, sent }, /* wparam != 1 */
369     { WM_ERASEBKGND, sent },
370     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
371     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
372     { WM_PAINT, sent },
373     { 0 }
374 };
375 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
376                 SWP_NOZORDER|SWP_FRAMECHANGED)
377  * for a visible overlapped window.
378  */
379 static const struct message WmSWP_FrameChangedDeferErase[] = {
380     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
381     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
382     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
383     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
384     { WM_PAINT, sent|parent },
385     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
386     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
387     { WM_PAINT, sent },
388     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
389     { WM_ERASEBKGND, sent|beginpaint },
390     { 0 }
391 };
392
393 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
394                 SWP_NOZORDER|SWP_FRAMECHANGED)
395  * for a visible overlapped window without WS_CLIPCHILDREN style set.
396  */
397 static const struct message WmSWP_FrameChanged_noclip[] = {
398     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
399     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
400     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
401     { WM_GETTEXT, sent|parent|defwinproc|optional },
402     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
403     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
404     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
405     { WM_PAINT, sent },
406     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
407     { WM_ERASEBKGND, sent|beginpaint },
408     { 0 }
409 };
410
411 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
412 static const struct message WmShowOverlappedSeq[] = {
413     { WM_SHOWWINDOW, sent|wparam, 1 },
414     { WM_NCPAINT, sent|wparam|optional, 1 },
415     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
416     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
417     { WM_NCPAINT, sent|wparam|optional, 1 },
418     { WM_GETTEXT, sent|defwinproc|optional },
419     { WM_ERASEBKGND, sent|optional },
420     { HCBT_ACTIVATE, hook },
421     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
422     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
423     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
424     { WM_NCPAINT, sent|wparam|optional, 1 },
425     { WM_ACTIVATEAPP, sent|wparam, 1 },
426     { WM_NCACTIVATE, sent|wparam, 1 },
427     { WM_GETTEXT, sent|defwinproc|optional },
428     { WM_ACTIVATE, sent|wparam, 1 },
429     { HCBT_SETFOCUS, hook },
430     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
431     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
432     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
433     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
434     { WM_GETTEXT, sent|optional },
435     { WM_NCPAINT, sent|wparam|optional, 1 },
436     { WM_GETTEXT, sent|defwinproc|optional },
437     { WM_ERASEBKGND, sent|optional },
438     /* Win9x adds SWP_NOZORDER below */
439     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
440     { WM_NCCALCSIZE, sent|optional },
441     { WM_GETTEXT, sent|optional },
442     { WM_NCPAINT, sent|optional },
443     { WM_ERASEBKGND, sent|optional },
444 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
445        * messages. Does that mean that CreateWindow doesn't set initial
446        * window dimensions for overlapped windows?
447        */
448     { WM_SIZE, sent },
449     { WM_MOVE, sent },
450 #endif
451     { WM_PAINT, sent|optional },
452     { WM_NCPAINT, sent|beginpaint|optional },
453     { 0 }
454 };
455 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
456 static const struct message WmShowMaxOverlappedSeq[] = {
457     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
458     { WM_GETMINMAXINFO, sent },
459     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
460     { WM_GETMINMAXINFO, sent|defwinproc },
461     { WM_NCCALCSIZE, sent|wparam, TRUE },
462     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
463     { HCBT_ACTIVATE, hook },
464     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
465     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
466     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
467     { WM_ACTIVATEAPP, sent|wparam, 1 },
468     { WM_NCACTIVATE, sent|wparam, 1 },
469     { WM_GETTEXT, sent|defwinproc|optional },
470     { WM_ACTIVATE, sent|wparam, 1 },
471     { HCBT_SETFOCUS, hook },
472     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
473     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
474     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
475     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
476     { WM_GETTEXT, sent|optional },
477     { WM_NCPAINT, sent|wparam|optional, 1 },
478     { WM_GETTEXT, sent|defwinproc|optional },
479     { WM_ERASEBKGND, sent|optional },
480     /* Win9x adds SWP_NOZORDER below */
481     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
482     { WM_MOVE, sent|defwinproc },
483     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
484     { WM_GETTEXT, sent|optional },
485     { WM_NCCALCSIZE, sent|optional },
486     { WM_NCPAINT, sent|optional },
487     { WM_ERASEBKGND, sent|optional },
488     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
489     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
490     { WM_PAINT, sent|optional },
491     { WM_NCPAINT, sent|beginpaint|optional },
492     { WM_ERASEBKGND, sent|beginpaint|optional },
493     { 0 }
494 };
495 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
496 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
497     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
498     { WM_GETTEXT, sent|optional },
499     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
500     { WM_GETMINMAXINFO, sent|defwinproc },
501     { WM_NCCALCSIZE, sent|wparam, TRUE },
502     { WM_NCPAINT, sent|optional },
503     { WM_GETTEXT, sent|defwinproc|optional },
504     { WM_ERASEBKGND, sent|optional },
505     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
506     { WM_MOVE, sent|defwinproc|optional },
507     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
508     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
509     { WM_NCPAINT, sent|optional },
510     { WM_ERASEBKGND, sent|optional },
511     { WM_PAINT, sent|optional },
512     { WM_NCPAINT, sent|beginpaint|optional },
513     { WM_ERASEBKGND, sent|beginpaint|optional },
514     { 0 }
515 };
516 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
517 static const struct message WmShowRestoreMinOverlappedSeq[] = {
518     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
519     { WM_QUERYOPEN, sent|optional },
520     { WM_GETTEXT, sent|optional },
521     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
522     { WM_GETMINMAXINFO, sent|defwinproc },
523     { WM_NCCALCSIZE, sent|wparam, TRUE },
524     { HCBT_ACTIVATE, hook },
525     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
526     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
527     { WM_ACTIVATEAPP, sent|wparam, 1 },
528     { WM_NCACTIVATE, sent|wparam, 1 },
529     { WM_GETTEXT, sent|defwinproc|optional },
530     { WM_ACTIVATE, sent|wparam, 1 },
531     { HCBT_SETFOCUS, hook },
532     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
533     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
534     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
535     { WM_GETTEXT, sent|optional },
536     { WM_NCPAINT, sent|wparam|optional, 1 },
537     { WM_GETTEXT, sent|defwinproc|optional },
538     { WM_ERASEBKGND, sent },
539     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
540     { WM_MOVE, sent|defwinproc },
541     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
542     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
543     { WM_NCPAINT, sent|wparam|optional, 1 },
544     { WM_ERASEBKGND, sent|optional },
545     { WM_ACTIVATE, sent|wparam, 1 },
546     { WM_GETTEXT, sent|optional },
547     { WM_PAINT, sent|optional },
548     { WM_NCPAINT, sent|beginpaint|optional },
549     { WM_ERASEBKGND, sent|beginpaint|optional },
550     { 0 }
551 };
552 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
553 static const struct message WmShowMinOverlappedSeq[] = {
554     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
555     { HCBT_SETFOCUS, hook },
556     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
557     { WM_KILLFOCUS, sent },
558     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
559     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
560     { WM_GETTEXT, sent|optional },
561     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
562     { WM_GETMINMAXINFO, sent|defwinproc },
563     { WM_NCCALCSIZE, sent|wparam, TRUE },
564     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
565     { WM_NCPAINT, sent|optional },
566     { WM_GETTEXT, sent|defwinproc|optional },
567     { WM_WINDOWPOSCHANGED, sent },
568     { WM_MOVE, sent|defwinproc },
569     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
570     { WM_NCCALCSIZE, sent|optional },
571     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
572     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
573     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
574     { WM_NCACTIVATE, sent|wparam, 0 },
575     { WM_GETTEXT, sent|defwinproc|optional },
576     { WM_ACTIVATE, sent },
577     { WM_ACTIVATEAPP, sent|wparam, 0 },
578     { WM_PAINT, sent|optional },
579     { WM_NCPAINT, sent|beginpaint|optional },
580     { WM_ERASEBKGND, sent|beginpaint|optional },
581     { 0 }
582 };
583 /* ShowWindow(SW_HIDE) for a visible overlapped window */
584 static const struct message WmHideOverlappedSeq[] = {
585     { WM_SHOWWINDOW, sent|wparam, 0 },
586     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
587     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
588     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
589     { WM_SIZE, sent|optional }, /* XP doesn't send it */
590     { WM_MOVE, sent|optional }, /* XP doesn't send it */
591     { WM_NCACTIVATE, sent|wparam, 0 },
592     { WM_ACTIVATE, sent|wparam, 0 },
593     { WM_ACTIVATEAPP, sent|wparam, 0 },
594     { WM_KILLFOCUS, sent|wparam, 0 },
595     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
596     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
597     { 0 }
598 };
599 /* DestroyWindow for a visible overlapped window */
600 static const struct message WmDestroyOverlappedSeq[] = {
601     { HCBT_DESTROYWND, hook },
602     { 0x0090, sent|optional },
603     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
604     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
605     { 0x0090, sent|optional },
606     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
607     { WM_NCACTIVATE, sent|optional|wparam, 0 },
608     { WM_ACTIVATE, sent|optional|wparam, 0 },
609     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
610     { WM_KILLFOCUS, sent|optional|wparam, 0 },
611     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
612     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
613     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
614     { WM_DESTROY, sent },
615     { WM_NCDESTROY, sent },
616     { 0 }
617 };
618 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
619 static const struct message WmCreateMaxPopupSeq[] = {
620     { HCBT_CREATEWND, hook },
621     { WM_NCCREATE, sent },
622     { WM_NCCALCSIZE, sent|wparam, 0 },
623     { WM_CREATE, sent },
624     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
625     { WM_SIZE, sent|wparam, SIZE_RESTORED },
626     { WM_MOVE, sent },
627     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
628     { WM_GETMINMAXINFO, sent },
629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
630     { WM_NCCALCSIZE, sent|wparam, TRUE },
631     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
632     { WM_MOVE, sent|defwinproc },
633     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
635     { WM_SHOWWINDOW, sent|wparam, 1 },
636     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
637     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
638     { HCBT_ACTIVATE, hook },
639     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
640     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
641     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
642     { WM_NCPAINT, sent|wparam|optional, 1 },
643     { WM_ERASEBKGND, sent|optional },
644     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
645     { WM_ACTIVATEAPP, sent|wparam, 1 },
646     { WM_NCACTIVATE, sent|wparam, 1 },
647     { WM_ACTIVATE, sent|wparam, 1 },
648     { HCBT_SETFOCUS, hook },
649     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
650     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
651     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
652     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
653     { WM_GETTEXT, sent|optional },
654     { WM_SYNCPAINT, sent|wparam|optional, 4 },
655     { WM_NCPAINT, sent|wparam|optional, 1 },
656     { WM_ERASEBKGND, sent|optional },
657     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
658     { 0 }
659 };
660 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
661 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
662     { HCBT_CREATEWND, hook },
663     { WM_NCCREATE, sent },
664     { WM_NCCALCSIZE, sent|wparam, 0 },
665     { WM_CREATE, sent },
666     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
667     { WM_SIZE, sent|wparam, SIZE_RESTORED },
668     { WM_MOVE, sent },
669     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
670     { WM_GETMINMAXINFO, sent },
671     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
672     { WM_NCCALCSIZE, sent|wparam, TRUE },
673     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
674     { WM_MOVE, sent|defwinproc },
675     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
676     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
677     { 0 }
678 };
679 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
680 static const struct message WmShowMaxPopupResizedSeq[] = {
681     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
682     { WM_GETMINMAXINFO, sent },
683     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
684     { WM_NCCALCSIZE, sent|wparam, TRUE },
685     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
686     { HCBT_ACTIVATE, hook },
687     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
688     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
689     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
690     { WM_ACTIVATEAPP, sent|wparam, 1 },
691     { WM_NCACTIVATE, sent|wparam, 1 },
692     { WM_ACTIVATE, sent|wparam, 1 },
693     { HCBT_SETFOCUS, hook },
694     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
695     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
696     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
697     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
698     { WM_GETTEXT, sent|optional },
699     { WM_NCPAINT, sent|wparam|optional, 1 },
700     { WM_ERASEBKGND, sent|optional },
701     { WM_WINDOWPOSCHANGED, sent },
702     /* WinNT4.0 sends WM_MOVE */
703     { WM_MOVE, sent|defwinproc|optional },
704     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
705     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
706     { 0 }
707 };
708 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
709 static const struct message WmShowMaxPopupSeq[] = {
710     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
711     { WM_GETMINMAXINFO, sent },
712     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
713     { WM_NCCALCSIZE, sent|wparam, TRUE },
714     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
715     { HCBT_ACTIVATE, hook },
716     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
717     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
718     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
719     { WM_ACTIVATEAPP, sent|wparam, 1 },
720     { WM_NCACTIVATE, sent|wparam, 1 },
721     { WM_ACTIVATE, sent|wparam, 1 },
722     { HCBT_SETFOCUS, hook },
723     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
724     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
725     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
726     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
727     { WM_GETTEXT, sent|optional },
728     { WM_SYNCPAINT, sent|wparam|optional, 4 },
729     { WM_NCPAINT, sent|wparam|optional, 1 },
730     { WM_ERASEBKGND, sent|optional },
731     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
732     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
733     { 0 }
734 };
735 /* CreateWindow(WS_VISIBLE) for popup window */
736 static const struct message WmCreatePopupSeq[] = {
737     { HCBT_CREATEWND, hook },
738     { WM_NCCREATE, sent },
739     { WM_NCCALCSIZE, sent|wparam, 0 },
740     { WM_CREATE, sent },
741     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
742     { WM_SIZE, sent|wparam, SIZE_RESTORED },
743     { WM_MOVE, sent },
744     { WM_SHOWWINDOW, sent|wparam, 1 },
745     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
746     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
747     { HCBT_ACTIVATE, hook },
748     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
749     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
750     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
751     { WM_NCPAINT, sent|wparam|optional, 1 },
752     { WM_ERASEBKGND, sent|optional },
753     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
754     { WM_ACTIVATEAPP, sent|wparam, 1 },
755     { WM_NCACTIVATE, sent|wparam, 1 },
756     { WM_ACTIVATE, sent|wparam, 1 },
757     { HCBT_SETFOCUS, hook },
758     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
759     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
760     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
761     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
762     { WM_GETTEXT, sent|optional },
763     { WM_SYNCPAINT, sent|wparam|optional, 4 },
764     { WM_NCPAINT, sent|wparam|optional, 1 },
765     { WM_ERASEBKGND, sent|optional },
766     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
767     { 0 }
768 };
769 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
770 static const struct message WmShowVisMaxPopupSeq[] = {
771     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
772     { WM_GETMINMAXINFO, sent },
773     { WM_GETTEXT, sent|optional },
774     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
775     { WM_GETTEXT, sent|optional },
776     { WM_NCCALCSIZE, sent|wparam, TRUE },
777     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
778     { WM_NCPAINT, sent|wparam|optional, 1 },
779     { WM_ERASEBKGND, sent|optional },
780     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
781     { WM_MOVE, sent|defwinproc },
782     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
783     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
784     { 0 }
785 };
786 /* CreateWindow (for a child popup window, not initially visible) */
787 static const struct message WmCreateChildPopupSeq[] = {
788     { HCBT_CREATEWND, hook },
789     { WM_NCCREATE, sent }, 
790     { WM_NCCALCSIZE, sent|wparam, 0 },
791     { WM_CREATE, sent },
792     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
793     { WM_SIZE, sent|wparam, SIZE_RESTORED },
794     { WM_MOVE, sent },
795     { 0 }
796 };
797 /* CreateWindow (for a popup window, not initially visible,
798  * which sets WS_VISIBLE in WM_CREATE handler)
799  */
800 static const struct message WmCreateInvisiblePopupSeq[] = {
801     { HCBT_CREATEWND, hook },
802     { WM_NCCREATE, sent }, 
803     { WM_NCCALCSIZE, sent|wparam, 0 },
804     { WM_CREATE, sent },
805     { WM_STYLECHANGING, sent },
806     { WM_STYLECHANGED, sent },
807     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
808     { WM_SIZE, sent|wparam, SIZE_RESTORED },
809     { WM_MOVE, sent },
810     { 0 }
811 };
812 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
813  * for a popup window with WS_VISIBLE style set
814  */
815 static const struct message WmShowVisiblePopupSeq_2[] = {
816     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
817     { 0 }
818 };
819 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
820  * for a popup window with WS_VISIBLE style set
821  */
822 static const struct message WmShowVisiblePopupSeq_3[] = {
823     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
824     { HCBT_ACTIVATE, hook },
825     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
826     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
827     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
828     { WM_NCACTIVATE, sent|wparam, 1 },
829     { WM_ACTIVATE, sent|wparam, 1 },
830     { HCBT_SETFOCUS, hook },
831     { WM_KILLFOCUS, sent|parent },
832     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
833     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
834     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
835     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
836     { WM_SETFOCUS, sent|defwinproc },
837     { WM_GETTEXT, sent|optional },
838     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
839     { 0 }
840 };
841 /* CreateWindow (for child window, not initially visible) */
842 static const struct message WmCreateChildSeq[] = {
843     { HCBT_CREATEWND, hook },
844     { WM_NCCREATE, sent }, 
845     /* child is inserted into parent's child list after WM_NCCREATE returns */
846     { WM_NCCALCSIZE, sent|wparam, 0 },
847     { WM_CREATE, sent },
848     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
849     { WM_SIZE, sent|wparam, SIZE_RESTORED },
850     { WM_MOVE, sent },
851     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
852     { 0 }
853 };
854 /* CreateWindow (for maximized child window, not initially visible) */
855 static const struct message WmCreateMaximizedChildSeq[] = {
856     { HCBT_CREATEWND, hook },
857     { WM_NCCREATE, sent }, 
858     { WM_NCCALCSIZE, sent|wparam, 0 },
859     { WM_CREATE, sent },
860     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
861     { WM_SIZE, sent|wparam, SIZE_RESTORED },
862     { WM_MOVE, sent },
863     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
864     { WM_GETMINMAXINFO, sent },
865     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
866     { WM_NCCALCSIZE, sent|wparam, 1 },
867     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
868     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
869     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
870     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
871     { 0 }
872 };
873 /* CreateWindow (for a child window, initially visible) */
874 static const struct message WmCreateVisibleChildSeq[] = {
875     { HCBT_CREATEWND, hook },
876     { WM_NCCREATE, sent }, 
877     /* child is inserted into parent's child list after WM_NCCREATE returns */
878     { WM_NCCALCSIZE, sent|wparam, 0 },
879     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
880     { WM_CREATE, sent },
881     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
882     { WM_SIZE, sent|wparam, SIZE_RESTORED },
883     { WM_MOVE, sent },
884     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
885     { WM_SHOWWINDOW, sent|wparam, 1 },
886     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
887     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
888     { WM_ERASEBKGND, sent|parent|optional },
889     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
890     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
891     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
892     { 0 }
893 };
894 /* ShowWindow(SW_SHOW) for a not visible child window */
895 static const struct message WmShowChildSeq[] = {
896     { WM_SHOWWINDOW, sent|wparam, 1 },
897     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
898     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
899     { WM_ERASEBKGND, sent|parent|optional },
900     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
901     { 0 }
902 };
903 /* ShowWindow(SW_HIDE) for a visible child window */
904 static const struct message WmHideChildSeq[] = {
905     { WM_SHOWWINDOW, sent|wparam, 0 },
906     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
907     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
908     { WM_ERASEBKGND, sent|parent|optional },
909     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
910     { 0 }
911 };
912 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
913 static const struct message WmHideChildSeq2[] = {
914     { WM_SHOWWINDOW, sent|wparam, 0 },
915     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
916     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
917     { WM_ERASEBKGND, sent|parent },
918     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
919     { 0 }
920 };
921 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
922  * for a not visible child window
923  */
924 static const struct message WmShowChildSeq_2[] = {
925     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
926     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
927     { WM_CHILDACTIVATE, sent },
928     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
929     { 0 }
930 };
931 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
932  * for a not visible child window
933  */
934 static const struct message WmShowChildSeq_3[] = {
935     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
936     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
937     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
938     { 0 }
939 };
940 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
941  * for a visible child window with a caption
942  */
943 static const struct message WmShowChildSeq_4[] = {
944     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
945     { WM_CHILDACTIVATE, sent },
946     { 0 }
947 };
948 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
949 static const struct message WmShowChildInvisibleParentSeq_1[] = {
950     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
952     { WM_NCCALCSIZE, sent|wparam, 1 },
953     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
954     { WM_CHILDACTIVATE, sent|optional },
955     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
956     { WM_MOVE, sent|defwinproc },
957     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
958     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
959     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
960     /* FIXME: Wine creates an icon/title window while Windows doesn't */
961     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
962     { WM_GETTEXT, sent|optional },
963     { 0 }
964 };
965 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
966 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
967     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
968     { 0 }
969 };
970 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
971 static const struct message WmShowChildInvisibleParentSeq_2[] = {
972     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
973     { WM_GETMINMAXINFO, sent },
974     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
975     { WM_NCCALCSIZE, sent|wparam, 1 },
976     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
977     { WM_CHILDACTIVATE, sent },
978     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
979     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
980     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
981     { 0 }
982 };
983 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
984 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
985     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
986     { 0 }
987 };
988 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
989 static const struct message WmShowChildInvisibleParentSeq_3[] = {
990     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
991     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
992     { WM_NCCALCSIZE, sent|wparam, 1 },
993     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
994     { WM_CHILDACTIVATE, sent },
995     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
996     { WM_MOVE, sent|defwinproc },
997     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
998     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
999     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1000     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1001     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1002     { WM_GETTEXT, sent|optional },
1003     { 0 }
1004 };
1005 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1006 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1007     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1008     { 0 }
1009 };
1010 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1011 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1012     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1013     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1014     { WM_NCCALCSIZE, sent|wparam, 1 },
1015     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1016     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1017     { WM_MOVE, sent|defwinproc },
1018     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1019     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1020     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1021     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1022     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1023     { WM_GETTEXT, sent|optional },
1024     { 0 }
1025 };
1026 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1027 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1028     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1029     { 0 }
1030 };
1031 /* ShowWindow(SW_SHOW) for child with invisible parent */
1032 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1033     { WM_SHOWWINDOW, sent|wparam, 1 },
1034     { 0 }
1035 };
1036 /* ShowWindow(SW_HIDE) for child with invisible parent */
1037 static const struct message WmHideChildInvisibleParentSeq[] = {
1038     { WM_SHOWWINDOW, sent|wparam, 0 },
1039     { 0 }
1040 };
1041 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1042 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1043     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1044     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1045     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1046     { 0 }
1047 };
1048 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1049 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1050     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1051     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1052     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1053     { 0 }
1054 };
1055 /* DestroyWindow for a visible child window */
1056 static const struct message WmDestroyChildSeq[] = {
1057     { HCBT_DESTROYWND, hook },
1058     { 0x0090, sent|optional },
1059     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1060     { WM_SHOWWINDOW, sent|wparam, 0 },
1061     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1062     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1063     { WM_ERASEBKGND, sent|parent|optional },
1064     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1065     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1066     { WM_KILLFOCUS, sent },
1067     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1068     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1069     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1070     { WM_SETFOCUS, sent|parent },
1071     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1072     { WM_DESTROY, sent },
1073     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1074     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1075     { WM_NCDESTROY, sent },
1076     { 0 }
1077 };
1078 /* DestroyWindow for a visible child window with invisible parent */
1079 static const struct message WmDestroyInvisibleChildSeq[] = {
1080     { HCBT_DESTROYWND, hook },
1081     { 0x0090, sent|optional },
1082     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1083     { WM_SHOWWINDOW, sent|wparam, 0 },
1084     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1085     { WM_DESTROY, sent },
1086     { WM_NCDESTROY, sent },
1087     { 0 }
1088 };
1089 /* Moving the mouse in nonclient area */
1090 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1091     { WM_NCHITTEST, sent },
1092     { WM_SETCURSOR, sent },
1093     { WM_NCMOUSEMOVE, posted },
1094     { 0 }
1095 };
1096 /* Moving the mouse in client area */
1097 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1098     { WM_NCHITTEST, sent },
1099     { WM_SETCURSOR, sent },
1100     { WM_MOUSEMOVE, posted },
1101     { 0 }
1102 };
1103 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1104 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1105     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1106     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1107     { WM_GETMINMAXINFO, sent|defwinproc },
1108     { WM_ENTERSIZEMOVE, sent|defwinproc },
1109     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1110     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1111     { WM_MOVE, sent|defwinproc },
1112     { WM_EXITSIZEMOVE, sent|defwinproc },
1113     { 0 }
1114 };
1115 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1116 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1117     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1118     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1119     { WM_GETMINMAXINFO, sent|defwinproc },
1120     { WM_ENTERSIZEMOVE, sent|defwinproc },
1121     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1122     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1123     { WM_GETMINMAXINFO, sent|defwinproc },
1124     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1125     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1126     { WM_GETTEXT, sent|defwinproc },
1127     { WM_ERASEBKGND, sent|defwinproc },
1128     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1129     { WM_MOVE, sent|defwinproc },
1130     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1131     { WM_EXITSIZEMOVE, sent|defwinproc },
1132     { 0 }
1133 };
1134 /* Resizing child window with MoveWindow (32) */
1135 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1136     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1137     { WM_NCCALCSIZE, sent|wparam, 1 },
1138     { WM_ERASEBKGND, sent|parent|optional },
1139     { WM_ERASEBKGND, sent|optional },
1140     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1141     { WM_MOVE, sent|defwinproc },
1142     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1143     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1144     { 0 }
1145 };
1146 /* Clicking on inactive button */
1147 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1148     { WM_NCHITTEST, sent },
1149     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1150     { WM_MOUSEACTIVATE, sent },
1151     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1152     { WM_SETCURSOR, sent },
1153     { WM_SETCURSOR, sent|parent|defwinproc },
1154     { WM_LBUTTONDOWN, posted },
1155     { WM_KILLFOCUS, posted|parent },
1156     { WM_SETFOCUS, posted },
1157     { WM_CTLCOLORBTN, posted|parent },
1158     { BM_SETSTATE, posted },
1159     { WM_CTLCOLORBTN, posted|parent },
1160     { WM_LBUTTONUP, posted },
1161     { BM_SETSTATE, posted },
1162     { WM_CTLCOLORBTN, posted|parent },
1163     { WM_COMMAND, posted|parent },
1164     { 0 }
1165 };
1166 /* Reparenting a button (16/32) */
1167 /* The last child (button) reparented gets topmost for its new parent. */
1168 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1169     { WM_SHOWWINDOW, sent|wparam, 0 },
1170     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1171     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1172     { WM_ERASEBKGND, sent|parent },
1173     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1174     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1175     { WM_CHILDACTIVATE, sent },
1176     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1177     { WM_MOVE, sent|defwinproc },
1178     { WM_SHOWWINDOW, sent|wparam, 1 },
1179     { 0 }
1180 };
1181 /* Creation of a custom dialog (32) */
1182 static const struct message WmCreateCustomDialogSeq[] = {
1183     { HCBT_CREATEWND, hook },
1184     { WM_GETMINMAXINFO, sent },
1185     { WM_NCCREATE, sent },
1186     { WM_NCCALCSIZE, sent|wparam, 0 },
1187     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1188     { WM_CREATE, sent },
1189     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1190     { WM_NOTIFYFORMAT, sent|optional },
1191     { WM_QUERYUISTATE, sent|optional },
1192     { WM_WINDOWPOSCHANGING, sent|optional },
1193     { WM_GETMINMAXINFO, sent|optional },
1194     { WM_NCCALCSIZE, sent|optional },
1195     { WM_WINDOWPOSCHANGED, sent|optional },
1196     { WM_SHOWWINDOW, sent|wparam, 1 },
1197     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1198     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1199     { HCBT_ACTIVATE, hook },
1200     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1201
1202
1203     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1204
1205     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1206
1207     { WM_NCACTIVATE, sent|wparam, 1 },
1208     { WM_GETTEXT, sent|optional|defwinproc },
1209     { WM_GETTEXT, sent|optional|defwinproc },
1210     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1211     { WM_ACTIVATE, sent|wparam, 1 },
1212     { WM_GETTEXT, sent|optional },
1213     { WM_KILLFOCUS, sent|parent },
1214     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1215     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1216     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1217     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1218     { WM_SETFOCUS, sent },
1219     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1220     { WM_NCPAINT, sent|wparam, 1 },
1221     { WM_GETTEXT, sent|optional|defwinproc },
1222     { WM_GETTEXT, sent|optional|defwinproc },
1223     { WM_ERASEBKGND, sent },
1224     { WM_CTLCOLORDLG, sent|defwinproc },
1225     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1226     { WM_GETTEXT, sent|optional },
1227     { WM_GETTEXT, sent|optional },
1228     { WM_NCCALCSIZE, sent|optional },
1229     { WM_NCPAINT, sent|optional },
1230     { WM_GETTEXT, sent|optional|defwinproc },
1231     { WM_GETTEXT, sent|optional|defwinproc },
1232     { WM_ERASEBKGND, sent|optional },
1233     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1234     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1235     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1236     { WM_MOVE, sent },
1237     { 0 }
1238 };
1239 /* Calling EndDialog for a custom dialog (32) */
1240 static const struct message WmEndCustomDialogSeq[] = {
1241     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1242     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1243     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1244     { WM_GETTEXT, sent|optional },
1245     { HCBT_ACTIVATE, hook },
1246     { WM_NCACTIVATE, sent|wparam, 0 },
1247     { WM_GETTEXT, sent|optional|defwinproc },
1248     { WM_GETTEXT, sent|optional|defwinproc },
1249     { WM_ACTIVATE, sent|wparam, 0 },
1250     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1251     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1252     { HCBT_SETFOCUS, hook },
1253     { WM_KILLFOCUS, sent },
1254     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1255     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1256     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1257     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1258     { WM_SETFOCUS, sent|parent|defwinproc },
1259     { 0 }
1260 };
1261 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1262 static const struct message WmShowCustomDialogSeq[] = {
1263     { WM_SHOWWINDOW, sent|wparam, 1 },
1264     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1265     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1266     { HCBT_ACTIVATE, hook },
1267     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1268
1269     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1270
1271     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1272     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1273     { WM_NCACTIVATE, sent|wparam, 1 },
1274     { WM_ACTIVATE, sent|wparam, 1 },
1275     { WM_GETTEXT, sent|optional },
1276
1277     { WM_KILLFOCUS, sent|parent },
1278     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1279     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1280     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1281     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1282     { WM_SETFOCUS, sent },
1283     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1284     { WM_NCPAINT, sent|wparam, 1 },
1285     { WM_ERASEBKGND, sent },
1286     { WM_CTLCOLORDLG, sent|defwinproc },
1287     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1288     { 0 }
1289 };
1290 /* Creation and destruction of a modal dialog (32) */
1291 static const struct message WmModalDialogSeq[] = {
1292     { WM_CANCELMODE, sent|parent },
1293     { HCBT_SETFOCUS, hook },
1294     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1295     { WM_KILLFOCUS, sent|parent },
1296     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1297     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1298     { WM_ENABLE, sent|parent|wparam, 0 },
1299     { HCBT_CREATEWND, hook },
1300     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1301     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1302     { WM_SETFONT, sent },
1303     { WM_INITDIALOG, sent },
1304     { WM_CHANGEUISTATE, sent|optional },
1305     { WM_UPDATEUISTATE, sent|optional },
1306     { WM_SHOWWINDOW, sent },
1307     { HCBT_ACTIVATE, hook },
1308     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1309     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1310     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1311     { WM_NCACTIVATE, sent|wparam, 1 },
1312     { WM_GETTEXT, sent|optional },
1313     { WM_ACTIVATE, sent|wparam, 1 },
1314     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1315     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1316     { WM_NCPAINT, sent },
1317     { WM_GETTEXT, sent|optional },
1318     { WM_ERASEBKGND, sent },
1319     { WM_CTLCOLORDLG, sent },
1320     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1321     { WM_GETTEXT, sent|optional },
1322     { WM_NCCALCSIZE, sent|optional },
1323     { WM_NCPAINT, sent|optional },
1324     { WM_GETTEXT, sent|optional },
1325     { WM_ERASEBKGND, sent|optional },
1326     { WM_CTLCOLORDLG, sent|optional },
1327     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1328     { WM_PAINT, sent|optional },
1329     { WM_CTLCOLORBTN, sent },
1330     { WM_ENTERIDLE, sent|parent|optional },
1331     { WM_ENTERIDLE, sent|parent|optional },
1332     { WM_ENTERIDLE, sent|parent|optional },
1333     { WM_ENTERIDLE, sent|parent|optional },
1334     { WM_ENTERIDLE, sent|parent|optional },
1335     { WM_ENTERIDLE, sent|parent|optional },
1336     { WM_ENTERIDLE, sent|parent|optional },
1337     { WM_ENTERIDLE, sent|parent|optional },
1338     { WM_ENTERIDLE, sent|parent|optional },
1339     { WM_ENTERIDLE, sent|parent|optional },
1340     { WM_ENTERIDLE, sent|parent|optional },
1341     { WM_ENTERIDLE, sent|parent|optional },
1342     { WM_ENTERIDLE, sent|parent|optional },
1343     { WM_ENTERIDLE, sent|parent|optional },
1344     { WM_ENTERIDLE, sent|parent|optional },
1345     { WM_ENTERIDLE, sent|parent|optional },
1346     { WM_ENTERIDLE, sent|parent|optional },
1347     { WM_ENTERIDLE, sent|parent|optional },
1348     { WM_ENTERIDLE, sent|parent|optional },
1349     { WM_ENTERIDLE, sent|parent|optional },
1350     { WM_TIMER, sent },
1351     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1352     { WM_ENABLE, sent|parent|wparam, 1 },
1353     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1354     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1355     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1356     { WM_GETTEXT, sent|optional },
1357     { HCBT_ACTIVATE, hook },
1358     { WM_NCACTIVATE, sent|wparam, 0 },
1359     { WM_GETTEXT, sent|optional },
1360     { WM_ACTIVATE, sent|wparam, 0 },
1361     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1362     { WM_WINDOWPOSCHANGING, sent|optional },
1363     { WM_WINDOWPOSCHANGED, sent|optional },
1364     { HCBT_SETFOCUS, hook },
1365     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1366     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1367     { WM_SETFOCUS, sent|parent|defwinproc },
1368     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1369     { HCBT_DESTROYWND, hook },
1370     { 0x0090, sent|optional },
1371     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1372     { WM_DESTROY, sent },
1373     { WM_NCDESTROY, sent },
1374     { 0 }
1375 };
1376 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1377 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1378     /* (inside dialog proc, handling WM_INITDIALOG) */
1379     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1380     { WM_NCCALCSIZE, sent },
1381     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1382     { WM_GETTEXT, sent|defwinproc },
1383     { WM_ACTIVATE, sent|parent|wparam, 0 },
1384     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1385     { WM_WINDOWPOSCHANGING, sent|parent },
1386     { WM_NCACTIVATE, sent|wparam, 1 },
1387     { WM_ACTIVATE, sent|wparam, 1 },
1388     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1389     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1390     /* (setting focus) */
1391     { WM_SHOWWINDOW, sent|wparam, 1 },
1392     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1393     { WM_NCPAINT, sent },
1394     { WM_GETTEXT, sent|defwinproc },
1395     { WM_ERASEBKGND, sent },
1396     { WM_CTLCOLORDLG, sent|defwinproc },
1397     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1398     { WM_PAINT, sent },
1399     /* (bunch of WM_CTLCOLOR* for each control) */
1400     { WM_PAINT, sent|parent },
1401     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1402     { WM_SETCURSOR, sent|parent },
1403     { 0 }
1404 };
1405 /* SetMenu for NonVisible windows with size change*/
1406 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1407     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1408     { WM_NCCALCSIZE, sent|wparam, 1 },
1409     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1410     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1411     { WM_MOVE, sent|defwinproc },
1412     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1413     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1414     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1415     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1416     { WM_GETTEXT, sent|optional },
1417     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1418     { 0 }
1419 };
1420 /* SetMenu for NonVisible windows with no size change */
1421 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1422     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1423     { WM_NCCALCSIZE, sent|wparam, 1 },
1424     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1425     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1426     { 0 }
1427 };
1428 /* SetMenu for Visible windows with size change */
1429 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1430     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1431     { WM_NCCALCSIZE, sent|wparam, 1 },
1432     { 0x0093, sent|defwinproc|optional },
1433     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1434     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1435     { 0x0093, sent|defwinproc|optional },
1436     { 0x0093, sent|defwinproc|optional },
1437     { 0x0091, sent|defwinproc|optional },
1438     { 0x0092, sent|defwinproc|optional },
1439     { WM_GETTEXT, sent|defwinproc|optional },
1440     { WM_ERASEBKGND, sent|optional },
1441     { WM_ACTIVATE, sent|optional },
1442     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1443     { WM_MOVE, sent|defwinproc },
1444     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1445     { 0x0093, sent|optional },
1446     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1447     { 0x0093, sent|defwinproc|optional },
1448     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1449     { 0x0093, sent|defwinproc|optional },
1450     { 0x0093, sent|defwinproc|optional },
1451     { 0x0091, sent|defwinproc|optional },
1452     { 0x0092, sent|defwinproc|optional },
1453     { WM_ERASEBKGND, sent|optional },
1454     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1455     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1456     { 0 }
1457 };
1458 /* SetMenu for Visible windows with no size change */
1459 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1460     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1461     { WM_NCCALCSIZE, sent|wparam, 1 },
1462     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1463     { WM_GETTEXT, sent|defwinproc|optional },
1464     { WM_ERASEBKGND, sent|optional },
1465     { WM_ACTIVATE, sent|optional },
1466     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1467     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1468     { 0 }
1469 };
1470 /* DrawMenuBar for a visible window */
1471 static const struct message WmDrawMenuBarSeq[] =
1472 {
1473     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474     { WM_NCCALCSIZE, sent|wparam, 1 },
1475     { 0x0093, sent|defwinproc|optional },
1476     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1477     { 0x0093, sent|defwinproc|optional },
1478     { 0x0093, sent|defwinproc|optional },
1479     { 0x0091, sent|defwinproc|optional },
1480     { 0x0092, sent|defwinproc|optional },
1481     { WM_GETTEXT, sent|defwinproc|optional },
1482     { WM_ERASEBKGND, sent|optional },
1483     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1484     { 0x0093, sent|optional },
1485     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1486     { 0 }
1487 };
1488
1489 static const struct message WmSetRedrawFalseSeq[] =
1490 {
1491     { WM_SETREDRAW, sent|wparam, 0 },
1492     { 0 }
1493 };
1494
1495 static const struct message WmSetRedrawTrueSeq[] =
1496 {
1497     { WM_SETREDRAW, sent|wparam, 1 },
1498     { 0 }
1499 };
1500
1501 static const struct message WmEnableWindowSeq_1[] =
1502 {
1503     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1504     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1505     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1506     { 0 }
1507 };
1508
1509 static const struct message WmEnableWindowSeq_2[] =
1510 {
1511     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1512     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1513     { 0 }
1514 };
1515
1516 static const struct message WmGetScrollRangeSeq[] =
1517 {
1518     { SBM_GETRANGE, sent },
1519     { 0 }
1520 };
1521 static const struct message WmGetScrollInfoSeq[] =
1522 {
1523     { SBM_GETSCROLLINFO, sent },
1524     { 0 }
1525 };
1526 static const struct message WmSetScrollRangeSeq[] =
1527 {
1528     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1529        sends SBM_SETSCROLLINFO.
1530      */
1531     { SBM_SETSCROLLINFO, sent },
1532     { 0 }
1533 };
1534 /* SetScrollRange for a window without a non-client area */
1535 static const struct message WmSetScrollRangeHSeq_empty[] =
1536 {
1537     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1538     { 0 }
1539 };
1540 static const struct message WmSetScrollRangeVSeq_empty[] =
1541 {
1542     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1543     { 0 }
1544 };
1545 static const struct message WmSetScrollRangeHVSeq[] =
1546 {
1547     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1548     { WM_NCCALCSIZE, sent|wparam, 1 },
1549     { WM_GETTEXT, sent|defwinproc|optional },
1550     { WM_ERASEBKGND, sent|optional },
1551     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1552     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1553     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1554     { 0 }
1555 };
1556 /* SetScrollRange for a window with a non-client area */
1557 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1558 {
1559     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1560     { WM_NCCALCSIZE, sent|wparam, 1 },
1561     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1562     { WM_NCPAINT, sent|optional },
1563     { WM_STYLECHANGING, sent|defwinproc|optional },
1564     { WM_STYLECHANGED, sent|defwinproc|optional },
1565     { WM_STYLECHANGING, sent|defwinproc|optional },
1566     { WM_STYLECHANGED, sent|defwinproc|optional },
1567     { WM_STYLECHANGING, sent|defwinproc|optional },
1568     { WM_STYLECHANGED, sent|defwinproc|optional },
1569     { WM_STYLECHANGING, sent|defwinproc|optional },
1570     { WM_STYLECHANGED, sent|defwinproc|optional },
1571     { WM_GETTEXT, sent|defwinproc|optional },
1572     { WM_GETTEXT, sent|defwinproc|optional },
1573     { WM_ERASEBKGND, sent|optional },
1574     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1575     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1576     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1577     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1578     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1579     { WM_GETTEXT, sent|optional },
1580     { WM_GETTEXT, sent|optional },
1581     { WM_GETTEXT, sent|optional },
1582     { WM_GETTEXT, sent|optional },
1583     { 0 }
1584 };
1585 /* test if we receive the right sequence of messages */
1586 /* after calling ShowWindow( SW_SHOWNA) */
1587 static const struct message WmSHOWNAChildInvisParInvis[] = {
1588     { WM_SHOWWINDOW, sent|wparam, 1 },
1589     { 0 }
1590 };
1591 static const struct message WmSHOWNAChildVisParInvis[] = {
1592     { WM_SHOWWINDOW, sent|wparam, 1 },
1593     { 0 }
1594 };
1595 static const struct message WmSHOWNAChildVisParVis[] = {
1596     { WM_SHOWWINDOW, sent|wparam, 1 },
1597     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1598     { 0 }
1599 };
1600 static const struct message WmSHOWNAChildInvisParVis[] = {
1601     { WM_SHOWWINDOW, sent|wparam, 1 },
1602     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1603     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1604     { WM_ERASEBKGND, sent|optional },
1605     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1606     { 0 }
1607 };
1608 static const struct message WmSHOWNATopVisible[] = {
1609     { WM_SHOWWINDOW, sent|wparam, 1 },
1610     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1611     { WM_NCPAINT, sent|wparam|optional, 1 },
1612     { WM_GETTEXT, sent|defwinproc|optional },
1613     { WM_ERASEBKGND, sent|optional },
1614     { WM_WINDOWPOSCHANGED, sent|optional },
1615     { 0 }
1616 };
1617 static const struct message WmSHOWNATopInvisible[] = {
1618     { WM_NOTIFYFORMAT, sent|optional },
1619     { WM_QUERYUISTATE, sent|optional },
1620     { WM_WINDOWPOSCHANGING, sent|optional },
1621     { WM_GETMINMAXINFO, sent|optional },
1622     { WM_NCCALCSIZE, sent|optional },
1623     { WM_WINDOWPOSCHANGED, sent|optional },
1624     { WM_SHOWWINDOW, sent|wparam, 1 },
1625     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1626     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1627     { WM_NCPAINT, sent|wparam, 1 },
1628     { WM_GETTEXT, sent|defwinproc|optional },
1629     { WM_ERASEBKGND, sent|optional },
1630     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1631     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1632     { WM_NCPAINT, sent|wparam|optional, 1 },
1633     { WM_ERASEBKGND, sent|optional },
1634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1635     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1636     { WM_MOVE, sent },
1637     { 0 }
1638 };
1639
1640 static int after_end_dialog, test_def_id;
1641 static int sequence_cnt, sequence_size;
1642 static struct recvd_message* sequence;
1643 static int log_all_parent_messages;
1644 static int paint_loop_done;
1645
1646 /* user32 functions */
1647 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1648 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1649 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1650 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1651 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1652 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1653 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1654 /* kernel32 functions */
1655 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1656
1657 static void init_procs(void)
1658 {
1659     HMODULE user32 = GetModuleHandleA("user32.dll");
1660     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1661
1662 #define GET_PROC(dll, func) \
1663     p ## func = (void*)GetProcAddress(dll, #func); \
1664     if(!p ## func) { \
1665       trace("GetProcAddress(%s) failed\n", #func); \
1666     }
1667
1668     GET_PROC(user32, GetAncestor)
1669     GET_PROC(user32, GetMenuInfo)
1670     GET_PROC(user32, NotifyWinEvent)
1671     GET_PROC(user32, SetMenuInfo)
1672     GET_PROC(user32, SetWinEventHook)
1673     GET_PROC(user32, TrackMouseEvent)
1674     GET_PROC(user32, UnhookWinEvent)
1675
1676     GET_PROC(kernel32, GetCPInfoExA)
1677
1678 #undef GET_PROC
1679 }
1680
1681 static const char *get_winpos_flags(UINT flags)
1682 {
1683     static char buffer[300];
1684
1685     buffer[0] = 0;
1686 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1687     DUMP( SWP_SHOWWINDOW );
1688     DUMP( SWP_HIDEWINDOW );
1689     DUMP( SWP_NOACTIVATE );
1690     DUMP( SWP_FRAMECHANGED );
1691     DUMP( SWP_NOCOPYBITS );
1692     DUMP( SWP_NOOWNERZORDER );
1693     DUMP( SWP_NOSENDCHANGING );
1694     DUMP( SWP_DEFERERASE );
1695     DUMP( SWP_ASYNCWINDOWPOS );
1696     DUMP( SWP_NOZORDER );
1697     DUMP( SWP_NOREDRAW );
1698     DUMP( SWP_NOSIZE );
1699     DUMP( SWP_NOMOVE );
1700     DUMP( SWP_NOCLIENTSIZE );
1701     DUMP( SWP_NOCLIENTMOVE );
1702     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1703     return buffer + 1;
1704 #undef DUMP
1705 }
1706
1707
1708 #define add_message(msg) add_message_(__LINE__,msg);
1709 static void add_message_(int line, const struct recvd_message *msg)
1710 {
1711     struct recvd_message *seq;
1712
1713     if (!sequence) 
1714     {
1715         sequence_size = 10;
1716         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1717     }
1718     if (sequence_cnt == sequence_size) 
1719     {
1720         sequence_size *= 2;
1721         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1722     }
1723     assert(sequence);
1724
1725     seq = &sequence[sequence_cnt];
1726     seq->hwnd = msg->hwnd;
1727     seq->message = msg->message;
1728     seq->flags = msg->flags;
1729     seq->wParam = msg->wParam;
1730     seq->lParam = msg->lParam;
1731     seq->line   = line;
1732     seq->descr  = msg->descr;
1733     seq->output[0] = 0;
1734
1735     if (msg->descr)
1736     {
1737         if (msg->flags & hook)
1738         {
1739             static const char * const CBT_code_name[10] =
1740             {
1741                 "HCBT_MOVESIZE",
1742                 "HCBT_MINMAX",
1743                 "HCBT_QS",
1744                 "HCBT_CREATEWND",
1745                 "HCBT_DESTROYWND",
1746                 "HCBT_ACTIVATE",
1747                 "HCBT_CLICKSKIPPED",
1748                 "HCBT_KEYSKIPPED",
1749                 "HCBT_SYSCOMMAND",
1750                 "HCBT_SETFOCUS"
1751             };
1752             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1753
1754             snprintf( seq->output, sizeof(seq->output), "%s: hook %d (%s) wp %08lx lp %08lx",
1755                       msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1756         }
1757         else if (msg->flags & winevent_hook)
1758         {
1759             snprintf( seq->output, sizeof(seq->output), "%s: winevent %p %08x %08lx %08lx",
1760                       msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1761         }
1762         else
1763         {
1764             switch (msg->message)
1765             {
1766             case WM_WINDOWPOSCHANGING:
1767             case WM_WINDOWPOSCHANGED:
1768             {
1769                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1770
1771                 snprintf( seq->output, sizeof(seq->output),
1772                           "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1773                           msg->descr, msg->hwnd,
1774                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1775                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1776                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1777                           get_winpos_flags(winpos->flags) );
1778
1779                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1780                  * in the high word for internal purposes
1781                  */
1782                 seq->wParam = winpos->flags & 0xffff;
1783                 /* We are not interested in the flags that don't match under XP and Win9x */
1784                 seq->wParam &= ~SWP_NOZORDER;
1785                 break;
1786             }
1787
1788             case WM_DRAWITEM:
1789             {
1790                 DRAW_ITEM_STRUCT di;
1791                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1792
1793                 snprintf( seq->output, sizeof(seq->output),
1794                           "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1795                           msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1796                           dis->itemID, dis->itemAction, dis->itemState);
1797
1798                 di.u.item.type = dis->CtlType;
1799                 di.u.item.ctl_id = dis->CtlID;
1800                 di.u.item.item_id = dis->itemID;
1801                 di.u.item.action = dis->itemAction;
1802                 di.u.item.state = dis->itemState;
1803
1804                 seq->lParam = di.u.lp;
1805                 break;
1806             }
1807             default:
1808                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1809                 snprintf( seq->output, sizeof(seq->output), "%s: %p %04x wp %08lx lp %08lx",
1810                           msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1811             }
1812         }
1813     }
1814
1815     sequence_cnt++;
1816 }
1817
1818 /* try to make sure pending X events have been processed before continuing */
1819 static void flush_events(void)
1820 {
1821     MSG msg;
1822     int diff = 200;
1823     int min_timeout = 100;
1824     DWORD time = GetTickCount() + diff;
1825
1826     while (diff > 0)
1827     {
1828         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1829         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1830         diff = time - GetTickCount();
1831         min_timeout = 50;
1832     }
1833 }
1834
1835 static void flush_sequence(void)
1836 {
1837     HeapFree(GetProcessHeap(), 0, sequence);
1838     sequence = 0;
1839     sequence_cnt = sequence_size = 0;
1840 }
1841
1842 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1843 {
1844     const struct recvd_message *actual = sequence;
1845     unsigned int count = 0;
1846
1847     trace_(file, line)("Failed sequence %s:\n", context );
1848     while (expected->message && actual->message)
1849     {
1850         if (actual->output[0])
1851         {
1852             if (expected->flags & hook)
1853             {
1854                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1855                                     count, expected->message, actual->output );
1856             }
1857             else if (expected->flags & winevent_hook)
1858             {
1859                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1860                                     count, expected->message, actual->output );
1861             }
1862             else
1863             {
1864                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1865                                     count, expected->message, actual->output );
1866             }
1867         }
1868
1869         if (expected->message == actual->message)
1870         {
1871             expected++;
1872             actual++;
1873         }
1874         /* silently drop winevent messages if there is no support for them */
1875         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1876             expected++;
1877         else
1878         {
1879             expected++;
1880             actual++;
1881         }
1882         count++;
1883     }
1884
1885     /* optional trailing messages */
1886     while (expected->message && ((expected->flags & optional) ||
1887             ((expected->flags & winevent_hook) && !hEvent_hook)))
1888     {
1889         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1890         expected++;
1891         count++;
1892     }
1893
1894     if (expected->message)
1895         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1896     else if (actual->message && actual->output[0])
1897         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1898 }
1899
1900 #define ok_sequence( exp, contx, todo) \
1901         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1902
1903
1904 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1905                          const char *file, int line)
1906 {
1907     static const struct recvd_message end_of_sequence;
1908     const struct message *expected = expected_list;
1909     const struct recvd_message *actual;
1910     int failcount = 0, dump = 0;
1911     unsigned int count = 0;
1912
1913     add_message(&end_of_sequence);
1914
1915     actual = sequence;
1916
1917     while (expected->message && actual->message)
1918     {
1919         if (expected->message == actual->message)
1920         {
1921             if (expected->flags & wparam)
1922             {
1923                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1924                 {
1925                     todo_wine {
1926                         failcount ++;
1927                         if (strcmp(winetest_platform, "wine")) dump++;
1928                         ok_( file, line) (FALSE,
1929                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1930                             context, count, expected->message, expected->wParam, actual->wParam);
1931                     }
1932                 }
1933                 else
1934                 {
1935                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
1936                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1937                                      context, count, expected->message, expected->wParam, actual->wParam);
1938                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
1939                 }
1940
1941             }
1942             if (expected->flags & lparam)
1943             {
1944                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
1945                 {
1946                     todo_wine {
1947                         failcount ++;
1948                         if (strcmp(winetest_platform, "wine")) dump++;
1949                         ok_( file, line) (FALSE,
1950                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1951                             context, count, expected->message, expected->lParam, actual->lParam);
1952                     }
1953                 }
1954                 else
1955                 {
1956                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
1957                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1958                                      context, count, expected->message, expected->lParam, actual->lParam);
1959                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
1960                 }
1961             }
1962             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1963                 (expected->flags & optional))
1964             {
1965                 /* don't match messages if their defwinproc status differs */
1966                 expected++;
1967                 count++;
1968                 continue;
1969             }
1970             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1971             {
1972                     todo_wine {
1973                         failcount ++;
1974                         if (strcmp(winetest_platform, "wine")) dump++;
1975                         ok_( file, line) (FALSE,
1976                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1977                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1978                     }
1979             }
1980             else
1981             {
1982                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1983                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1984                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1985                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
1986             }
1987
1988             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1989                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
1990                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1991             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
1992
1993             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1994                 "%s: %u: the msg 0x%04x should have been %s\n",
1995                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
1996             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
1997
1998             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1999                 "%s: %u: the msg 0x%04x was expected in %s\n",
2000                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2001             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2002
2003             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2004                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2005                 context, count, expected->message);
2006             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2007
2008             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2009                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2010                 context, count, expected->message);
2011             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2012
2013             expected++;
2014             actual++;
2015         }
2016         /* silently drop hook messages if there is no support for them */
2017         else if ((expected->flags & optional) ||
2018                  ((expected->flags & hook) && !hCBT_hook) ||
2019                  ((expected->flags & winevent_hook) && !hEvent_hook))
2020             expected++;
2021         else if (todo)
2022         {
2023             failcount++;
2024             todo_wine {
2025                 if (strcmp(winetest_platform, "wine")) dump++;
2026                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2027                                   context, count, expected->message, actual->message);
2028             }
2029             goto done;
2030         }
2031         else
2032         {
2033             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2034                               context, count, expected->message, actual->message);
2035             dump++;
2036             expected++;
2037             actual++;
2038         }
2039         count++;
2040     }
2041
2042     /* skip all optional trailing messages */
2043     while (expected->message && ((expected->flags & optional) ||
2044                                  ((expected->flags & hook) && !hCBT_hook) ||
2045                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2046         expected++;
2047
2048     if (todo)
2049     {
2050         todo_wine {
2051             if (expected->message || actual->message) {
2052                 failcount++;
2053                 if (strcmp(winetest_platform, "wine")) dump++;
2054                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2055                                   context, count, expected->message, actual->message);
2056             }
2057         }
2058     }
2059     else
2060     {
2061         if (expected->message || actual->message)
2062         {
2063             dump++;
2064             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2065                               context, count, expected->message, actual->message);
2066         }
2067     }
2068     if( todo && !failcount) /* succeeded yet marked todo */
2069         todo_wine {
2070             if (!strcmp(winetest_platform, "wine")) dump++;
2071             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2072         }
2073
2074 done:
2075     if (dump) dump_sequence(expected_list, context, file, line);
2076     flush_sequence();
2077 }
2078
2079 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2080
2081 /******************************** MDI test **********************************/
2082
2083 /* CreateWindow for MDI frame window, initially visible */
2084 static const struct message WmCreateMDIframeSeq[] = {
2085     { HCBT_CREATEWND, hook },
2086     { WM_GETMINMAXINFO, sent },
2087     { WM_NCCREATE, sent },
2088     { WM_NCCALCSIZE, sent|wparam, 0 },
2089     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2090     { WM_CREATE, sent },
2091     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2092     { WM_NOTIFYFORMAT, sent|optional },
2093     { WM_QUERYUISTATE, sent|optional },
2094     { WM_WINDOWPOSCHANGING, sent|optional },
2095     { WM_GETMINMAXINFO, sent|optional },
2096     { WM_NCCALCSIZE, sent|optional },
2097     { WM_WINDOWPOSCHANGED, sent|optional },
2098     { WM_SHOWWINDOW, sent|wparam, 1 },
2099     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2100     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2101     { HCBT_ACTIVATE, hook },
2102     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2103     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2104     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2105     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2106     { WM_NCACTIVATE, sent|wparam, 1 },
2107     { WM_GETTEXT, sent|defwinproc|optional },
2108     { WM_ACTIVATE, sent|wparam, 1 },
2109     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2110     { HCBT_SETFOCUS, hook },
2111     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2112     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2113     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2114     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2115     /* Win9x adds SWP_NOZORDER below */
2116     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2117     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2118     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2119     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2120     { WM_MOVE, sent },
2121     { 0 }
2122 };
2123 /* DestroyWindow for MDI frame window, initially visible */
2124 static const struct message WmDestroyMDIframeSeq[] = {
2125     { HCBT_DESTROYWND, hook },
2126     { 0x0090, sent|optional },
2127     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2128     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2129     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2130     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2131     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2132     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2133     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2134     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2135     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2136     { WM_DESTROY, sent },
2137     { WM_NCDESTROY, sent },
2138     { 0 }
2139 };
2140 /* CreateWindow for MDI client window, initially visible */
2141 static const struct message WmCreateMDIclientSeq[] = {
2142     { HCBT_CREATEWND, hook },
2143     { WM_NCCREATE, sent },
2144     { WM_NCCALCSIZE, sent|wparam, 0 },
2145     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2146     { WM_CREATE, sent },
2147     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2148     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2149     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2150     { WM_MOVE, sent },
2151     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2152     { WM_SHOWWINDOW, sent|wparam, 1 },
2153     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2154     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2155     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2156     { 0 }
2157 };
2158 /* ShowWindow(SW_SHOW) for MDI client window */
2159 static const struct message WmShowMDIclientSeq[] = {
2160     { WM_SHOWWINDOW, sent|wparam, 1 },
2161     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2162     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2163     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2164     { 0 }
2165 };
2166 /* ShowWindow(SW_HIDE) for MDI client window */
2167 static const struct message WmHideMDIclientSeq[] = {
2168     { WM_SHOWWINDOW, sent|wparam, 0 },
2169     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2170     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2171     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2172     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2173     { 0 }
2174 };
2175 /* DestroyWindow for MDI client window, initially visible */
2176 static const struct message WmDestroyMDIclientSeq[] = {
2177     { HCBT_DESTROYWND, hook },
2178     { 0x0090, sent|optional },
2179     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2180     { WM_SHOWWINDOW, sent|wparam, 0 },
2181     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2182     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2183     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2184     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2185     { WM_DESTROY, sent },
2186     { WM_NCDESTROY, sent },
2187     { 0 }
2188 };
2189 /* CreateWindow for MDI child window, initially visible */
2190 static const struct message WmCreateMDIchildVisibleSeq[] = {
2191     { HCBT_CREATEWND, hook },
2192     { WM_NCCREATE, sent }, 
2193     { WM_NCCALCSIZE, sent|wparam, 0 },
2194     { WM_CREATE, sent },
2195     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2196     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2197     { WM_MOVE, sent },
2198     /* Win2k sends wparam set to
2199      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2200      * while Win9x doesn't bother to set child window id according to
2201      * CLIENTCREATESTRUCT.idFirstChild
2202      */
2203     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2204     { WM_SHOWWINDOW, sent|wparam, 1 },
2205     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2206     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2207     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2208     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2209     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2210     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2211     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2212
2213     /* Win9x: message sequence terminates here. */
2214
2215     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2216     { HCBT_SETFOCUS, hook }, /* in MDI client */
2217     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2218     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2219     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2220     { WM_SETFOCUS, sent }, /* in MDI client */
2221     { HCBT_SETFOCUS, hook },
2222     { WM_KILLFOCUS, sent }, /* in MDI client */
2223     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2224     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2225     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2226     { WM_SETFOCUS, sent|defwinproc },
2227     { WM_MDIACTIVATE, sent|defwinproc },
2228     { 0 }
2229 };
2230 /* CreateWindow for MDI child window with invisible parent */
2231 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2232     { HCBT_CREATEWND, hook },
2233     { WM_GETMINMAXINFO, sent },
2234     { WM_NCCREATE, sent }, 
2235     { WM_NCCALCSIZE, sent|wparam, 0 },
2236     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2237     { WM_CREATE, sent },
2238     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2239     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2240     { WM_MOVE, sent },
2241     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2242     { WM_SHOWWINDOW, sent|wparam, 1 },
2243     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2244     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2245     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2246     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2247
2248     /* Win9x: message sequence terminates here. */
2249
2250     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2251     { HCBT_SETFOCUS, hook }, /* in MDI client */
2252     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2253     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2254     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2255     { WM_SETFOCUS, sent }, /* in MDI client */
2256     { HCBT_SETFOCUS, hook },
2257     { WM_KILLFOCUS, sent }, /* in MDI client */
2258     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2259     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2260     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2261     { WM_SETFOCUS, sent|defwinproc },
2262     { WM_MDIACTIVATE, sent|defwinproc },
2263     { 0 }
2264 };
2265 /* DestroyWindow for MDI child window, initially visible */
2266 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2267     { HCBT_DESTROYWND, hook },
2268     /* Win2k sends wparam set to
2269      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2270      * while Win9x doesn't bother to set child window id according to
2271      * CLIENTCREATESTRUCT.idFirstChild
2272      */
2273     { 0x0090, sent|optional },
2274     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2275     { WM_SHOWWINDOW, sent|wparam, 0 },
2276     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2277     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2278     { WM_ERASEBKGND, sent|parent|optional },
2279     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2280
2281     /* { WM_DESTROY, sent }
2282      * Win9x: message sequence terminates here.
2283      */
2284
2285     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2286     { WM_KILLFOCUS, sent },
2287     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2288     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2289     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2290     { WM_SETFOCUS, sent }, /* in MDI client */
2291
2292     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2293     { WM_KILLFOCUS, sent }, /* in MDI client */
2294     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2295     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2296     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2297     { WM_SETFOCUS, sent }, /* in MDI client */
2298
2299     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2300
2301     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2302     { WM_KILLFOCUS, sent },
2303     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2304     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2305     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2306     { WM_SETFOCUS, sent }, /* in MDI client */
2307
2308     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2309     { WM_KILLFOCUS, sent }, /* in MDI client */
2310     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2311     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2312     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2313     { WM_SETFOCUS, sent }, /* in MDI client */
2314
2315     { WM_DESTROY, sent },
2316
2317     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2318     { WM_KILLFOCUS, sent },
2319     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2320     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2321     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2322     { WM_SETFOCUS, sent }, /* in MDI client */
2323
2324     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2325     { WM_KILLFOCUS, sent }, /* in MDI client */
2326     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2327     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2328     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2329     { WM_SETFOCUS, sent }, /* in MDI client */
2330
2331     { WM_NCDESTROY, sent },
2332     { 0 }
2333 };
2334 /* CreateWindow for MDI child window, initially invisible */
2335 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2336     { HCBT_CREATEWND, hook },
2337     { WM_NCCREATE, sent }, 
2338     { WM_NCCALCSIZE, sent|wparam, 0 },
2339     { WM_CREATE, sent },
2340     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2341     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2342     { WM_MOVE, sent },
2343     /* Win2k sends wparam set to
2344      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2345      * while Win9x doesn't bother to set child window id according to
2346      * CLIENTCREATESTRUCT.idFirstChild
2347      */
2348     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2349     { 0 }
2350 };
2351 /* DestroyWindow for MDI child window, initially invisible */
2352 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2353     { HCBT_DESTROYWND, hook },
2354     /* Win2k sends wparam set to
2355      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2356      * while Win9x doesn't bother to set child window id according to
2357      * CLIENTCREATESTRUCT.idFirstChild
2358      */
2359     { 0x0090, sent|optional },
2360     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2361     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2362     { WM_DESTROY, sent },
2363     { WM_NCDESTROY, sent },
2364     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2365     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2366     { 0 }
2367 };
2368 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2369 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2370     { HCBT_CREATEWND, hook },
2371     { WM_NCCREATE, sent }, 
2372     { WM_NCCALCSIZE, sent|wparam, 0 },
2373     { WM_CREATE, sent },
2374     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2375     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2376     { WM_MOVE, sent },
2377     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2378     { WM_GETMINMAXINFO, sent },
2379     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2380     { WM_NCCALCSIZE, sent|wparam, 1 },
2381     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2382     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2383      /* in MDI frame */
2384     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2385     { WM_NCCALCSIZE, sent|wparam, 1 },
2386     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2387     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2388     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
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     { WM_SHOWWINDOW, sent|wparam, 1 },
2396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2397     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2398     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2399     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2400     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2401     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2402     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2403
2404     /* Win9x: message sequence terminates here. */
2405
2406     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2407     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2408     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2409     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2410     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2411     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2412     { HCBT_SETFOCUS, hook|optional },
2413     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2414     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2415     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2416     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2417     { WM_SETFOCUS, sent|defwinproc|optional },
2418     { WM_MDIACTIVATE, sent|defwinproc|optional },
2419      /* in MDI frame */
2420     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2421     { WM_NCCALCSIZE, sent|wparam, 1 },
2422     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2423     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2424     { 0 }
2425 };
2426 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2427 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2428     /* restore the 1st MDI child */
2429     { WM_SETREDRAW, sent|wparam, 0 },
2430     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2431     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2432     { WM_NCCALCSIZE, sent|wparam, 1 },
2433     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2434     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2435     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2436      /* in MDI frame */
2437     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2438     { WM_NCCALCSIZE, sent|wparam, 1 },
2439     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2440     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2441     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2442     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2443     /* create the 2nd MDI child */
2444     { HCBT_CREATEWND, hook },
2445     { WM_NCCREATE, sent }, 
2446     { WM_NCCALCSIZE, sent|wparam, 0 },
2447     { WM_CREATE, sent },
2448     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2449     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2450     { WM_MOVE, sent },
2451     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2452     { WM_GETMINMAXINFO, sent },
2453     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2454     { WM_NCCALCSIZE, sent|wparam, 1 },
2455     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2456     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2457     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2458      /* in MDI frame */
2459     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2460     { WM_NCCALCSIZE, sent|wparam, 1 },
2461     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2462     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2463     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2464     /* Win2k sends wparam set to
2465      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2466      * while Win9x doesn't bother to set child window id according to
2467      * CLIENTCREATESTRUCT.idFirstChild
2468      */
2469     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2470     { WM_SHOWWINDOW, sent|wparam, 1 },
2471     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2472     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2473     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2474     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2475     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2476     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2477
2478     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2479     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2480
2481     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2482
2483     /* Win9x: message sequence terminates here. */
2484
2485     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2486     { HCBT_SETFOCUS, hook },
2487     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2488     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2489     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2490     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2491     { WM_SETFOCUS, sent }, /* in MDI client */
2492     { HCBT_SETFOCUS, hook },
2493     { WM_KILLFOCUS, sent }, /* in MDI client */
2494     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2495     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2496     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2497     { WM_SETFOCUS, sent|defwinproc },
2498
2499     { WM_MDIACTIVATE, sent|defwinproc },
2500      /* in MDI frame */
2501     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2502     { WM_NCCALCSIZE, sent|wparam, 1 },
2503     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2504     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2505     { 0 }
2506 };
2507 /* WM_MDICREATE MDI child window, initially visible and maximized */
2508 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2509     { WM_MDICREATE, sent },
2510     { HCBT_CREATEWND, hook },
2511     { WM_NCCREATE, sent }, 
2512     { WM_NCCALCSIZE, sent|wparam, 0 },
2513     { WM_CREATE, sent },
2514     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2515     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2516     { WM_MOVE, sent },
2517     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2518     { WM_GETMINMAXINFO, sent },
2519     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2520     { WM_NCCALCSIZE, sent|wparam, 1 },
2521     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2522     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2523
2524      /* in MDI frame */
2525     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2526     { WM_NCCALCSIZE, sent|wparam, 1 },
2527     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2528     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2529     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2530
2531     /* Win2k sends wparam set to
2532      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2533      * while Win9x doesn't bother to set child window id according to
2534      * CLIENTCREATESTRUCT.idFirstChild
2535      */
2536     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2537     { WM_SHOWWINDOW, sent|wparam, 1 },
2538     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2539
2540     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2541
2542     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2543     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2544     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2545
2546     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2547     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2548
2549     /* Win9x: message sequence terminates here. */
2550
2551     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2552     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2553     { HCBT_SETFOCUS, hook }, /* in MDI client */
2554     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2555     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2556     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2557     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2558     { HCBT_SETFOCUS, hook|optional },
2559     { WM_KILLFOCUS, sent }, /* in MDI client */
2560     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2561     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2562     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2563     { WM_SETFOCUS, sent|defwinproc },
2564
2565     { WM_MDIACTIVATE, sent|defwinproc },
2566
2567      /* in MDI child */
2568     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2569     { WM_NCCALCSIZE, sent|wparam, 1 },
2570     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2571     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2572
2573      /* in MDI frame */
2574     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2575     { WM_NCCALCSIZE, sent|wparam, 1 },
2576     { 0x0093, sent|defwinproc|optional },
2577     { 0x0093, sent|defwinproc|optional },
2578     { 0x0093, sent|defwinproc|optional },
2579     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2580     { WM_MOVE, sent|defwinproc },
2581     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2582
2583      /* in MDI client */
2584     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2585     { WM_NCCALCSIZE, sent|wparam, 1 },
2586     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2587     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2588
2589      /* in MDI child */
2590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2591     { WM_NCCALCSIZE, sent|wparam, 1 },
2592     { 0x0093, sent|optional },
2593     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2594     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2595
2596     { 0x0093, sent|optional },
2597     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2598     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2599     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2600     { 0x0093, sent|defwinproc|optional },
2601     { 0x0093, sent|defwinproc|optional },
2602     { 0x0093, sent|defwinproc|optional },
2603     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2604     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2605
2606     { 0 }
2607 };
2608 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2609 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2610     { HCBT_CREATEWND, hook },
2611     { WM_GETMINMAXINFO, sent },
2612     { WM_NCCREATE, sent }, 
2613     { WM_NCCALCSIZE, sent|wparam, 0 },
2614     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2615     { WM_CREATE, sent },
2616     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2617     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2618     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2619     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2620     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2621     { WM_MOVE, sent },
2622     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2623     { WM_GETMINMAXINFO, sent },
2624     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2625     { WM_GETMINMAXINFO, sent|defwinproc },
2626     { WM_NCCALCSIZE, sent|wparam, 1 },
2627     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2628     { WM_MOVE, sent|defwinproc },
2629     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2630      /* in MDI frame */
2631     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2632     { WM_NCCALCSIZE, sent|wparam, 1 },
2633     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2635     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2636     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2637     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2638     /* Win2k sends wparam set to
2639      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2640      * while Win9x doesn't bother to set child window id according to
2641      * CLIENTCREATESTRUCT.idFirstChild
2642      */
2643     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2644     { 0 }
2645 };
2646 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2647 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2648     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2649     { HCBT_SYSCOMMAND, hook },
2650     { WM_CLOSE, sent|defwinproc },
2651     { WM_MDIDESTROY, sent }, /* in MDI client */
2652
2653     /* bring the 1st MDI child to top */
2654     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2655     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2656
2657     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2658
2659     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2660     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2661     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2662
2663     /* maximize the 1st MDI child */
2664     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2665     { WM_GETMINMAXINFO, sent|defwinproc },
2666     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2667     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2668     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2669     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2670     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2671
2672     /* restore the 2nd MDI child */
2673     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2674     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2675     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2676     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2677
2678     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2679
2680     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2681     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2682
2683     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2684
2685     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2686      /* in MDI frame */
2687     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2688     { WM_NCCALCSIZE, sent|wparam, 1 },
2689     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2690     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2691     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2692
2693     /* bring the 1st MDI child to top */
2694     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2695     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2696     { HCBT_SETFOCUS, hook },
2697     { WM_KILLFOCUS, sent|defwinproc },
2698     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2699     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2700     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2701     { WM_SETFOCUS, sent }, /* in MDI client */
2702     { HCBT_SETFOCUS, hook },
2703     { WM_KILLFOCUS, sent }, /* in MDI client */
2704     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2705     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2706     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2707     { WM_SETFOCUS, sent|defwinproc },
2708     { WM_MDIACTIVATE, sent|defwinproc },
2709     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2710
2711     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2712     { WM_SHOWWINDOW, sent|wparam, 1 },
2713     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2714     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2715     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2716     { WM_MDIREFRESHMENU, sent },
2717
2718     { HCBT_DESTROYWND, hook },
2719     /* Win2k sends wparam set to
2720      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2721      * while Win9x doesn't bother to set child window id according to
2722      * CLIENTCREATESTRUCT.idFirstChild
2723      */
2724     { 0x0090, sent|defwinproc|optional },
2725     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2726     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2727     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2728     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2729     { WM_ERASEBKGND, sent|parent|optional },
2730     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2731
2732     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2733     { WM_DESTROY, sent|defwinproc },
2734     { WM_NCDESTROY, sent|defwinproc },
2735     { 0 }
2736 };
2737 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2738 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2739     { WM_MDIDESTROY, sent }, /* in MDI client */
2740     { WM_SHOWWINDOW, sent|wparam, 0 },
2741     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2742     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2743     { WM_ERASEBKGND, sent|parent|optional },
2744     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2745
2746     { HCBT_SETFOCUS, hook },
2747     { WM_KILLFOCUS, sent },
2748     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2749     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2750     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2751     { WM_SETFOCUS, sent }, /* in MDI client */
2752     { HCBT_SETFOCUS, hook },
2753     { WM_KILLFOCUS, sent }, /* in MDI client */
2754     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2755     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2756     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2757     { WM_SETFOCUS, sent },
2758
2759      /* in MDI child */
2760     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2761     { WM_NCCALCSIZE, sent|wparam, 1 },
2762     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2763     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2764
2765      /* in MDI frame */
2766     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2767     { WM_NCCALCSIZE, sent|wparam, 1 },
2768     { 0x0093, sent|defwinproc|optional },
2769     { 0x0093, sent|defwinproc|optional },
2770     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2771     { WM_MOVE, sent|defwinproc },
2772     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2773
2774      /* in MDI client */
2775     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2776     { WM_NCCALCSIZE, sent|wparam, 1 },
2777     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2778     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2779
2780      /* in MDI child */
2781     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2782     { WM_NCCALCSIZE, sent|wparam, 1 },
2783     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2784     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2785
2786      /* in MDI child */
2787     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2788     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2789     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2790     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2791
2792      /* in MDI frame */
2793     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2794     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2795     { 0x0093, sent|defwinproc|optional },
2796     { 0x0093, sent|defwinproc|optional },
2797     { 0x0093, sent|defwinproc|optional },
2798     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2799     { WM_MOVE, sent|defwinproc },
2800     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2801
2802      /* in MDI client */
2803     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2804     { WM_NCCALCSIZE, sent|wparam, 1 },
2805     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2806     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2807
2808      /* in MDI child */
2809     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2810     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2811     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2812     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2813     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2814     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2815
2816     { 0x0093, sent|defwinproc|optional },
2817     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2818     { 0x0093, sent|defwinproc|optional },
2819     { 0x0093, sent|defwinproc|optional },
2820     { 0x0093, sent|defwinproc|optional },
2821     { 0x0093, sent|optional },
2822
2823     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2824     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2825     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2826     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2827     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2828
2829      /* in MDI frame */
2830     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2831     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2832     { 0x0093, sent|defwinproc|optional },
2833     { 0x0093, sent|defwinproc|optional },
2834     { 0x0093, sent|defwinproc|optional },
2835     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2836     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2837     { 0x0093, sent|optional },
2838
2839     { WM_NCACTIVATE, sent|wparam, 0 },
2840     { WM_MDIACTIVATE, sent },
2841
2842     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2843     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2844     { WM_NCCALCSIZE, sent|wparam, 1 },
2845
2846     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2847
2848     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2849     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2850     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2851
2852      /* in MDI child */
2853     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2854     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2855     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2856     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2857
2858      /* in MDI frame */
2859     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2860     { WM_NCCALCSIZE, sent|wparam, 1 },
2861     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2862     { WM_MOVE, sent|defwinproc },
2863     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2864
2865      /* in MDI client */
2866     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2867     { WM_NCCALCSIZE, sent|wparam, 1 },
2868     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2869     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2870     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2871     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2872     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2874     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2875
2876     { HCBT_SETFOCUS, hook },
2877     { WM_KILLFOCUS, sent },
2878     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2879     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2880     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2881     { WM_SETFOCUS, sent }, /* in MDI client */
2882
2883     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2884
2885     { HCBT_DESTROYWND, hook },
2886     /* Win2k sends wparam set to
2887      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2888      * while Win9x doesn't bother to set child window id according to
2889      * CLIENTCREATESTRUCT.idFirstChild
2890      */
2891     { 0x0090, sent|optional },
2892     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2893
2894     { WM_SHOWWINDOW, sent|wparam, 0 },
2895     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2896     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2897     { WM_ERASEBKGND, sent|parent|optional },
2898     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2899
2900     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2901     { WM_DESTROY, sent },
2902     { WM_NCDESTROY, sent },
2903     { 0 }
2904 };
2905 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2906 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2907     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2908     { WM_GETMINMAXINFO, sent },
2909     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2910     { WM_NCCALCSIZE, sent|wparam, 1 },
2911     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2912     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2913
2914     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2915     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2916     { HCBT_SETFOCUS, hook|optional },
2917     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2918     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2919     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2920     { HCBT_SETFOCUS, hook|optional },
2921     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2922     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2923     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2924     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2925     { WM_SETFOCUS, sent|optional|defwinproc },
2926     { WM_MDIACTIVATE, sent|optional|defwinproc },
2927     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2928     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2929      /* in MDI frame */
2930     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2931     { WM_NCCALCSIZE, sent|wparam, 1 },
2932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2933     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2934     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2935     { 0 }
2936 };
2937 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2938 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2939     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2940     { WM_GETMINMAXINFO, sent },
2941     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2942     { WM_GETMINMAXINFO, sent|defwinproc },
2943     { WM_NCCALCSIZE, sent|wparam, 1 },
2944     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2945     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2946
2947     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2948     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2949     { HCBT_SETFOCUS, hook|optional },
2950     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2951     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2952     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2953     { HCBT_SETFOCUS, hook|optional },
2954     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2955     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2956     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2957     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2958     { WM_SETFOCUS, sent|defwinproc|optional },
2959     { WM_MDIACTIVATE, sent|defwinproc|optional },
2960     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2961     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2962     { 0 }
2963 };
2964 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2965 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2966     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2967     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2968     { WM_GETMINMAXINFO, sent },
2969     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2970     { WM_GETMINMAXINFO, sent|defwinproc },
2971     { WM_NCCALCSIZE, sent|wparam, 1 },
2972     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2973     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2974     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2975     { WM_MOVE, sent|defwinproc },
2976     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2977
2978     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2979     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2980     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2981     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2982     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2983     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2984      /* in MDI frame */
2985     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2986     { WM_NCCALCSIZE, sent|wparam, 1 },
2987     { 0x0093, sent|defwinproc|optional },
2988     { 0x0094, sent|defwinproc|optional },
2989     { 0x0094, sent|defwinproc|optional },
2990     { 0x0094, sent|defwinproc|optional },
2991     { 0x0094, sent|defwinproc|optional },
2992     { 0x0093, sent|defwinproc|optional },
2993     { 0x0093, sent|defwinproc|optional },
2994     { 0x0091, sent|defwinproc|optional },
2995     { 0x0092, sent|defwinproc|optional },
2996     { 0x0092, sent|defwinproc|optional },
2997     { 0x0092, sent|defwinproc|optional },
2998     { 0x0092, sent|defwinproc|optional },
2999     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3000     { WM_MOVE, sent|defwinproc },
3001     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3002     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3003      /* in MDI client */
3004     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3005     { WM_NCCALCSIZE, sent|wparam, 1 },
3006     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3007     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3008      /* in MDI child */
3009     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3010     { WM_GETMINMAXINFO, sent|defwinproc },
3011     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3012     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3013     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3014     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3015     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3016     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3017     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3018     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3019      /* in MDI frame */
3020     { 0x0093, sent|optional },
3021     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3022     { 0x0093, sent|defwinproc|optional },
3023     { 0x0093, sent|defwinproc|optional },
3024     { 0x0093, sent|defwinproc|optional },
3025     { 0x0091, sent|defwinproc|optional },
3026     { 0x0092, sent|defwinproc|optional },
3027     { 0x0092, sent|defwinproc|optional },
3028     { 0x0092, sent|defwinproc|optional },
3029     { 0x0092, sent|defwinproc|optional },
3030     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3032     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3033     { 0 }
3034 };
3035 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3036 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3037     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3038     { WM_GETMINMAXINFO, sent },
3039     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3040     { WM_NCCALCSIZE, sent|wparam, 1 },
3041     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3042     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3043     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3044      /* in MDI frame */
3045     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3046     { WM_NCCALCSIZE, sent|wparam, 1 },
3047     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3048     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3049     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3050     { 0 }
3051 };
3052 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3053 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3054     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3055     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3056     { WM_NCCALCSIZE, sent|wparam, 1 },
3057     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3058     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3059     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3060      /* in MDI frame */
3061     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3062     { WM_NCCALCSIZE, sent|wparam, 1 },
3063     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3064     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3065     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3066     { 0 }
3067 };
3068 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3069 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3070     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3071     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3072     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3073     { WM_NCCALCSIZE, sent|wparam, 1 },
3074     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3075     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3076     { WM_MOVE, sent|defwinproc },
3077     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3078     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3079     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3080     { HCBT_SETFOCUS, hook },
3081     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3082     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3083     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3084     { WM_SETFOCUS, sent },
3085     { 0 }
3086 };
3087 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3088 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3089     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3090     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3091     { WM_NCCALCSIZE, sent|wparam, 1 },
3092     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3093     { WM_MOVE, sent|defwinproc },
3094     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3095     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3096     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3097     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3098     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3099     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3100     { 0 }
3101 };
3102 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3103 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3104     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3105     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3106     { WM_NCCALCSIZE, sent|wparam, 1 },
3107     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3108     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3109     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3110     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3111      /* in MDI frame */
3112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3113     { WM_NCCALCSIZE, sent|wparam, 1 },
3114     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3115     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3116     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3117     { 0 }
3118 };
3119
3120 static HWND mdi_client;
3121 static WNDPROC old_mdi_client_proc;
3122
3123 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3124 {
3125     struct recvd_message msg;
3126
3127     /* do not log painting messages */
3128     if (message != WM_PAINT &&
3129         message != WM_NCPAINT &&
3130         message != WM_SYNCPAINT &&
3131         message != WM_ERASEBKGND &&
3132         message != WM_NCHITTEST &&
3133         message != WM_GETTEXT &&
3134         message != WM_MDIGETACTIVE &&
3135         message != WM_GETICON &&
3136         message != WM_GETOBJECT &&
3137         message != WM_DEVICECHANGE)
3138     {
3139         msg.hwnd = hwnd;
3140         msg.message = message;
3141         msg.flags = sent|wparam|lparam;
3142         msg.wParam = wParam;
3143         msg.lParam = lParam;
3144         msg.descr = "mdi client";
3145         add_message(&msg);
3146     }
3147
3148     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3149 }
3150
3151 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3152 {
3153     static long defwndproc_counter = 0;
3154     LRESULT ret;
3155     struct recvd_message msg;
3156
3157     /* do not log painting messages */
3158     if (message != WM_PAINT &&
3159         message != WM_NCPAINT &&
3160         message != WM_SYNCPAINT &&
3161         message != WM_ERASEBKGND &&
3162         message != WM_NCHITTEST &&
3163         message != WM_GETTEXT &&
3164         message != WM_GETICON &&
3165         message != WM_GETOBJECT &&
3166         message != WM_DEVICECHANGE)
3167     {
3168         switch (message)
3169         {
3170             case WM_MDIACTIVATE:
3171             {
3172                 HWND active, client = GetParent(hwnd);
3173
3174                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3175
3176                 if (hwnd == (HWND)lParam) /* if we are being activated */
3177                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3178                 else
3179                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3180                 break;
3181             }
3182         }
3183
3184         msg.hwnd = hwnd;
3185         msg.message = message;
3186         msg.flags = sent|wparam|lparam;
3187         if (defwndproc_counter) msg.flags |= defwinproc;
3188         msg.wParam = wParam;
3189         msg.lParam = lParam;
3190         msg.descr = "mdi child";
3191         add_message(&msg);
3192     }
3193
3194     defwndproc_counter++;
3195     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3196     defwndproc_counter--;
3197
3198     return ret;
3199 }
3200
3201 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3202 {
3203     static long defwndproc_counter = 0;
3204     LRESULT ret;
3205     struct recvd_message msg;
3206
3207     /* do not log painting messages */
3208     if (message != WM_PAINT &&
3209         message != WM_NCPAINT &&
3210         message != WM_SYNCPAINT &&
3211         message != WM_ERASEBKGND &&
3212         message != WM_NCHITTEST &&
3213         message != WM_GETTEXT &&
3214         message != WM_GETICON &&
3215         message != WM_GETOBJECT &&
3216         message != WM_DEVICECHANGE)
3217     {
3218         msg.hwnd = hwnd;
3219         msg.message = message;
3220         msg.flags = sent|wparam|lparam;
3221         if (defwndproc_counter) msg.flags |= defwinproc;
3222         msg.wParam = wParam;
3223         msg.lParam = lParam;
3224         msg.descr = "mdi frame";
3225         add_message(&msg);
3226     }
3227
3228     defwndproc_counter++;
3229     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3230     defwndproc_counter--;
3231
3232     return ret;
3233 }
3234
3235 static BOOL mdi_RegisterWindowClasses(void)
3236 {
3237     WNDCLASSA cls;
3238
3239     cls.style = 0;
3240     cls.lpfnWndProc = mdi_frame_wnd_proc;
3241     cls.cbClsExtra = 0;
3242     cls.cbWndExtra = 0;
3243     cls.hInstance = GetModuleHandleA(0);
3244     cls.hIcon = 0;
3245     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3246     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3247     cls.lpszMenuName = NULL;
3248     cls.lpszClassName = "MDI_frame_class";
3249     if (!RegisterClassA(&cls)) return FALSE;
3250
3251     cls.lpfnWndProc = mdi_child_wnd_proc;
3252     cls.lpszClassName = "MDI_child_class";
3253     if (!RegisterClassA(&cls)) return FALSE;
3254
3255     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3256     old_mdi_client_proc = cls.lpfnWndProc;
3257     cls.hInstance = GetModuleHandleA(0);
3258     cls.lpfnWndProc = mdi_client_hook_proc;
3259     cls.lpszClassName = "MDI_client_class";
3260     if (!RegisterClassA(&cls)) assert(0);
3261
3262     return TRUE;
3263 }
3264
3265 static void test_mdi_messages(void)
3266 {
3267     MDICREATESTRUCTA mdi_cs;
3268     CLIENTCREATESTRUCT client_cs;
3269     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3270     BOOL zoomed;
3271     HMENU hMenu = CreateMenu();
3272
3273     assert(mdi_RegisterWindowClasses());
3274
3275     flush_sequence();
3276
3277     trace("creating MDI frame window\n");
3278     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3279                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3280                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3281                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3282                                 GetDesktopWindow(), hMenu,
3283                                 GetModuleHandleA(0), NULL);
3284     assert(mdi_frame);
3285     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3286
3287     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3288     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3289
3290     trace("creating MDI client window\n");
3291     client_cs.hWindowMenu = 0;
3292     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3293     mdi_client = CreateWindowExA(0, "MDI_client_class",
3294                                  NULL,
3295                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3296                                  0, 0, 0, 0,
3297                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3298     assert(mdi_client);
3299     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3300
3301     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3302     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3303
3304     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3305     ok(!active_child, "wrong active MDI child %p\n", active_child);
3306     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3307
3308     SetFocus(0);
3309     flush_sequence();
3310
3311     trace("creating invisible MDI child window\n");
3312     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3313                                 WS_CHILD,
3314                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3315                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3316     assert(mdi_child);
3317
3318     flush_sequence();
3319     ShowWindow(mdi_child, SW_SHOWNORMAL);
3320     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3321
3322     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3323     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3324
3325     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3326     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3327
3328     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3329     ok(!active_child, "wrong active MDI child %p\n", active_child);
3330     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3331
3332     ShowWindow(mdi_child, SW_HIDE);
3333     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3334     flush_sequence();
3335
3336     ShowWindow(mdi_child, SW_SHOW);
3337     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3338
3339     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3340     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3341
3342     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3343     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3344
3345     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3346     ok(!active_child, "wrong active MDI child %p\n", active_child);
3347     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3348
3349     DestroyWindow(mdi_child);
3350     flush_sequence();
3351
3352     trace("creating visible MDI child window\n");
3353     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3354                                 WS_CHILD | WS_VISIBLE,
3355                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3356                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3357     assert(mdi_child);
3358     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3359
3360     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3361     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3362
3363     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3364     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3365
3366     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3367     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3368     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3369     flush_sequence();
3370
3371     DestroyWindow(mdi_child);
3372     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3373
3374     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3375     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3376
3377     /* Win2k: MDI client still returns a just destroyed child as active
3378      * Win9x: MDI client returns 0
3379      */
3380     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3381     ok(active_child == mdi_child || /* win2k */
3382        !active_child, /* win9x */
3383        "wrong active MDI child %p\n", active_child);
3384     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3385
3386     flush_sequence();
3387
3388     trace("creating invisible MDI child window\n");
3389     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3390                                 WS_CHILD,
3391                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3392                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3393     assert(mdi_child2);
3394     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3395
3396     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3397     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3398
3399     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3400     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3401
3402     /* Win2k: MDI client still returns a just destroyed child as active
3403      * Win9x: MDI client returns mdi_child2
3404      */
3405     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3406     ok(active_child == mdi_child || /* win2k */
3407        active_child == mdi_child2, /* win9x */
3408        "wrong active MDI child %p\n", active_child);
3409     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3410     flush_sequence();
3411
3412     ShowWindow(mdi_child2, SW_MAXIMIZE);
3413     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3414
3415     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3416     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3417
3418     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3419     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3420     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3421     flush_sequence();
3422
3423     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3424     ok(GetFocus() == mdi_child2 || /* win2k */
3425        GetFocus() == 0, /* win9x */
3426        "wrong focus window %p\n", GetFocus());
3427
3428     SetFocus(0);
3429     flush_sequence();
3430
3431     ShowWindow(mdi_child2, SW_HIDE);
3432     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3433
3434     ShowWindow(mdi_child2, SW_RESTORE);
3435     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3436     flush_sequence();
3437
3438     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3439     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3440
3441     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3442     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3443     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3444     flush_sequence();
3445
3446     SetFocus(0);
3447     flush_sequence();
3448
3449     ShowWindow(mdi_child2, SW_HIDE);
3450     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3451
3452     ShowWindow(mdi_child2, SW_SHOW);
3453     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3454
3455     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3456     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3457
3458     ShowWindow(mdi_child2, SW_MAXIMIZE);
3459     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3460
3461     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3462     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3463
3464     ShowWindow(mdi_child2, SW_RESTORE);
3465     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3466
3467     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3468     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3469
3470     ShowWindow(mdi_child2, SW_MINIMIZE);
3471     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3472
3473     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3474     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3475
3476     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3477     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3478     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3479     flush_sequence();
3480
3481     ShowWindow(mdi_child2, SW_RESTORE);
3482     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3483
3484     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3485     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
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     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3499     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3500
3501     DestroyWindow(mdi_child2);
3502     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3503
3504     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3505     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3506
3507     /* test for maximized MDI children */
3508     trace("creating maximized visible MDI child window 1\n");
3509     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3510                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3511                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3512                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3513     assert(mdi_child);
3514     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3515     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3516
3517     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3518     ok(GetFocus() == mdi_child || /* win2k */
3519        GetFocus() == 0, /* win9x */
3520        "wrong focus window %p\n", GetFocus());
3521
3522     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3523     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3524     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3525     flush_sequence();
3526
3527     trace("creating maximized visible MDI child window 2\n");
3528     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3529                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3530                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3531                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3532     assert(mdi_child2);
3533     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3534     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3535     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3536
3537     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3538     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3539
3540     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3541     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3542     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3543     flush_sequence();
3544
3545     trace("destroying maximized visible MDI child window 2\n");
3546     DestroyWindow(mdi_child2);
3547     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3548
3549     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3550
3551     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3552     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3553
3554     /* Win2k: MDI client still returns a just destroyed child as active
3555      * Win9x: MDI client returns 0
3556      */
3557     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3558     ok(active_child == mdi_child2 || /* win2k */
3559        !active_child, /* win9x */
3560        "wrong active MDI child %p\n", active_child);
3561     flush_sequence();
3562
3563     ShowWindow(mdi_child, SW_MAXIMIZE);
3564     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3565     flush_sequence();
3566
3567     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3568     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3569
3570     trace("re-creating maximized visible MDI child window 2\n");
3571     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3572                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3573                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3574                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3575     assert(mdi_child2);
3576     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3577     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3578     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3579
3580     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3581     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3582
3583     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3584     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3585     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3586     flush_sequence();
3587
3588     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3589     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3590     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3591
3592     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3593     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3594     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3595
3596     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3597     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3598     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3599     flush_sequence();
3600
3601     DestroyWindow(mdi_child);
3602     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3603
3604     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3605     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3606
3607     /* Win2k: MDI client still returns a just destroyed child as active
3608      * Win9x: MDI client returns 0
3609      */
3610     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3611     ok(active_child == mdi_child || /* win2k */
3612        !active_child, /* win9x */
3613        "wrong active MDI child %p\n", active_child);
3614     flush_sequence();
3615
3616     trace("creating maximized invisible MDI child window\n");
3617     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3618                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3619                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3620                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3621     assert(mdi_child2);
3622     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3623     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3624     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3625     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3626
3627     /* Win2k: MDI client still returns a just destroyed child as active
3628      * Win9x: MDI client returns 0
3629      */
3630     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3631     ok(active_child == mdi_child || /* win2k */
3632        !active_child, /* win9x */
3633        "wrong active MDI child %p\n", active_child);
3634     flush_sequence();
3635
3636     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3637     ShowWindow(mdi_child2, SW_MAXIMIZE);
3638     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3639     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3640     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3641     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3642
3643     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3644     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3645     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3646     flush_sequence();
3647
3648     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3649     flush_sequence();
3650
3651     /* end of test for maximized MDI children */
3652     SetFocus(0);
3653     flush_sequence();
3654     trace("creating maximized visible MDI child window 1(Switch test)\n");
3655     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3656                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3657                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3658                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3659     assert(mdi_child);
3660     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3661     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3662
3663     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3664     ok(GetFocus() == mdi_child || /* win2k */
3665        GetFocus() == 0, /* win9x */
3666        "wrong focus window %p(Switch test)\n", GetFocus());
3667
3668     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3669     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3670     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3671     flush_sequence();
3672
3673     trace("creating maximized visible MDI child window 2(Switch test)\n");
3674     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3675                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3676                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3677                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3678     assert(mdi_child2);
3679     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3680
3681     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3682     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3683
3684     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3685     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3686
3687     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3688     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3689     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3690     flush_sequence();
3691
3692     trace("Switch child window.\n");
3693     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3694     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3695     trace("end of test for switch maximized MDI children\n");
3696     flush_sequence();
3697
3698     /* Prepare for switching test of not maximized MDI children  */
3699     ShowWindow( mdi_child, SW_NORMAL );
3700     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3701     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3702     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3703     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3704     flush_sequence();
3705
3706     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3707     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3708     trace("end of test for switch not maximized MDI children\n");
3709     flush_sequence();
3710
3711     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3712     flush_sequence();
3713
3714     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3715     flush_sequence();
3716
3717     SetFocus(0);
3718     flush_sequence();
3719     /* end of tests for switch maximized/not maximized MDI children */
3720
3721     mdi_cs.szClass = "MDI_child_Class";
3722     mdi_cs.szTitle = "MDI child";
3723     mdi_cs.hOwner = GetModuleHandleA(0);
3724     mdi_cs.x = 0;
3725     mdi_cs.y = 0;
3726     mdi_cs.cx = CW_USEDEFAULT;
3727     mdi_cs.cy = CW_USEDEFAULT;
3728     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3729     mdi_cs.lParam = 0;
3730     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3731     ok(mdi_child != 0, "MDI child creation failed\n");
3732     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3733
3734     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3735
3736     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3737     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3738
3739     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3740     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3741     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3742
3743     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3744     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3745     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3746     flush_sequence();
3747
3748     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3749     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3750
3751     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3752     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3753     ok(!active_child, "wrong active MDI child %p\n", active_child);
3754
3755     SetFocus(0);
3756     flush_sequence();
3757
3758     DestroyWindow(mdi_client);
3759     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3760
3761     /* test maximization of MDI child with invisible parent */
3762     client_cs.hWindowMenu = 0;
3763     mdi_client = CreateWindow("MDI_client_class",
3764                                  NULL,
3765                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3766                                  0, 0, 660, 430,
3767                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3768     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3769
3770     ShowWindow(mdi_client, SW_HIDE);
3771     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3772
3773     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3774                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3775                                 0, 0, 650, 440,
3776                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3777     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3778
3779     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3780     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3781     zoomed = IsZoomed(mdi_child);
3782     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3783     
3784     ShowWindow(mdi_client, SW_SHOW);
3785     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3786
3787     DestroyWindow(mdi_child);
3788     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3789
3790     /* end of test for maximization of MDI child with invisible parent */
3791
3792     DestroyWindow(mdi_client);
3793     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3794
3795     DestroyWindow(mdi_frame);
3796     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3797 }
3798 /************************* End of MDI test **********************************/
3799
3800 static void test_WM_SETREDRAW(HWND hwnd)
3801 {
3802     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3803
3804     flush_events();
3805     flush_sequence();
3806
3807     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3808     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3809
3810     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3811     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3812
3813     flush_sequence();
3814     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3815     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3816
3817     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3818     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3819
3820     /* restore original WS_VISIBLE state */
3821     SetWindowLongA(hwnd, GWL_STYLE, style);
3822
3823     flush_events();
3824     flush_sequence();
3825 }
3826
3827 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3828 {
3829     struct recvd_message msg;
3830
3831     switch (message)
3832     {
3833         /* ignore */
3834         case WM_GETICON:
3835         case WM_GETOBJECT:
3836         case WM_MOUSEMOVE:
3837         case WM_SETCURSOR:
3838         case WM_DEVICECHANGE:
3839             return 0;
3840         case WM_NCHITTEST:
3841             return HTCLIENT;
3842     }
3843
3844     msg.hwnd = hwnd;
3845     msg.message = message;
3846     msg.flags = sent|wparam|lparam;
3847     msg.wParam = wParam;
3848     msg.lParam = lParam;
3849     msg.descr = "dialog";
3850     add_message(&msg);
3851
3852     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3853     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3854     return 0;
3855 }
3856
3857 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3858 {
3859     DWORD style, exstyle;
3860     INT xmin, xmax;
3861     BOOL ret;
3862
3863     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3864     style = GetWindowLongA(hwnd, GWL_STYLE);
3865     /* do not be confused by WS_DLGFRAME set */
3866     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3867
3868     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3869     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3870
3871     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3872     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3873     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3874         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3875     else
3876         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3877
3878     style = GetWindowLongA(hwnd, GWL_STYLE);
3879     if (set) ok(style & set, "style %08x should be set\n", set);
3880     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3881
3882     /* a subsequent call should do nothing */
3883     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3884     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3885     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3886
3887     xmin = 0xdeadbeef;
3888     xmax = 0xdeadbeef;
3889     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3890     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3891     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3892     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3893     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3894     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3895 }
3896
3897 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3898 {
3899     DWORD style, exstyle;
3900     SCROLLINFO si;
3901     BOOL ret;
3902
3903     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3904     style = GetWindowLongA(hwnd, GWL_STYLE);
3905     /* do not be confused by WS_DLGFRAME set */
3906     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3907
3908     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3909     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3910
3911     si.cbSize = sizeof(si);
3912     si.fMask = SIF_RANGE;
3913     si.nMin = min;
3914     si.nMax = max;
3915     SetScrollInfo(hwnd, ctl, &si, TRUE);
3916     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3917         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3918     else
3919         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3920
3921     style = GetWindowLongA(hwnd, GWL_STYLE);
3922     if (set) ok(style & set, "style %08x should be set\n", set);
3923     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3924
3925     /* a subsequent call should do nothing */
3926     SetScrollInfo(hwnd, ctl, &si, TRUE);
3927     if (style & WS_HSCROLL)
3928         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3929     else if (style & WS_VSCROLL)
3930         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3931     else
3932         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3933
3934     si.fMask = SIF_PAGE;
3935     si.nPage = 5;
3936     SetScrollInfo(hwnd, ctl, &si, FALSE);
3937     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3938
3939     si.fMask = SIF_POS;
3940     si.nPos = max - 1;
3941     SetScrollInfo(hwnd, ctl, &si, FALSE);
3942     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3943
3944     si.fMask = SIF_RANGE;
3945     si.nMin = 0xdeadbeef;
3946     si.nMax = 0xdeadbeef;
3947     ret = GetScrollInfo(hwnd, ctl, &si);
3948     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3949     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3950     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3951     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3952 }
3953
3954 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3955 static void test_scroll_messages(HWND hwnd)
3956 {
3957     SCROLLINFO si;
3958     INT min, max;
3959     BOOL ret;
3960
3961     flush_events();
3962     flush_sequence();
3963
3964     min = 0xdeadbeef;
3965     max = 0xdeadbeef;
3966     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3967     ok( ret, "GetScrollRange error %d\n", GetLastError());
3968     if (sequence->message != WmGetScrollRangeSeq[0].message)
3969         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3970     /* values of min and max are undefined */
3971     flush_sequence();
3972
3973     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3974     ok( ret, "SetScrollRange error %d\n", GetLastError());
3975     if (sequence->message != WmSetScrollRangeSeq[0].message)
3976         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3977     flush_sequence();
3978
3979     min = 0xdeadbeef;
3980     max = 0xdeadbeef;
3981     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3982     ok( ret, "GetScrollRange error %d\n", GetLastError());
3983     if (sequence->message != WmGetScrollRangeSeq[0].message)
3984         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3985     /* values of min and max are undefined */
3986     flush_sequence();
3987
3988     si.cbSize = sizeof(si);
3989     si.fMask = SIF_RANGE;
3990     si.nMin = 20;
3991     si.nMax = 160;
3992     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3993     if (sequence->message != WmSetScrollRangeSeq[0].message)
3994         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3995     flush_sequence();
3996
3997     si.fMask = SIF_PAGE;
3998     si.nPage = 10;
3999     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4000     if (sequence->message != WmSetScrollRangeSeq[0].message)
4001         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4002     flush_sequence();
4003
4004     si.fMask = SIF_POS;
4005     si.nPos = 20;
4006     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4007     if (sequence->message != WmSetScrollRangeSeq[0].message)
4008         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4009     flush_sequence();
4010
4011     si.fMask = SIF_RANGE;
4012     si.nMin = 0xdeadbeef;
4013     si.nMax = 0xdeadbeef;
4014     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4015     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4016     if (sequence->message != WmGetScrollInfoSeq[0].message)
4017         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4018     /* values of min and max are undefined */
4019     flush_sequence();
4020
4021     /* set WS_HSCROLL */
4022     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4023     /* clear WS_HSCROLL */
4024     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4025
4026     /* set WS_HSCROLL */
4027     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4028     /* clear WS_HSCROLL */
4029     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4030
4031     /* set WS_VSCROLL */
4032     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4033     /* clear WS_VSCROLL */
4034     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4035
4036     /* set WS_VSCROLL */
4037     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4038     /* clear WS_VSCROLL */
4039     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4040 }
4041
4042 static void test_showwindow(void)
4043 {
4044     HWND hwnd, hchild;
4045     RECT rc;
4046
4047     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4048                            100, 100, 200, 200, 0, 0, 0, NULL);
4049     ok (hwnd != 0, "Failed to create overlapped window\n");
4050     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4051                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4052     ok (hchild != 0, "Failed to create child\n");
4053     flush_sequence();
4054
4055     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4056     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4057     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4058     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
4059
4060     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4061     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4062     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4063     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4064     /* back to invisible */
4065     ShowWindow(hchild, SW_HIDE);
4066     ShowWindow(hwnd, SW_HIDE);
4067     flush_sequence();
4068     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4069     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4070     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4071     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4072     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4073     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4074     flush_sequence();
4075     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4076     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4077     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4078     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4079     ShowWindow( hwnd, SW_SHOW);
4080     flush_sequence();
4081     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4082     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4083     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4084
4085     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4086     ShowWindow( hchild, SW_HIDE);
4087     flush_sequence();
4088     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4089     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4090     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4091
4092     SetCapture(hchild);
4093     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4094     DestroyWindow(hchild);
4095     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4096
4097     DestroyWindow(hwnd);
4098     flush_sequence();
4099
4100     /* Popup windows */
4101     /* Test 1:
4102      * 1. Create invisible maximized popup window.
4103      * 2. Move and resize it.
4104      * 3. Show it maximized.
4105      */
4106     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4107     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4108                            100, 100, 200, 200, 0, 0, 0, NULL);
4109     ok (hwnd != 0, "Failed to create popup window\n");
4110     ok(IsZoomed(hwnd), "window should be maximized\n");
4111     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4112
4113     GetWindowRect(hwnd, &rc);
4114     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4115         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4116         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4117         rc.left, rc.top, rc.right, rc.bottom);
4118     /* Reset window's size & position */
4119     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4120     ok(IsZoomed(hwnd), "window should be maximized\n");
4121     flush_sequence();
4122
4123     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4124     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4125     ok(IsZoomed(hwnd), "window should be maximized\n");
4126     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4127
4128     GetWindowRect(hwnd, &rc);
4129     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4130         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4131         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4132         rc.left, rc.top, rc.right, rc.bottom);
4133     DestroyWindow(hwnd);
4134     flush_sequence();
4135
4136     /* Test 2:
4137      * 1. Create invisible maximized popup window.
4138      * 2. Show it maximized.
4139      */
4140     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4141     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4142                            100, 100, 200, 200, 0, 0, 0, NULL);
4143     ok (hwnd != 0, "Failed to create popup window\n");
4144     ok(IsZoomed(hwnd), "window should be maximized\n");
4145     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4146
4147     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4148     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4149     ok(IsZoomed(hwnd), "window should be maximized\n");
4150     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4151     DestroyWindow(hwnd);
4152     flush_sequence();
4153
4154     /* Test 3:
4155      * 1. Create visible maximized popup window.
4156      */
4157     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4158     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4159                            100, 100, 200, 200, 0, 0, 0, NULL);
4160     ok (hwnd != 0, "Failed to create popup window\n");
4161     ok(IsZoomed(hwnd), "window should be maximized\n");
4162     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4163     DestroyWindow(hwnd);
4164     flush_sequence();
4165
4166     /* Test 4:
4167      * 1. Create visible popup window.
4168      * 2. Maximize it.
4169      */
4170     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4171     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4172                            100, 100, 200, 200, 0, 0, 0, NULL);
4173     ok (hwnd != 0, "Failed to create popup window\n");
4174     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4175     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4176
4177     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4178     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4179     ok(IsZoomed(hwnd), "window should be maximized\n");
4180     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4181     DestroyWindow(hwnd);
4182     flush_sequence();
4183 }
4184
4185 static void test_sys_menu(void)
4186 {
4187     HWND hwnd;
4188     HMENU hmenu;
4189     UINT state;
4190
4191     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4192                            100, 100, 200, 200, 0, 0, 0, NULL);
4193     ok (hwnd != 0, "Failed to create overlapped window\n");
4194
4195     flush_sequence();
4196
4197     /* test existing window without CS_NOCLOSE style */
4198     hmenu = GetSystemMenu(hwnd, FALSE);
4199     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4200
4201     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4202     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4203     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4204
4205     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4206     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4207
4208     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4209     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4210     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4211
4212     EnableMenuItem(hmenu, SC_CLOSE, 0);
4213     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4214
4215     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4216     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4217     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4218
4219     /* test whether removing WS_SYSMENU destroys a system menu */
4220     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4221     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4222     flush_sequence();
4223     hmenu = GetSystemMenu(hwnd, FALSE);
4224     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4225
4226     DestroyWindow(hwnd);
4227
4228     /* test new window with CS_NOCLOSE style */
4229     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4230                            100, 100, 200, 200, 0, 0, 0, NULL);
4231     ok (hwnd != 0, "Failed to create overlapped window\n");
4232
4233     hmenu = GetSystemMenu(hwnd, FALSE);
4234     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4235
4236     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4237     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4238
4239     DestroyWindow(hwnd);
4240
4241     /* test new window without WS_SYSMENU style */
4242     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4243                            100, 100, 200, 200, 0, 0, 0, NULL);
4244     ok(hwnd != 0, "Failed to create overlapped window\n");
4245
4246     hmenu = GetSystemMenu(hwnd, FALSE);
4247     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4248
4249     DestroyWindow(hwnd);
4250 }
4251
4252 /* For shown WS_OVERLAPPEDWINDOW */
4253 static const struct message WmSetIcon_1[] = {
4254     { WM_SETICON, sent },
4255     { 0x00AE, sent|defwinproc|optional }, /* XP */
4256     { WM_GETTEXT, sent|defwinproc|optional },
4257     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4258     { 0 }
4259 };
4260
4261 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4262 static const struct message WmSetIcon_2[] = {
4263     { WM_SETICON, sent },
4264     { 0 }
4265 };
4266
4267 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4268 static const struct message WmInitEndSession[] = {
4269     { 0x003B, sent },
4270     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4271     { 0 }
4272 };
4273
4274 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4275 static const struct message WmInitEndSession_2[] = {
4276     { 0x003B, sent },
4277     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4278     { 0 }
4279 };
4280
4281 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4282 static const struct message WmInitEndSession_3[] = {
4283     { 0x003B, sent },
4284     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4285     { 0 }
4286 };
4287
4288 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4289 static const struct message WmInitEndSession_4[] = {
4290     { 0x003B, sent },
4291     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4292     { 0 }
4293 };
4294
4295 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4296 static const struct message WmInitEndSession_5[] = {
4297     { 0x003B, sent },
4298     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4299     { 0 }
4300 };
4301
4302 static const struct message WmOptionalPaint[] = {
4303     { WM_PAINT, sent|optional },
4304     { WM_NCPAINT, sent|beginpaint|optional },
4305     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4306     { WM_ERASEBKGND, sent|beginpaint|optional },
4307     { 0 }
4308 };
4309
4310 static const struct message WmZOrder[] = {
4311     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4312     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4313     { HCBT_ACTIVATE, hook },
4314     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4315     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4316     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4317     { WM_GETTEXT, sent|optional },
4318     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4319     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4320     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4321     { WM_GETTEXT, sent|defwinproc|optional },
4322     { WM_GETTEXT, sent|defwinproc|optional },
4323     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4324     { HCBT_SETFOCUS, hook },
4325     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4326     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4327     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4328     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4329     { WM_GETTEXT, sent|optional },
4330     { WM_NCCALCSIZE, sent|optional },
4331     { 0 }
4332 };
4333
4334 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4335 {
4336     DWORD ret;
4337     MSG msg;
4338
4339     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4340     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4341
4342     PostMessageA(hwnd, WM_USER, 0, 0);
4343
4344     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4345     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4346
4347     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4348     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4349
4350     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4351     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4352
4353     PostMessageA(hwnd, WM_USER, 0, 0);
4354
4355     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4356     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4357
4358     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4359     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4360
4361     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4362     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4363     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4364
4365     PostMessageA(hwnd, WM_USER, 0, 0);
4366
4367     /* new incoming message causes it to become signaled again */
4368     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4369     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4370
4371     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4372     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4373     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4374     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4375 }
4376
4377 /* test if we receive the right sequence of messages */
4378 static void test_messages(void)
4379 {
4380     HWND hwnd, hparent, hchild;
4381     HWND hchild2, hbutton;
4382     HMENU hmenu;
4383     MSG msg;
4384     LRESULT res;
4385
4386     flush_sequence();
4387
4388     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4389                            100, 100, 200, 200, 0, 0, 0, NULL);
4390     ok (hwnd != 0, "Failed to create overlapped window\n");
4391     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4392
4393     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4394     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4395     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4396
4397     /* test WM_SETREDRAW on a not visible top level window */
4398     test_WM_SETREDRAW(hwnd);
4399
4400     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4401     flush_events();
4402     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4403     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4404
4405     ok(GetActiveWindow() == hwnd, "window should be active\n");
4406     ok(GetFocus() == hwnd, "window should have input focus\n");
4407     ShowWindow(hwnd, SW_HIDE);
4408     flush_events();
4409     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4410
4411     ShowWindow(hwnd, SW_SHOW);
4412     flush_events();
4413     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4414
4415     ShowWindow(hwnd, SW_HIDE);
4416     flush_events();
4417     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4418
4419     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4420     flush_events();
4421     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4422
4423     ShowWindow(hwnd, SW_RESTORE);
4424     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4425     flush_events();
4426     flush_sequence();
4427
4428     ShowWindow(hwnd, SW_MINIMIZE);
4429     flush_events();
4430     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4431     flush_sequence();
4432
4433     ShowWindow(hwnd, SW_RESTORE);
4434     flush_events();
4435     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4436     flush_sequence();
4437
4438     ShowWindow(hwnd, SW_SHOW);
4439     flush_events();
4440     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4441
4442     ok(GetActiveWindow() == hwnd, "window should be active\n");
4443     ok(GetFocus() == hwnd, "window should have input focus\n");
4444     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4445     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4446     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4447     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4448
4449     /* test WM_SETREDRAW on a visible top level window */
4450     ShowWindow(hwnd, SW_SHOW);
4451     flush_events();
4452     test_WM_SETREDRAW(hwnd);
4453
4454     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4455     test_scroll_messages(hwnd);
4456
4457     /* test resizing and moving */
4458     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4459     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4460     flush_events();
4461     flush_sequence();
4462     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4463     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4464     flush_events();
4465     flush_sequence();
4466     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4467     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4468     flush_events();
4469     flush_sequence();
4470
4471     /* popups don't get WM_GETMINMAXINFO */
4472     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4473     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4474     flush_sequence();
4475     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4476     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4477
4478     DestroyWindow(hwnd);
4479     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4480
4481     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4482                               100, 100, 200, 200, 0, 0, 0, NULL);
4483     ok (hparent != 0, "Failed to create parent window\n");
4484     flush_sequence();
4485
4486     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4487                              0, 0, 10, 10, hparent, 0, 0, NULL);
4488     ok (hchild != 0, "Failed to create child window\n");
4489     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4490     DestroyWindow(hchild);
4491     flush_sequence();
4492
4493     /* visible child window with a caption */
4494     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4495                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4496                              0, 0, 10, 10, hparent, 0, 0, NULL);
4497     ok (hchild != 0, "Failed to create child window\n");
4498     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4499
4500     trace("testing scroll APIs on a visible child window %p\n", hchild);
4501     test_scroll_messages(hchild);
4502
4503     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4504     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4505
4506     DestroyWindow(hchild);
4507     flush_sequence();
4508
4509     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4510                              0, 0, 10, 10, hparent, 0, 0, NULL);
4511     ok (hchild != 0, "Failed to create child window\n");
4512     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4513     
4514     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4515                                100, 100, 50, 50, hparent, 0, 0, NULL);
4516     ok (hchild2 != 0, "Failed to create child2 window\n");
4517     flush_sequence();
4518
4519     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4520                               0, 100, 50, 50, hchild, 0, 0, NULL);
4521     ok (hbutton != 0, "Failed to create button window\n");
4522
4523     /* test WM_SETREDRAW on a not visible child window */
4524     test_WM_SETREDRAW(hchild);
4525
4526     ShowWindow(hchild, SW_SHOW);
4527     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4528
4529     /* check parent messages too */
4530     log_all_parent_messages++;
4531     ShowWindow(hchild, SW_HIDE);
4532     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4533     log_all_parent_messages--;
4534
4535     ShowWindow(hchild, SW_SHOW);
4536     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4537
4538     ShowWindow(hchild, SW_HIDE);
4539     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4540
4541     ShowWindow(hchild, SW_SHOW);
4542     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4543
4544     /* test WM_SETREDRAW on a visible child window */
4545     test_WM_SETREDRAW(hchild);
4546
4547     log_all_parent_messages++;
4548     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4549     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4550     log_all_parent_messages--;
4551
4552     ShowWindow(hchild, SW_HIDE);
4553     flush_sequence();
4554     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4555     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4556
4557     ShowWindow(hchild, SW_HIDE);
4558     flush_sequence();
4559     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4560     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4561
4562     /* DestroyWindow sequence below expects that a child has focus */
4563     SetFocus(hchild);
4564     flush_sequence();
4565
4566     DestroyWindow(hchild);
4567     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4568     DestroyWindow(hchild2);
4569     DestroyWindow(hbutton);
4570
4571     flush_sequence();
4572     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4573                              0, 0, 100, 100, hparent, 0, 0, NULL);
4574     ok (hchild != 0, "Failed to create child popup window\n");
4575     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4576     DestroyWindow(hchild);
4577
4578     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4579     flush_sequence();
4580     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4581                              0, 0, 100, 100, hparent, 0, 0, NULL);
4582     ok (hchild != 0, "Failed to create popup window\n");
4583     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4584     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4585     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4586     flush_sequence();
4587     ShowWindow(hchild, SW_SHOW);
4588     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4589     flush_sequence();
4590     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4591     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4592     flush_sequence();
4593     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4594     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4595     DestroyWindow(hchild);
4596
4597     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4598      * changes nothing in message sequences.
4599      */
4600     flush_sequence();
4601     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4602                              0, 0, 100, 100, hparent, 0, 0, NULL);
4603     ok (hchild != 0, "Failed to create popup window\n");
4604     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4605     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4606     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4607     flush_sequence();
4608     ShowWindow(hchild, SW_SHOW);
4609     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4610     flush_sequence();
4611     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4612     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4613     DestroyWindow(hchild);
4614
4615     flush_sequence();
4616     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4617                            0, 0, 100, 100, hparent, 0, 0, NULL);
4618     ok(hwnd != 0, "Failed to create custom dialog window\n");
4619     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4620
4621     /*
4622     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4623     test_scroll_messages(hwnd);
4624     */
4625
4626     flush_sequence();
4627
4628     test_def_id = 1;
4629     SendMessage(hwnd, WM_NULL, 0, 0);
4630
4631     flush_sequence();
4632     after_end_dialog = 1;
4633     EndDialog( hwnd, 0 );
4634     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4635
4636     DestroyWindow(hwnd);
4637     after_end_dialog = 0;
4638     test_def_id = 0;
4639
4640     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4641                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4642     ok(hwnd != 0, "Failed to create custom dialog window\n");
4643     flush_sequence();
4644     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4645     ShowWindow(hwnd, SW_SHOW);
4646     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4647     DestroyWindow(hwnd);
4648
4649     flush_sequence();
4650     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4651     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4652
4653     DestroyWindow(hparent);
4654     flush_sequence();
4655
4656     /* Message sequence for SetMenu */
4657     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4658     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4659
4660     hmenu = CreateMenu();
4661     ok (hmenu != 0, "Failed to create menu\n");
4662     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4663     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4664                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4665     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4666     ok (SetMenu(hwnd, 0), "SetMenu\n");
4667     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4668     ok (SetMenu(hwnd, 0), "SetMenu\n");
4669     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4670     ShowWindow(hwnd, SW_SHOW);
4671     UpdateWindow( hwnd );
4672     flush_events();
4673     flush_sequence();
4674     ok (SetMenu(hwnd, 0), "SetMenu\n");
4675     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4676     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4677     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4678
4679     UpdateWindow( hwnd );
4680     flush_events();
4681     flush_sequence();
4682     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4683     flush_events();
4684     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4685
4686     DestroyWindow(hwnd);
4687     flush_sequence();
4688
4689     /* Message sequence for EnableWindow */
4690     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4691                               100, 100, 200, 200, 0, 0, 0, NULL);
4692     ok (hparent != 0, "Failed to create parent window\n");
4693     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4694                              0, 0, 10, 10, hparent, 0, 0, NULL);
4695     ok (hchild != 0, "Failed to create child window\n");
4696
4697     SetFocus(hchild);
4698     flush_events();
4699     flush_sequence();
4700
4701     EnableWindow(hparent, FALSE);
4702     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4703
4704     EnableWindow(hparent, TRUE);
4705     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4706
4707     flush_events();
4708     flush_sequence();
4709
4710     test_MsgWaitForMultipleObjects(hparent);
4711
4712     /* the following test causes an exception in user.exe under win9x */
4713     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4714     {
4715         DestroyWindow(hparent);
4716         flush_sequence();
4717         return;
4718     }
4719     PostMessageW( hparent, WM_USER+1, 0, 0 );
4720     /* PeekMessage(NULL) fails, but still removes the message */
4721     SetLastError(0xdeadbeef);
4722     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4723     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4724         GetLastError() == 0xdeadbeef, /* NT4 */
4725         "last error is %d\n", GetLastError() );
4726     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4727     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4728
4729     DestroyWindow(hchild);
4730     DestroyWindow(hparent);
4731     flush_sequence();
4732
4733     /* Message sequences for WM_SETICON */
4734     trace("testing WM_SETICON\n");
4735     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4736                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4737                            NULL, NULL, 0);
4738     ShowWindow(hwnd, SW_SHOW);
4739     UpdateWindow(hwnd);
4740     flush_events();
4741     flush_sequence();
4742     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4743     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4744
4745     ShowWindow(hwnd, SW_HIDE);
4746     flush_events();
4747     flush_sequence();
4748     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4749     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4750     DestroyWindow(hwnd);
4751     flush_sequence();
4752
4753     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4754                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4755                            NULL, NULL, 0);
4756     ShowWindow(hwnd, SW_SHOW);
4757     UpdateWindow(hwnd);
4758     flush_events();
4759     flush_sequence();
4760     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4761     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4762
4763     ShowWindow(hwnd, SW_HIDE);
4764     flush_events();
4765     flush_sequence();
4766     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4767     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4768
4769     flush_sequence();
4770     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4771     if (!res)
4772     {
4773         todo_wine win_skip( "Message 0x3b not supported\n" );
4774         goto done;
4775     }
4776     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4777     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4778     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4779     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4780     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4781     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4782     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4783     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4784
4785     flush_sequence();
4786     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4787     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4788     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4789     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4790     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4791     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4792
4793     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4794     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4795     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4796
4797     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4798     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4799     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4800
4801 done:
4802     DestroyWindow(hwnd);
4803     flush_sequence();
4804 }
4805
4806 static void test_setwindowpos(void)
4807 {
4808     HWND hwnd;
4809     RECT rc;
4810     LRESULT res;
4811     const INT winX = 100;
4812     const INT winY = 100;
4813     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4814
4815     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4816                            0, 0, winX, winY, 0,
4817                            NULL, NULL, 0);
4818
4819     GetWindowRect(hwnd, &rc);
4820     expect(sysX, rc.right);
4821     expect(winY, rc.bottom);
4822
4823     flush_events();
4824     flush_sequence();
4825     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4826     ok_sequence(WmZOrder, "Z-Order", TRUE);
4827     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4828
4829     GetWindowRect(hwnd, &rc);
4830     expect(sysX, rc.right);
4831     expect(winY, rc.bottom);
4832     DestroyWindow(hwnd);
4833 }
4834
4835 static void invisible_parent_tests(void)
4836 {
4837     HWND hparent, hchild;
4838
4839     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4840                               100, 100, 200, 200, 0, 0, 0, NULL);
4841     ok (hparent != 0, "Failed to create parent window\n");
4842     flush_sequence();
4843
4844     /* test showing child with hidden parent */
4845
4846     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4847                              0, 0, 10, 10, hparent, 0, 0, NULL);
4848     ok (hchild != 0, "Failed to create child window\n");
4849     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4850
4851     ShowWindow( hchild, SW_MINIMIZE );
4852     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4853     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4854     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4855
4856     /* repeat */
4857     flush_events();
4858     flush_sequence();
4859     ShowWindow( hchild, SW_MINIMIZE );
4860     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4861
4862     DestroyWindow(hchild);
4863     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4864                              0, 0, 10, 10, hparent, 0, 0, NULL);
4865     flush_sequence();
4866
4867     ShowWindow( hchild, SW_MAXIMIZE );
4868     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4869     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4870     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4871
4872     /* repeat */
4873     flush_events();
4874     flush_sequence();
4875     ShowWindow( hchild, SW_MAXIMIZE );
4876     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4877
4878     DestroyWindow(hchild);
4879     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4880                              0, 0, 10, 10, hparent, 0, 0, NULL);
4881     flush_sequence();
4882
4883     ShowWindow( hchild, SW_RESTORE );
4884     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4885     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4886     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4887
4888     DestroyWindow(hchild);
4889     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4890                              0, 0, 10, 10, hparent, 0, 0, NULL);
4891     flush_sequence();
4892
4893     ShowWindow( hchild, SW_SHOWMINIMIZED );
4894     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4895     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4896     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4897
4898     /* repeat */
4899     flush_events();
4900     flush_sequence();
4901     ShowWindow( hchild, SW_SHOWMINIMIZED );
4902     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4903
4904     DestroyWindow(hchild);
4905     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4906                              0, 0, 10, 10, hparent, 0, 0, NULL);
4907     flush_sequence();
4908
4909     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4910     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4911     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4912     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4913     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
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_SHOWMINNOACTIVE );
4921     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) 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_SHOWMINNOACTIVE );
4929     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) 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     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4937     ShowWindow( hchild, SW_FORCEMINIMIZE );
4938     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4939 todo_wine {
4940     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4941 }
4942     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4943
4944     DestroyWindow(hchild);
4945     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4946                              0, 0, 10, 10, hparent, 0, 0, NULL);
4947     flush_sequence();
4948
4949     ShowWindow( hchild, SW_SHOWNA );
4950     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4951     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4952     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4953
4954     /* repeat */
4955     flush_events();
4956     flush_sequence();
4957     ShowWindow( hchild, SW_SHOWNA );
4958     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4959
4960     DestroyWindow(hchild);
4961     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4962                              0, 0, 10, 10, hparent, 0, 0, NULL);
4963     flush_sequence();
4964
4965     ShowWindow( hchild, SW_SHOW );
4966     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4967     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4968     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4969
4970     /* repeat */
4971     flush_events();
4972     flush_sequence();
4973     ShowWindow( hchild, SW_SHOW );
4974     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4975
4976     ShowWindow( hchild, SW_HIDE );
4977     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4978     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4979     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4980
4981     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4982     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4983     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4984     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4985
4986     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4987     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4988     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4989     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4990
4991     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4992     flush_sequence();
4993     DestroyWindow(hchild);
4994     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4995
4996     DestroyWindow(hparent);
4997     flush_sequence();
4998 }
4999
5000 /****************** button message test *************************/
5001 static const struct message WmSetFocusButtonSeq[] =
5002 {
5003     { HCBT_SETFOCUS, hook },
5004     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5005     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5006     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5007     { WM_SETFOCUS, sent|wparam, 0 },
5008     { WM_CTLCOLORBTN, sent|defwinproc },
5009     { 0 }
5010 };
5011 static const struct message WmKillFocusButtonSeq[] =
5012 {
5013     { HCBT_SETFOCUS, hook },
5014     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5015     { WM_KILLFOCUS, sent|wparam, 0 },
5016     { WM_CTLCOLORBTN, sent|defwinproc },
5017     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5018     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5019     { 0 }
5020 };
5021 static const struct message WmSetFocusStaticSeq[] =
5022 {
5023     { HCBT_SETFOCUS, hook },
5024     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5025     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5026     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5027     { WM_SETFOCUS, sent|wparam, 0 },
5028     { WM_CTLCOLORSTATIC, sent|defwinproc },
5029     { 0 }
5030 };
5031 static const struct message WmKillFocusStaticSeq[] =
5032 {
5033     { HCBT_SETFOCUS, hook },
5034     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5035     { WM_KILLFOCUS, sent|wparam, 0 },
5036     { WM_CTLCOLORSTATIC, sent|defwinproc },
5037     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5038     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5039     { 0 }
5040 };
5041 static const struct message WmLButtonDownSeq[] =
5042 {
5043     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5044     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5045     { HCBT_SETFOCUS, hook },
5046     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5047     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5048     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5049     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5050     { WM_CTLCOLORBTN, sent|defwinproc },
5051     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5052     { WM_CTLCOLORBTN, sent|defwinproc },
5053     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5054     { 0 }
5055 };
5056 static const struct message WmLButtonUpSeq[] =
5057 {
5058     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5059     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5060     { WM_CTLCOLORBTN, sent|defwinproc },
5061     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5062     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5063     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5064     { 0 }
5065 };
5066 static const struct message WmSetFontButtonSeq[] =
5067 {
5068     { WM_SETFONT, sent },
5069     { WM_PAINT, sent },
5070     { WM_ERASEBKGND, sent|defwinproc|optional },
5071     { WM_CTLCOLORBTN, sent|defwinproc },
5072     { 0 }
5073 };
5074
5075 static WNDPROC old_button_proc;
5076
5077 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5078 {
5079     static long defwndproc_counter = 0;
5080     LRESULT ret;
5081     struct recvd_message msg;
5082
5083     switch (message)
5084     {
5085     case WM_GETICON:
5086     case WM_GETOBJECT:
5087         return 0;  /* ignore them */
5088     case WM_SYNCPAINT:
5089         break;
5090     case BM_SETSTATE:
5091         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5092         /* fall through */
5093     default:
5094         msg.hwnd = hwnd;
5095         msg.message = message;
5096         msg.flags = sent|wparam|lparam;
5097         if (defwndproc_counter) msg.flags |= defwinproc;
5098         msg.wParam = wParam;
5099         msg.lParam = lParam;
5100         msg.descr = "button";
5101         add_message(&msg);
5102     }
5103
5104     defwndproc_counter++;
5105     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5106     defwndproc_counter--;
5107
5108     return ret;
5109 }
5110
5111 static void subclass_button(void)
5112 {
5113     WNDCLASSA cls;
5114
5115     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5116
5117     old_button_proc = cls.lpfnWndProc;
5118
5119     cls.hInstance = GetModuleHandle(0);
5120     cls.lpfnWndProc = button_hook_proc;
5121     cls.lpszClassName = "my_button_class";
5122     UnregisterClass(cls.lpszClassName, cls.hInstance);
5123     if (!RegisterClassA(&cls)) assert(0);
5124 }
5125
5126 static void test_button_messages(void)
5127 {
5128     static const struct
5129     {
5130         DWORD style;
5131         DWORD dlg_code;
5132         const struct message *setfocus;
5133         const struct message *killfocus;
5134     } button[] = {
5135         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5136           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5137         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5138           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5139         { BS_CHECKBOX, DLGC_BUTTON,
5140           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5141         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5142           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5143         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5144           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5145         { BS_3STATE, DLGC_BUTTON,
5146           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5147         { BS_AUTO3STATE, DLGC_BUTTON,
5148           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5149         { BS_GROUPBOX, DLGC_STATIC,
5150           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5151         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5152           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5153         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5154           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5155         { BS_OWNERDRAW, DLGC_BUTTON,
5156           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5157     };
5158     unsigned int i;
5159     HWND hwnd;
5160     DWORD dlg_code;
5161     HFONT zfont;
5162
5163     subclass_button();
5164
5165     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5166     {
5167         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5168                                0, 0, 50, 14, 0, 0, 0, NULL);
5169         ok(hwnd != 0, "Failed to create button window\n");
5170
5171         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5172         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5173
5174         ShowWindow(hwnd, SW_SHOW);
5175         UpdateWindow(hwnd);
5176         SetFocus(0);
5177         flush_sequence();
5178
5179         trace("button style %08x\n", button[i].style);
5180         SetFocus(hwnd);
5181         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5182
5183         SetFocus(0);
5184         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5185
5186         DestroyWindow(hwnd);
5187     }
5188
5189     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5190                            0, 0, 50, 14, 0, 0, 0, NULL);
5191     ok(hwnd != 0, "Failed to create button window\n");
5192
5193     SetForegroundWindow(hwnd);
5194     SetFocus(0);
5195     flush_events();
5196     flush_sequence();
5197
5198     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5199     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5200
5201     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5202     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5203
5204     flush_sequence();
5205     zfont = GetStockObject(SYSTEM_FONT);
5206     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5207     UpdateWindow(hwnd);
5208     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5209
5210     DestroyWindow(hwnd);
5211 }
5212
5213 /****************** static message test *************************/
5214 static const struct message WmSetFontStaticSeq[] =
5215 {
5216     { WM_SETFONT, sent },
5217     { WM_PAINT, sent|defwinproc|optional },
5218     { WM_ERASEBKGND, sent|defwinproc|optional },
5219     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5220     { 0 }
5221 };
5222
5223 static WNDPROC old_static_proc;
5224
5225 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5226 {
5227     static long defwndproc_counter = 0;
5228     LRESULT ret;
5229     struct recvd_message msg;
5230
5231     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5232
5233     msg.hwnd = hwnd;
5234     msg.message = message;
5235     msg.flags = sent|wparam|lparam;
5236     if (defwndproc_counter) msg.flags |= defwinproc;
5237     msg.wParam = wParam;
5238     msg.lParam = lParam;
5239     msg.descr = "static";
5240     add_message(&msg);
5241
5242     defwndproc_counter++;
5243     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5244     defwndproc_counter--;
5245
5246     return ret;
5247 }
5248
5249 static void subclass_static(void)
5250 {
5251     WNDCLASSA cls;
5252
5253     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5254
5255     old_static_proc = cls.lpfnWndProc;
5256
5257     cls.hInstance = GetModuleHandle(0);
5258     cls.lpfnWndProc = static_hook_proc;
5259     cls.lpszClassName = "my_static_class";
5260     UnregisterClass(cls.lpszClassName, cls.hInstance);
5261     if (!RegisterClassA(&cls)) assert(0);
5262 }
5263
5264 static void test_static_messages(void)
5265 {
5266     /* FIXME: make as comprehensive as the button message test */
5267     static const struct
5268     {
5269         DWORD style;
5270         DWORD dlg_code;
5271         const struct message *setfont;
5272     } static_ctrl[] = {
5273         { SS_LEFT, DLGC_STATIC,
5274           WmSetFontStaticSeq }
5275     };
5276     unsigned int i;
5277     HWND hwnd;
5278     DWORD dlg_code;
5279
5280     subclass_static();
5281
5282     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5283     {
5284         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5285                                0, 0, 50, 14, 0, 0, 0, NULL);
5286         ok(hwnd != 0, "Failed to create static window\n");
5287
5288         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5289         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5290
5291         ShowWindow(hwnd, SW_SHOW);
5292         UpdateWindow(hwnd);
5293         SetFocus(0);
5294         flush_sequence();
5295
5296         trace("static style %08x\n", static_ctrl[i].style);
5297         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5298         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5299
5300         DestroyWindow(hwnd);
5301     }
5302 }
5303
5304 /****************** ComboBox message test *************************/
5305 #define ID_COMBOBOX 0x000f
5306
5307 static const struct message WmKeyDownComboSeq[] =
5308 {
5309     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5310     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5311     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5312     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5313     { WM_CTLCOLOREDIT, sent|parent },
5314     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5315     { 0 }
5316 };
5317
5318 static WNDPROC old_combobox_proc;
5319
5320 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5321 {
5322     static long defwndproc_counter = 0;
5323     LRESULT ret;
5324     struct recvd_message msg;
5325
5326     /* do not log painting messages */
5327     if (message != WM_PAINT &&
5328         message != WM_NCPAINT &&
5329         message != WM_SYNCPAINT &&
5330         message != WM_ERASEBKGND &&
5331         message != WM_NCHITTEST &&
5332         message != WM_GETTEXT &&
5333         message != WM_GETICON &&
5334         message != WM_GETOBJECT &&
5335         message != WM_DEVICECHANGE)
5336     {
5337         msg.hwnd = hwnd;
5338         msg.message = message;
5339         msg.flags = sent|wparam|lparam;
5340         if (defwndproc_counter) msg.flags |= defwinproc;
5341         msg.wParam = wParam;
5342         msg.lParam = lParam;
5343         msg.descr = "combo";
5344         add_message(&msg);
5345     }
5346
5347     defwndproc_counter++;
5348     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5349     defwndproc_counter--;
5350
5351     return ret;
5352 }
5353
5354 static void subclass_combobox(void)
5355 {
5356     WNDCLASSA cls;
5357
5358     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5359
5360     old_combobox_proc = cls.lpfnWndProc;
5361
5362     cls.hInstance = GetModuleHandle(0);
5363     cls.lpfnWndProc = combobox_hook_proc;
5364     cls.lpszClassName = "my_combobox_class";
5365     UnregisterClass(cls.lpszClassName, cls.hInstance);
5366     if (!RegisterClassA(&cls)) assert(0);
5367 }
5368
5369 static void test_combobox_messages(void)
5370 {
5371     HWND parent, combo;
5372     LRESULT ret;
5373
5374     subclass_combobox();
5375
5376     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5377                              100, 100, 200, 200, 0, 0, 0, NULL);
5378     ok(parent != 0, "Failed to create parent window\n");
5379     flush_sequence();
5380
5381     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5382                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5383     ok(combo != 0, "Failed to create combobox window\n");
5384
5385     UpdateWindow(combo);
5386
5387     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5388     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5389
5390     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5391     ok(ret == 0, "expected 0, got %ld\n", ret);
5392     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5393     ok(ret == 1, "expected 1, got %ld\n", ret);
5394     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5395     ok(ret == 2, "expected 2, got %ld\n", ret);
5396
5397     SendMessage(combo, CB_SETCURSEL, 0, 0);
5398     SetFocus(combo);
5399     flush_sequence();
5400
5401     log_all_parent_messages++;
5402     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5403     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5404     log_all_parent_messages--;
5405     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5406
5407     DestroyWindow(combo);
5408     DestroyWindow(parent);
5409 }
5410
5411 /****************** WM_IME_KEYDOWN message test *******************/
5412
5413 static const struct message WmImeKeydownMsgSeq_0[] =
5414 {
5415     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5416     { WM_CHAR, wparam, 'A' },
5417     { 0 }
5418 };
5419
5420 static const struct message WmImeKeydownMsgSeq_1[] =
5421 {
5422     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5423     { WM_CHAR,    optional|wparam, VK_RETURN },
5424     { 0 }
5425 };
5426
5427 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5428 {
5429     struct recvd_message msg;
5430
5431     msg.hwnd = hwnd;
5432     msg.message = message;
5433     msg.flags = wparam|lparam;
5434     msg.wParam = wParam;
5435     msg.lParam = lParam;
5436     msg.descr = "wmime_keydown";
5437     add_message(&msg);
5438
5439     return DefWindowProcA(hwnd, message, wParam, lParam);
5440 }
5441
5442 static void register_wmime_keydown_class(void)
5443 {
5444     WNDCLASSA cls;
5445
5446     ZeroMemory(&cls, sizeof(WNDCLASSA));
5447     cls.lpfnWndProc = wmime_keydown_procA;
5448     cls.hInstance = GetModuleHandleA(0);
5449     cls.lpszClassName = "wmime_keydown_class";
5450     if (!RegisterClassA(&cls)) assert(0);
5451 }
5452
5453 static void test_wmime_keydown_message(void)
5454 {
5455     HWND hwnd;
5456     MSG msg;
5457
5458     trace("Message sequences by WM_IME_KEYDOWN\n");
5459
5460     register_wmime_keydown_class();
5461     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5462                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5463                            NULL, NULL, 0);
5464     flush_events();
5465     flush_sequence();
5466
5467     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5468     SendMessage(hwnd, WM_CHAR, 'A', 1);
5469     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5470
5471     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5472     {
5473         TranslateMessage(&msg);
5474         DispatchMessage(&msg);
5475     }
5476     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5477
5478     DestroyWindow(hwnd);
5479 }
5480
5481 /************* painting message test ********************/
5482
5483 void dump_region(HRGN hrgn)
5484 {
5485     DWORD i, size;
5486     RGNDATA *data = NULL;
5487     RECT *rect;
5488
5489     if (!hrgn)
5490     {
5491         printf( "null region\n" );
5492         return;
5493     }
5494     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5495     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5496     GetRegionData( hrgn, size, data );
5497     printf("%d rects:", data->rdh.nCount );
5498     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5499         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5500     printf("\n");
5501     HeapFree( GetProcessHeap(), 0, data );
5502 }
5503
5504 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5505 {
5506     INT ret;
5507     RECT r1, r2;
5508     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5509     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5510
5511     ret = GetUpdateRgn( hwnd, update, FALSE );
5512     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5513     if (ret == NULLREGION)
5514     {
5515         ok( !hrgn, "Update region shouldn't be empty\n" );
5516     }
5517     else
5518     {
5519         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5520         {
5521             ok( 0, "Regions are different\n" );
5522             if (winetest_debug > 0)
5523             {
5524                 printf( "Update region: " );
5525                 dump_region( update );
5526                 printf( "Wanted region: " );
5527                 dump_region( hrgn );
5528             }
5529         }
5530     }
5531     GetRgnBox( update, &r1 );
5532     GetUpdateRect( hwnd, &r2, FALSE );
5533     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5534         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5535         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5536
5537     DeleteObject( tmp );
5538     DeleteObject( update );
5539 }
5540
5541 static const struct message WmInvalidateRgn[] = {
5542     { WM_NCPAINT, sent },
5543     { WM_GETTEXT, sent|defwinproc|optional },
5544     { 0 }
5545 };
5546
5547 static const struct message WmGetUpdateRect[] = {
5548     { WM_NCPAINT, sent },
5549     { WM_GETTEXT, sent|defwinproc|optional },
5550     { WM_PAINT, sent },
5551     { 0 }
5552 };
5553
5554 static const struct message WmInvalidateFull[] = {
5555     { WM_NCPAINT, sent|wparam, 1 },
5556     { WM_GETTEXT, sent|defwinproc|optional },
5557     { 0 }
5558 };
5559
5560 static const struct message WmInvalidateErase[] = {
5561     { WM_NCPAINT, sent|wparam, 1 },
5562     { WM_GETTEXT, sent|defwinproc|optional },
5563     { WM_ERASEBKGND, sent },
5564     { 0 }
5565 };
5566
5567 static const struct message WmInvalidatePaint[] = {
5568     { WM_PAINT, sent },
5569     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5570     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5571     { 0 }
5572 };
5573
5574 static const struct message WmInvalidateErasePaint[] = {
5575     { WM_PAINT, sent },
5576     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5577     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5578     { WM_ERASEBKGND, sent|beginpaint },
5579     { 0 }
5580 };
5581
5582 static const struct message WmInvalidateErasePaint2[] = {
5583     { WM_PAINT, sent },
5584     { WM_NCPAINT, sent|beginpaint },
5585     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5586     { WM_ERASEBKGND, sent|beginpaint|optional },
5587     { 0 }
5588 };
5589
5590 static const struct message WmErase[] = {
5591     { WM_ERASEBKGND, sent },
5592     { 0 }
5593 };
5594
5595 static const struct message WmPaint[] = {
5596     { WM_PAINT, sent },
5597     { 0 }
5598 };
5599
5600 static const struct message WmParentOnlyPaint[] = {
5601     { WM_PAINT, sent|parent },
5602     { 0 }
5603 };
5604
5605 static const struct message WmInvalidateParent[] = {
5606     { WM_NCPAINT, sent|parent },
5607     { WM_GETTEXT, sent|defwinproc|parent|optional },
5608     { WM_ERASEBKGND, sent|parent },
5609     { 0 }
5610 };
5611
5612 static const struct message WmInvalidateParentChild[] = {
5613     { WM_NCPAINT, sent|parent },
5614     { WM_GETTEXT, sent|defwinproc|parent|optional },
5615     { WM_ERASEBKGND, sent|parent },
5616     { WM_NCPAINT, sent },
5617     { WM_GETTEXT, sent|defwinproc|optional },
5618     { WM_ERASEBKGND, sent },
5619     { 0 }
5620 };
5621
5622 static const struct message WmInvalidateParentChild2[] = {
5623     { WM_ERASEBKGND, sent|parent },
5624     { WM_NCPAINT, sent },
5625     { WM_GETTEXT, sent|defwinproc|optional },
5626     { WM_ERASEBKGND, sent },
5627     { 0 }
5628 };
5629
5630 static const struct message WmParentPaint[] = {
5631     { WM_PAINT, sent|parent },
5632     { WM_PAINT, sent },
5633     { 0 }
5634 };
5635
5636 static const struct message WmParentPaintNc[] = {
5637     { WM_PAINT, sent|parent },
5638     { WM_PAINT, sent },
5639     { WM_NCPAINT, sent|beginpaint },
5640     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5641     { WM_ERASEBKGND, sent|beginpaint|optional },
5642     { 0 }
5643 };
5644
5645 static const struct message WmChildPaintNc[] = {
5646     { WM_PAINT, sent },
5647     { WM_NCPAINT, sent|beginpaint },
5648     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5649     { WM_ERASEBKGND, sent|beginpaint },
5650     { 0 }
5651 };
5652
5653 static const struct message WmParentErasePaint[] = {
5654     { WM_PAINT, sent|parent },
5655     { WM_NCPAINT, sent|parent|beginpaint },
5656     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5657     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5658     { WM_PAINT, sent },
5659     { WM_NCPAINT, sent|beginpaint },
5660     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5661     { WM_ERASEBKGND, sent|beginpaint },
5662     { 0 }
5663 };
5664
5665 static const struct message WmParentOnlyNcPaint[] = {
5666     { WM_PAINT, sent|parent },
5667     { WM_NCPAINT, sent|parent|beginpaint },
5668     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5669     { 0 }
5670 };
5671
5672 static const struct message WmSetParentStyle[] = {
5673     { WM_STYLECHANGING, sent|parent },
5674     { WM_STYLECHANGED, sent|parent },
5675     { 0 }
5676 };
5677
5678 static void test_paint_messages(void)
5679 {
5680     BOOL ret;
5681     RECT rect;
5682     POINT pt;
5683     MSG msg;
5684     HWND hparent, hchild;
5685     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5686     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5687     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5688                                 100, 100, 200, 200, 0, 0, 0, NULL);
5689     ok (hwnd != 0, "Failed to create overlapped window\n");
5690
5691     ShowWindow( hwnd, SW_SHOW );
5692     UpdateWindow( hwnd );
5693     flush_events();
5694     flush_sequence();
5695
5696     check_update_rgn( hwnd, 0 );
5697     SetRectRgn( hrgn, 10, 10, 20, 20 );
5698     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5699     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5700     check_update_rgn( hwnd, hrgn );
5701     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5702     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5703     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5704     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5705     check_update_rgn( hwnd, hrgn );
5706     /* validate everything */
5707     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5708     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5709     check_update_rgn( hwnd, 0 );
5710
5711     /* test empty region */
5712     SetRectRgn( hrgn, 10, 10, 10, 15 );
5713     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5714     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5715     check_update_rgn( hwnd, 0 );
5716     /* test empty rect */
5717     SetRect( &rect, 10, 10, 10, 15 );
5718     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5719     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5720     check_update_rgn( hwnd, 0 );
5721
5722     /* flush pending messages */
5723     flush_events();
5724     flush_sequence();
5725
5726     GetClientRect( hwnd, &rect );
5727     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5728     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5729      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5730      */
5731     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5732     SetRectEmpty( &rect );
5733     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5734     check_update_rgn( hwnd, hrgn );
5735     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5736     flush_events();
5737     ok_sequence( WmPaint, "Paint", FALSE );
5738     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5739     check_update_rgn( hwnd, 0 );
5740
5741     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5742      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5743      */
5744     trace("testing ValidateRect(0, NULL)\n");
5745     SetRectEmpty( &rect );
5746     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5747     check_update_rgn( hwnd, hrgn );
5748     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5749     flush_events();
5750     ok_sequence( WmPaint, "Paint", FALSE );
5751     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5752     check_update_rgn( hwnd, 0 );
5753
5754     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5755     SetLastError(0xdeadbeef);
5756     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5757     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5758        "wrong error code %d\n", GetLastError());
5759     check_update_rgn( hwnd, 0 );
5760     flush_events();
5761     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5762
5763     trace("testing ValidateRgn(0, NULL)\n");
5764     SetLastError(0xdeadbeef);
5765     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5766     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5767        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5768        "wrong error code %d\n", GetLastError());
5769     check_update_rgn( hwnd, 0 );
5770     flush_events();
5771     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5772
5773     /* now with frame */
5774     SetRectRgn( hrgn, -5, -5, 20, 20 );
5775
5776     /* flush pending messages */
5777     flush_events();
5778     flush_sequence();
5779     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5780     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5781
5782     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5783     check_update_rgn( hwnd, hrgn );
5784
5785     flush_sequence();
5786     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5787     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5788
5789     flush_sequence();
5790     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5791     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5792
5793     GetClientRect( hwnd, &rect );
5794     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5795     check_update_rgn( hwnd, hrgn );
5796
5797     flush_sequence();
5798     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5799     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5800
5801     flush_sequence();
5802     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5803     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5804     check_update_rgn( hwnd, 0 );
5805
5806     flush_sequence();
5807     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5808     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5809     check_update_rgn( hwnd, 0 );
5810
5811     flush_sequence();
5812     SetRectRgn( hrgn, 0, 0, 100, 100 );
5813     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5814     SetRectRgn( hrgn, 0, 0, 50, 100 );
5815     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5816     SetRectRgn( hrgn, 50, 0, 100, 100 );
5817     check_update_rgn( hwnd, hrgn );
5818     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5819     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5820     check_update_rgn( hwnd, 0 );
5821
5822     flush_sequence();
5823     SetRectRgn( hrgn, 0, 0, 100, 100 );
5824     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5825     SetRectRgn( hrgn, 0, 0, 100, 50 );
5826     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5827     ok_sequence( WmErase, "Erase", FALSE );
5828     SetRectRgn( hrgn, 0, 50, 100, 100 );
5829     check_update_rgn( hwnd, hrgn );
5830
5831     flush_sequence();
5832     SetRectRgn( hrgn, 0, 0, 100, 100 );
5833     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5834     SetRectRgn( hrgn, 0, 0, 50, 50 );
5835     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5836     ok_sequence( WmPaint, "Paint", FALSE );
5837
5838     flush_sequence();
5839     SetRectRgn( hrgn, -4, -4, -2, -2 );
5840     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5841     SetRectRgn( hrgn, -200, -200, -198, -198 );
5842     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5843     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5844
5845     flush_sequence();
5846     SetRectRgn( hrgn, -4, -4, -2, -2 );
5847     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5848     SetRectRgn( hrgn, -4, -4, -3, -3 );
5849     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5850     SetRectRgn( hrgn, 0, 0, 1, 1 );
5851     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5852     ok_sequence( WmPaint, "Paint", FALSE );
5853
5854     flush_sequence();
5855     SetRectRgn( hrgn, -4, -4, -1, -1 );
5856     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5857     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5858     /* make sure no WM_PAINT was generated */
5859     flush_events();
5860     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5861
5862     flush_sequence();
5863     SetRectRgn( hrgn, -4, -4, -1, -1 );
5864     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5865     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5866     {
5867         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5868         {
5869             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5870             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5871             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5872             ret = GetUpdateRect( hwnd, &rect, FALSE );
5873             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5874             /* this will send WM_NCPAINT and validate the non client area */
5875             ret = GetUpdateRect( hwnd, &rect, TRUE );
5876             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5877         }
5878         DispatchMessage( &msg );
5879     }
5880     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5881
5882     DestroyWindow( hwnd );
5883
5884     /* now test with a child window */
5885
5886     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5887                               100, 100, 200, 200, 0, 0, 0, NULL);
5888     ok (hparent != 0, "Failed to create parent window\n");
5889
5890     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5891                            10, 10, 100, 100, hparent, 0, 0, NULL);
5892     ok (hchild != 0, "Failed to create child window\n");
5893
5894     ShowWindow( hparent, SW_SHOW );
5895     UpdateWindow( hparent );
5896     UpdateWindow( hchild );
5897     flush_events();
5898     flush_sequence();
5899     log_all_parent_messages++;
5900
5901     SetRect( &rect, 0, 0, 50, 50 );
5902     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5903     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5904     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5905
5906     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5907     pt.x = pt.y = 0;
5908     MapWindowPoints( hchild, hparent, &pt, 1 );
5909     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5910     check_update_rgn( hchild, hrgn );
5911     SetRectRgn( hrgn, 0, 0, 50, 50 );
5912     check_update_rgn( hparent, hrgn );
5913     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5914     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5915     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5916     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5917
5918     flush_events();
5919     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5920
5921     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5922     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5923     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5924     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5925     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5926
5927     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5928     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5929     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5930
5931     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5932     flush_sequence();
5933     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5934     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5935     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5936
5937     /* flush all paint messages */
5938     flush_events();
5939     flush_sequence();
5940
5941     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5942     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5943     SetRectRgn( hrgn, 0, 0, 50, 50 );
5944     check_update_rgn( hparent, hrgn );
5945     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5946     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5947     SetRectRgn( hrgn, 0, 0, 50, 50 );
5948     check_update_rgn( hparent, hrgn );
5949
5950     /* flush all paint messages */
5951     flush_events();
5952     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5953     flush_sequence();
5954
5955     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5956     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5957     SetRectRgn( hrgn, 0, 0, 50, 50 );
5958     check_update_rgn( hparent, hrgn );
5959     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5960     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5961     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5962     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5963     check_update_rgn( hparent, hrgn );
5964     /* flush all paint messages */
5965     flush_events();
5966     flush_sequence();
5967
5968     /* same as above but parent gets completely validated */
5969     SetRect( &rect, 20, 20, 30, 30 );
5970     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5971     SetRectRgn( hrgn, 20, 20, 30, 30 );
5972     check_update_rgn( hparent, hrgn );
5973     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5974     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5975     check_update_rgn( hparent, 0 );  /* no update region */
5976     flush_events();
5977     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5978
5979     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5980     flush_sequence();
5981     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5982     SetRectRgn( hrgn, 20, 20, 30, 30 );
5983     check_update_rgn( hparent, hrgn );
5984     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5985     SetRectRgn( hrgn, 20, 20, 30, 30 );
5986     check_update_rgn( hparent, hrgn );
5987
5988     /* same as above but normal WM_PAINT doesn't validate parent */
5989     flush_sequence();
5990     SetRect( &rect, 20, 20, 30, 30 );
5991     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5992     SetRectRgn( hrgn, 20, 20, 30, 30 );
5993     check_update_rgn( hparent, hrgn );
5994     /* no WM_PAINT in child while parent still pending */
5995     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5996     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5997     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5998     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5999
6000     flush_sequence();
6001     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6002     /* no WM_PAINT in child while parent still pending */
6003     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6004     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6005     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6006     /* now that parent is valid child should get WM_PAINT */
6007     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6008     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6009     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6010     ok_sequence( WmEmptySeq, "No other message", FALSE );
6011
6012     /* same thing with WS_CLIPCHILDREN in parent */
6013     flush_sequence();
6014     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6015     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6016     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6017     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6018     ok_sequence( WmEmptySeq, "No message", FALSE );
6019     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6020     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6021
6022     flush_sequence();
6023     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6024     SetRectRgn( hrgn, 20, 20, 30, 30 );
6025     check_update_rgn( hparent, hrgn );
6026     /* no WM_PAINT in child while parent still pending */
6027     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6028     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6029     /* WM_PAINT in parent first */
6030     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6031     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6032
6033     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6034     flush_sequence();
6035     SetRect( &rect, 0, 0, 30, 30 );
6036     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6037     SetRectRgn( hrgn, 0, 0, 30, 30 );
6038     check_update_rgn( hparent, hrgn );
6039     flush_events();
6040     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6041
6042     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6043     flush_sequence();
6044     SetRect( &rect, -10, 0, 30, 30 );
6045     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6046     SetRect( &rect, 0, 0, 20, 20 );
6047     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6048     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6049     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6050
6051     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6052     flush_sequence();
6053     SetRect( &rect, -10, 0, 30, 30 );
6054     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6055     SetRect( &rect, 0, 0, 100, 100 );
6056     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6057     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6058     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6059     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6060     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6061
6062     /* test RDW_INTERNALPAINT behavior */
6063
6064     flush_sequence();
6065     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6066     flush_events();
6067     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6068
6069     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6070     flush_events();
6071     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6072
6073     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6074     flush_events();
6075     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6076
6077     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6078     UpdateWindow( hparent );
6079     flush_events();
6080     flush_sequence();
6081     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6082     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6083     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6084                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6085     flush_events();
6086     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6087
6088     UpdateWindow( hparent );
6089     flush_events();
6090     flush_sequence();
6091     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6092     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6093     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6094                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6095     flush_events();
6096     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6097
6098     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6099     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6100     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6101     flush_events();
6102     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6103
6104     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6105     UpdateWindow( hparent );
6106     flush_events();
6107     flush_sequence();
6108     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6109     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6110     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6111                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6112     flush_events();
6113     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6114
6115     UpdateWindow( hparent );
6116     flush_events();
6117     flush_sequence();
6118     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6119     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6120     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6121                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6122     flush_events();
6123     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6124
6125     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6126     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6127
6128     UpdateWindow( hparent );
6129     flush_events();
6130     flush_sequence();
6131     trace("testing SetWindowPos(-10000, -10000) on child\n");
6132     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6133     check_update_rgn( hchild, 0 );
6134     flush_events();
6135
6136 #if 0 /* this one doesn't pass under Wine yet */
6137     UpdateWindow( hparent );
6138     flush_events();
6139     flush_sequence();
6140     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6141     ShowWindow( hchild, SW_MINIMIZE );
6142     check_update_rgn( hchild, 0 );
6143     flush_events();
6144 #endif
6145
6146     UpdateWindow( hparent );
6147     flush_events();
6148     flush_sequence();
6149     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6150     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6151     check_update_rgn( hparent, 0 );
6152     flush_events();
6153
6154     log_all_parent_messages--;
6155     DestroyWindow( hparent );
6156     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6157
6158     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6159
6160     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6161                               100, 100, 200, 200, 0, 0, 0, NULL);
6162     ok (hparent != 0, "Failed to create parent window\n");
6163
6164     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6165                            10, 10, 100, 100, hparent, 0, 0, NULL);
6166     ok (hchild != 0, "Failed to create child window\n");
6167
6168     ShowWindow( hparent, SW_SHOW );
6169     UpdateWindow( hparent );
6170     UpdateWindow( hchild );
6171     flush_events();
6172     flush_sequence();
6173
6174     /* moving child outside of parent boundaries changes update region */
6175     SetRect( &rect, 0, 0, 40, 40 );
6176     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6177     SetRectRgn( hrgn, 0, 0, 40, 40 );
6178     check_update_rgn( hchild, hrgn );
6179     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6180     SetRectRgn( hrgn, 10, 0, 40, 40 );
6181     check_update_rgn( hchild, hrgn );
6182     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6183     SetRectRgn( hrgn, 10, 10, 40, 40 );
6184     check_update_rgn( hchild, hrgn );
6185
6186     /* moving parent off-screen does too */
6187     SetRect( &rect, 0, 0, 100, 100 );
6188     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6189     SetRectRgn( hrgn, 0, 0, 100, 100 );
6190     check_update_rgn( hparent, hrgn );
6191     SetRectRgn( hrgn, 10, 10, 40, 40 );
6192     check_update_rgn( hchild, hrgn );
6193     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6194     SetRectRgn( hrgn, 20, 20, 100, 100 );
6195     check_update_rgn( hparent, hrgn );
6196     SetRectRgn( hrgn, 30, 30, 40, 40 );
6197     check_update_rgn( hchild, hrgn );
6198
6199     /* invalidated region is cropped by the parent rects */
6200     SetRect( &rect, 0, 0, 50, 50 );
6201     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6202     SetRectRgn( hrgn, 30, 30, 50, 50 );
6203     check_update_rgn( hchild, hrgn );
6204
6205     DestroyWindow( hparent );
6206     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6207     flush_sequence();
6208
6209     DeleteObject( hrgn );
6210     DeleteObject( hrgn2 );
6211 }
6212
6213 struct wnd_event
6214 {
6215     HWND hwnd;
6216     HANDLE event;
6217 };
6218
6219 static DWORD WINAPI thread_proc(void *param)
6220 {
6221     MSG msg;
6222     struct wnd_event *wnd_event = (struct wnd_event *)param;
6223
6224     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6225                                       100, 100, 200, 200, 0, 0, 0, NULL);
6226     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6227
6228     SetEvent(wnd_event->event);
6229
6230     while (GetMessage(&msg, 0, 0, 0))
6231     {
6232         TranslateMessage(&msg);
6233         DispatchMessage(&msg);
6234     }
6235
6236     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6237
6238     return 0;
6239 }
6240
6241 static void test_interthread_messages(void)
6242 {
6243     HANDLE hThread;
6244     DWORD tid;
6245     WNDPROC proc;
6246     MSG msg;
6247     char buf[256];
6248     int len, expected_len;
6249     struct wnd_event wnd_event;
6250     BOOL ret;
6251
6252     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6253     if (!wnd_event.event)
6254     {
6255         trace("skipping interthread message test under win9x\n");
6256         return;
6257     }
6258
6259     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6260     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6261
6262     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6263
6264     CloseHandle(wnd_event.event);
6265
6266     SetLastError(0xdeadbeef);
6267     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6268     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6269        "wrong error code %d\n", GetLastError());
6270
6271     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6272     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6273
6274     expected_len = lstrlenA("window caption text");
6275     memset(buf, 0, sizeof(buf));
6276     SetLastError(0xdeadbeef);
6277     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6278     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6279     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6280
6281     msg.hwnd = wnd_event.hwnd;
6282     msg.message = WM_GETTEXT;
6283     msg.wParam = sizeof(buf);
6284     msg.lParam = (LPARAM)buf;
6285     memset(buf, 0, sizeof(buf));
6286     SetLastError(0xdeadbeef);
6287     len = DispatchMessageA(&msg);
6288     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6289        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6290
6291     /* the following test causes an exception in user.exe under win9x */
6292     msg.hwnd = wnd_event.hwnd;
6293     msg.message = WM_TIMER;
6294     msg.wParam = 0;
6295     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6296     SetLastError(0xdeadbeef);
6297     len = DispatchMessageA(&msg);
6298     ok(!len && GetLastError() == 0xdeadbeef,
6299        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6300
6301     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6302     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6303
6304     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6305     CloseHandle(hThread);
6306
6307     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6308 }
6309
6310
6311 static const struct message WmVkN[] = {
6312     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6313     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6314     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6315     { WM_CHAR, wparam|lparam, 'n', 1 },
6316     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6317     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6318     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6319     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6320     { 0 }
6321 };
6322 static const struct message WmShiftVkN[] = {
6323     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6324     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6325     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6326     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6327     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6328     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6329     { WM_CHAR, wparam|lparam, 'N', 1 },
6330     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6331     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6332     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6333     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6334     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6335     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6336     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6337     { 0 }
6338 };
6339 static const struct message WmCtrlVkN[] = {
6340     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6341     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6342     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6343     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6344     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6345     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6346     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6347     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6348     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6349     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6350     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6351     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6352     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6353     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6354     { 0 }
6355 };
6356 static const struct message WmCtrlVkN_2[] = {
6357     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6358     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6359     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6360     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6361     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6362     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6363     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6364     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6365     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6366     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6367     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6368     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6369     { 0 }
6370 };
6371 static const struct message WmAltVkN[] = {
6372     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6373     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6374     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6375     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6376     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6377     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6378     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6379     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6380     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6381     { HCBT_SYSCOMMAND, hook },
6382     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6383     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6384     { 0x00AE, sent|defwinproc|optional }, /* XP */
6385     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6386     { WM_INITMENU, sent|defwinproc },
6387     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6388     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6389     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6390     { WM_CAPTURECHANGED, sent|defwinproc },
6391     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6392     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6393     { WM_EXITMENULOOP, sent|defwinproc },
6394     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6395     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6396     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6397     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6398     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6399     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6400     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6401     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6402     { 0 }
6403 };
6404 static const struct message WmAltVkN_2[] = {
6405     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6406     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6407     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6408     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6409     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6410     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6411     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6412     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6413     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6414     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6415     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6416     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6417     { 0 }
6418 };
6419 static const struct message WmCtrlAltVkN[] = {
6420     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6421     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6422     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6423     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6424     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6425     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6426     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6427     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6428     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6429     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6430     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6431     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6432     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6433     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6434     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6435     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6436     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6437     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6438     { 0 }
6439 };
6440 static const struct message WmCtrlShiftVkN[] = {
6441     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6442     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6443     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6444     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6445     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6446     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6447     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6448     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6449     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6450     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6451     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6452     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6453     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6454     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6455     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6456     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6457     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6458     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6459     { 0 }
6460 };
6461 static const struct message WmCtrlAltShiftVkN[] = {
6462     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6463     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6464     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6465     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6466     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6467     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6468     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6469     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6470     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6471     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6472     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6473     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6474     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6475     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6476     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6477     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6478     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6479     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6480     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6481     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6482     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6483     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6484     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6485     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6486     { 0 }
6487 };
6488 static const struct message WmAltPressRelease[] = {
6489     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6490     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6491     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6492     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6493     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6494     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6495     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6496     { HCBT_SYSCOMMAND, hook },
6497     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6498     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6499     { WM_INITMENU, sent|defwinproc },
6500     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6501     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6502     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6503
6504     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6505
6506     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6507     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6508     { WM_CAPTURECHANGED, sent|defwinproc },
6509     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6510     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6511     { WM_EXITMENULOOP, sent|defwinproc },
6512     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6513     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6514     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6515     { 0 }
6516 };
6517 static const struct message WmAltMouseButton[] = {
6518     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6519     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6520     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6521     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6522     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6523     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6524     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6525     { WM_LBUTTONUP, wparam, 0, 0 },
6526     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6527     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6528     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6529     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6530     { 0 }
6531 };
6532 static const struct message WmF1Seq[] = {
6533     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6534     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6535     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6536     { WM_KEYF1, wparam|lparam, 0, 0 },
6537     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6538     { WM_HELP, sent|defwinproc },
6539     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6540     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6541     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6542     { 0 }
6543 };
6544 static const struct message WmVkAppsSeq[] = {
6545     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6546     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6547     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6548     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6549     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6550     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6551     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6552     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6553     { 0 }
6554 };
6555
6556 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6557 {
6558     MSG msg;
6559
6560     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6561     {
6562         struct recvd_message log_msg;
6563
6564         /* ignore some unwanted messages */
6565         if (msg.message == WM_MOUSEMOVE ||
6566             msg.message == WM_GETICON ||
6567             msg.message == WM_GETOBJECT ||
6568             msg.message == WM_TIMER ||
6569             msg.message == WM_DEVICECHANGE)
6570             continue;
6571
6572         log_msg.hwnd = msg.hwnd;
6573         log_msg.message = msg.message;
6574         log_msg.flags = wparam|lparam;
6575         log_msg.wParam = msg.wParam;
6576         log_msg.lParam = msg.lParam;
6577         log_msg.descr = "accel";
6578         add_message(&log_msg);
6579
6580         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6581         {
6582             TranslateMessage(&msg);
6583             DispatchMessage(&msg);
6584         }
6585     }
6586 }
6587
6588 static void test_accelerators(void)
6589 {
6590     RECT rc;
6591     SHORT state;
6592     HACCEL hAccel;
6593     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6594                                 100, 100, 200, 200, 0, 0, 0, NULL);
6595     BOOL ret;
6596
6597     assert(hwnd != 0);
6598     UpdateWindow(hwnd);
6599     flush_events();
6600     flush_sequence();
6601
6602     SetFocus(hwnd);
6603     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6604
6605     state = GetKeyState(VK_SHIFT);
6606     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6607     state = GetKeyState(VK_CAPITAL);
6608     ok(state == 0, "wrong CapsLock state %04x\n", state);
6609
6610     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6611     assert(hAccel != 0);
6612
6613     flush_events();
6614     pump_msg_loop(hwnd, 0);
6615     flush_sequence();
6616
6617     trace("testing VK_N press/release\n");
6618     flush_sequence();
6619     keybd_event('N', 0, 0, 0);
6620     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6621     pump_msg_loop(hwnd, hAccel);
6622     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6623
6624     trace("testing Shift+VK_N press/release\n");
6625     flush_sequence();
6626     keybd_event(VK_SHIFT, 0, 0, 0);
6627     keybd_event('N', 0, 0, 0);
6628     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6629     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6630     pump_msg_loop(hwnd, hAccel);
6631     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6632
6633     trace("testing Ctrl+VK_N press/release\n");
6634     flush_sequence();
6635     keybd_event(VK_CONTROL, 0, 0, 0);
6636     keybd_event('N', 0, 0, 0);
6637     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6638     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6639     pump_msg_loop(hwnd, hAccel);
6640     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6641
6642     trace("testing Alt+VK_N press/release\n");
6643     flush_sequence();
6644     keybd_event(VK_MENU, 0, 0, 0);
6645     keybd_event('N', 0, 0, 0);
6646     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6647     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6648     pump_msg_loop(hwnd, hAccel);
6649     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6650
6651     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6652     flush_sequence();
6653     keybd_event(VK_CONTROL, 0, 0, 0);
6654     keybd_event(VK_MENU, 0, 0, 0);
6655     keybd_event('N', 0, 0, 0);
6656     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6657     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6658     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6659     pump_msg_loop(hwnd, hAccel);
6660     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6661
6662     ret = DestroyAcceleratorTable(hAccel);
6663     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6664
6665     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6666     assert(hAccel != 0);
6667
6668     trace("testing VK_N press/release\n");
6669     flush_sequence();
6670     keybd_event('N', 0, 0, 0);
6671     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6672     pump_msg_loop(hwnd, hAccel);
6673     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6674
6675     trace("testing Shift+VK_N press/release\n");
6676     flush_sequence();
6677     keybd_event(VK_SHIFT, 0, 0, 0);
6678     keybd_event('N', 0, 0, 0);
6679     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6680     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6681     pump_msg_loop(hwnd, hAccel);
6682     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6683
6684     trace("testing Ctrl+VK_N press/release 2\n");
6685     flush_sequence();
6686     keybd_event(VK_CONTROL, 0, 0, 0);
6687     keybd_event('N', 0, 0, 0);
6688     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6689     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6690     pump_msg_loop(hwnd, hAccel);
6691     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6692
6693     trace("testing Alt+VK_N press/release 2\n");
6694     flush_sequence();
6695     keybd_event(VK_MENU, 0, 0, 0);
6696     keybd_event('N', 0, 0, 0);
6697     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6698     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6699     pump_msg_loop(hwnd, hAccel);
6700     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6701
6702     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6703     flush_sequence();
6704     keybd_event(VK_CONTROL, 0, 0, 0);
6705     keybd_event(VK_MENU, 0, 0, 0);
6706     keybd_event('N', 0, 0, 0);
6707     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6708     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6709     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6710     pump_msg_loop(hwnd, hAccel);
6711     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6712
6713     trace("testing Ctrl+Shift+VK_N press/release\n");
6714     flush_sequence();
6715     keybd_event(VK_CONTROL, 0, 0, 0);
6716     keybd_event(VK_SHIFT, 0, 0, 0);
6717     keybd_event('N', 0, 0, 0);
6718     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6719     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6720     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6721     pump_msg_loop(hwnd, hAccel);
6722     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6723
6724     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6725     flush_sequence();
6726     keybd_event(VK_CONTROL, 0, 0, 0);
6727     keybd_event(VK_MENU, 0, 0, 0);
6728     keybd_event(VK_SHIFT, 0, 0, 0);
6729     keybd_event('N', 0, 0, 0);
6730     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6731     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6732     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6733     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6734     pump_msg_loop(hwnd, hAccel);
6735     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6736
6737     ret = DestroyAcceleratorTable(hAccel);
6738     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6739
6740     trace("testing Alt press/release\n");
6741     flush_sequence();
6742     keybd_event(VK_MENU, 0, 0, 0);
6743     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6744     keybd_event(VK_MENU, 0, 0, 0);
6745     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6746     pump_msg_loop(hwnd, 0);
6747     /* this test doesn't pass in Wine for managed windows */
6748     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6749
6750     trace("testing Alt+MouseButton press/release\n");
6751     /* first, move mouse pointer inside of the window client area */
6752     GetClientRect(hwnd, &rc);
6753     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6754     rc.left += (rc.right - rc.left)/2;
6755     rc.top += (rc.bottom - rc.top)/2;
6756     SetCursorPos(rc.left, rc.top);
6757
6758     flush_events();
6759     flush_sequence();
6760     keybd_event(VK_MENU, 0, 0, 0);
6761     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6762     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6763     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6764     pump_msg_loop(hwnd, 0);
6765     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6766
6767     trace("testing VK_F1 press/release\n");
6768     keybd_event(VK_F1, 0, 0, 0);
6769     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6770     pump_msg_loop(hwnd, 0);
6771     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6772
6773     trace("testing VK_APPS press/release\n");
6774     keybd_event(VK_APPS, 0, 0, 0);
6775     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6776     pump_msg_loop(hwnd, 0);
6777     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6778
6779     DestroyWindow(hwnd);
6780 }
6781
6782 /************* window procedures ********************/
6783
6784 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6785                              WPARAM wParam, LPARAM lParam)
6786 {
6787     static long defwndproc_counter = 0;
6788     static long beginpaint_counter = 0;
6789     LRESULT ret;
6790     struct recvd_message msg;
6791
6792     /* ignore registered messages */
6793     if (message >= 0xc000) return 0;
6794
6795     switch (message)
6796     {
6797         case WM_ENABLE:
6798         {
6799             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6800             ok((BOOL)wParam == !(style & WS_DISABLED),
6801                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6802             break;
6803         }
6804
6805         case WM_CAPTURECHANGED:
6806             if (test_DestroyWindow_flag)
6807             {
6808                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6809                 if (style & WS_CHILD)
6810                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6811                 else if (style & WS_POPUP)
6812                     lParam = WND_POPUP_ID;
6813                 else
6814                     lParam = WND_PARENT_ID;
6815             }
6816             break;
6817
6818         case WM_NCDESTROY:
6819         {
6820             HWND capture;
6821
6822             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6823             capture = GetCapture();
6824             if (capture)
6825             {
6826                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6827                 trace("current capture %p, releasing...\n", capture);
6828                 ReleaseCapture();
6829             }
6830         }
6831         /* fall through */
6832         case WM_DESTROY:
6833             if (pGetAncestor)
6834                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6835             if (test_DestroyWindow_flag)
6836             {
6837                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6838                 if (style & WS_CHILD)
6839                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6840                 else if (style & WS_POPUP)
6841                     lParam = WND_POPUP_ID;
6842                 else
6843                     lParam = WND_PARENT_ID;
6844             }
6845             break;
6846
6847         /* test_accelerators() depends on this */
6848         case WM_NCHITTEST:
6849             return HTCLIENT;
6850
6851         /* ignore */
6852         case WM_MOUSEMOVE:
6853         case WM_MOUSEACTIVATE:
6854         case WM_NCMOUSEMOVE:
6855         case WM_SETCURSOR:
6856         case WM_GETICON:
6857         case WM_GETOBJECT:
6858         case WM_DEVICECHANGE:
6859             return 0;
6860     }
6861
6862     msg.hwnd = hwnd;
6863     msg.message = message;
6864     msg.flags = sent|wparam|lparam;
6865     if (defwndproc_counter) msg.flags |= defwinproc;
6866     if (beginpaint_counter) msg.flags |= beginpaint;
6867     msg.wParam = wParam;
6868     msg.lParam = lParam;
6869     msg.descr = "MsgCheckProc";
6870     add_message(&msg);
6871
6872     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6873     {
6874         HWND parent = GetParent(hwnd);
6875         RECT rc;
6876         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6877
6878         GetClientRect(parent, &rc);
6879         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6880         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6881               minmax->ptReserved.x, minmax->ptReserved.y,
6882               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6883               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6884               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6885               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6886
6887         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6888            minmax->ptMaxSize.x, rc.right);
6889         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6890            minmax->ptMaxSize.y, rc.bottom);
6891     }
6892
6893     if (message == WM_PAINT)
6894     {
6895         PAINTSTRUCT ps;
6896         beginpaint_counter++;
6897         BeginPaint( hwnd, &ps );
6898         beginpaint_counter--;
6899         EndPaint( hwnd, &ps );
6900         return 0;
6901     }
6902
6903     defwndproc_counter++;
6904     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6905                   : DefWindowProcA(hwnd, message, wParam, lParam);
6906     defwndproc_counter--;
6907
6908     return ret;
6909 }
6910
6911 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6912 {
6913     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6914 }
6915
6916 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6917 {
6918     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6919 }
6920
6921 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6922 {
6923     static long defwndproc_counter = 0;
6924     LRESULT ret;
6925     struct recvd_message msg;
6926
6927     switch (message)
6928     {
6929     case WM_GETICON:
6930     case WM_GETOBJECT:
6931         return 0;  /* ignore them */
6932     case WM_QUERYENDSESSION:
6933     case WM_ENDSESSION:
6934         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
6935         break;
6936     }
6937
6938     msg.hwnd = hwnd;
6939     msg.message = message;
6940     msg.flags = sent|wparam|lparam;
6941     if (defwndproc_counter) msg.flags |= defwinproc;
6942     msg.wParam = wParam;
6943     msg.lParam = lParam;
6944     msg.descr = "popup";
6945     add_message(&msg);
6946
6947     if (message == WM_CREATE)
6948     {
6949         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6950         SetWindowLongA(hwnd, GWL_STYLE, style);
6951     }
6952
6953     defwndproc_counter++;
6954     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6955     defwndproc_counter--;
6956
6957     return ret;
6958 }
6959
6960 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6961 {
6962     static long defwndproc_counter = 0;
6963     static long beginpaint_counter = 0;
6964     LRESULT ret;
6965     struct recvd_message msg;
6966
6967     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
6968
6969     /* ignore registered messages */
6970     if (message >= 0xc000) return 0;
6971
6972     if (log_all_parent_messages ||
6973         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6974         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6975         message == WM_ENABLE || message == WM_ENTERIDLE ||
6976         message == WM_DRAWITEM ||
6977         message == WM_IME_SETCONTEXT)
6978     {
6979         switch (message)
6980         {
6981             /* ignore */
6982             case WM_NCHITTEST:
6983                 return HTCLIENT;
6984             case WM_SETCURSOR:
6985             case WM_MOUSEMOVE:
6986                 return 0;
6987
6988             case WM_ERASEBKGND:
6989             {
6990                 RECT rc;
6991                 INT ret = GetClipBox((HDC)wParam, &rc);
6992
6993                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6994                        ret, rc.left, rc.top, rc.right, rc.bottom);
6995                 break;
6996             }
6997         }
6998
6999         msg.hwnd = hwnd;
7000         msg.message = message;
7001         msg.flags = sent|parent|wparam|lparam;
7002         if (defwndproc_counter) msg.flags |= defwinproc;
7003         if (beginpaint_counter) msg.flags |= beginpaint;
7004         msg.wParam = wParam;
7005         msg.lParam = lParam;
7006         msg.descr = "parent";
7007         add_message(&msg);
7008     }
7009
7010     if (message == WM_PAINT)
7011     {
7012         PAINTSTRUCT ps;
7013         beginpaint_counter++;
7014         BeginPaint( hwnd, &ps );
7015         beginpaint_counter--;
7016         EndPaint( hwnd, &ps );
7017         return 0;
7018     }
7019
7020     defwndproc_counter++;
7021     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7022     defwndproc_counter--;
7023
7024     return ret;
7025 }
7026
7027 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7028 {
7029     static long defwndproc_counter = 0;
7030     LRESULT ret;
7031     struct recvd_message msg;
7032
7033     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7034
7035     if (test_def_id)
7036     {
7037         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7038         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7039         if (after_end_dialog)
7040             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7041         else
7042             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7043     }
7044
7045     msg.hwnd = hwnd;
7046     msg.message = message;
7047     msg.flags = sent|wparam|lparam;
7048     if (defwndproc_counter) msg.flags |= defwinproc;
7049     msg.wParam = wParam;
7050     msg.lParam = lParam;
7051     msg.descr = "dialog";
7052     add_message(&msg);
7053
7054     defwndproc_counter++;
7055     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7056     defwndproc_counter--;
7057
7058     return ret;
7059 }
7060
7061 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7062 {
7063     static long defwndproc_counter = 0;
7064     LRESULT ret;
7065     struct recvd_message msg;
7066
7067     /* log only specific messages we are interested in */
7068     switch (message)
7069     {
7070 #if 0 /* probably log these as well */
7071     case WM_ACTIVATE:
7072     case WM_SETFOCUS:
7073     case WM_KILLFOCUS:
7074 #endif
7075     case WM_SHOWWINDOW:
7076     case WM_SIZE:
7077     case WM_MOVE:
7078     case WM_GETMINMAXINFO:
7079     case WM_WINDOWPOSCHANGING:
7080     case WM_WINDOWPOSCHANGED:
7081         break;
7082
7083     default: /* ignore */
7084         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7085         return DefWindowProcA(hwnd, message, wParam, lParam);
7086     }
7087
7088     msg.hwnd = hwnd;
7089     msg.message = message;
7090     msg.flags = sent|wparam|lparam;
7091     if (defwndproc_counter) msg.flags |= defwinproc;
7092     msg.wParam = wParam;
7093     msg.lParam = lParam;
7094     msg.descr = "show";
7095     add_message(&msg);
7096
7097     defwndproc_counter++;
7098     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7099     defwndproc_counter--;
7100
7101     return ret;
7102 }
7103
7104 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7105 {
7106     switch (msg)
7107     {
7108         case WM_CREATE: return 0;
7109         case WM_PAINT:
7110         {
7111             MSG msg2;
7112             static int i = 0;
7113
7114             if (i < 256)
7115             {
7116                 i++;
7117                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7118                 {
7119                     TranslateMessage(&msg2);
7120                     DispatchMessage(&msg2);
7121                 }
7122                 i--;
7123             }
7124             else ok(broken(1), "infinite loop\n");
7125             if ( i == 0)
7126                 paint_loop_done = 1;
7127             return DefWindowProcA(hWnd,msg,wParam,lParam);
7128         }
7129     }
7130     return DefWindowProcA(hWnd,msg,wParam,lParam);
7131 }
7132
7133 static BOOL RegisterWindowClasses(void)
7134 {
7135     WNDCLASSA cls;
7136     WNDCLASSW clsW;
7137
7138     cls.style = 0;
7139     cls.lpfnWndProc = MsgCheckProcA;
7140     cls.cbClsExtra = 0;
7141     cls.cbWndExtra = 0;
7142     cls.hInstance = GetModuleHandleA(0);
7143     cls.hIcon = 0;
7144     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7145     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7146     cls.lpszMenuName = NULL;
7147     cls.lpszClassName = "TestWindowClass";
7148     if(!RegisterClassA(&cls)) return FALSE;
7149
7150     cls.lpfnWndProc = ShowWindowProcA;
7151     cls.lpszClassName = "ShowWindowClass";
7152     if(!RegisterClassA(&cls)) return FALSE;
7153
7154     cls.lpfnWndProc = PopupMsgCheckProcA;
7155     cls.lpszClassName = "TestPopupClass";
7156     if(!RegisterClassA(&cls)) return FALSE;
7157
7158     cls.lpfnWndProc = ParentMsgCheckProcA;
7159     cls.lpszClassName = "TestParentClass";
7160     if(!RegisterClassA(&cls)) return FALSE;
7161
7162     cls.lpfnWndProc = DefWindowProcA;
7163     cls.lpszClassName = "SimpleWindowClass";
7164     if(!RegisterClassA(&cls)) return FALSE;
7165
7166     cls.lpfnWndProc = PaintLoopProcA;
7167     cls.lpszClassName = "PaintLoopWindowClass";
7168     if(!RegisterClassA(&cls)) return FALSE;
7169
7170     cls.style = CS_NOCLOSE;
7171     cls.lpszClassName = "NoCloseWindowClass";
7172     if(!RegisterClassA(&cls)) return FALSE;
7173
7174     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7175     cls.style = 0;
7176     cls.hInstance = GetModuleHandleA(0);
7177     cls.hbrBackground = 0;
7178     cls.lpfnWndProc = TestDlgProcA;
7179     cls.lpszClassName = "TestDialogClass";
7180     if(!RegisterClassA(&cls)) return FALSE;
7181
7182     clsW.style = 0;
7183     clsW.lpfnWndProc = MsgCheckProcW;
7184     clsW.cbClsExtra = 0;
7185     clsW.cbWndExtra = 0;
7186     clsW.hInstance = GetModuleHandleW(0);
7187     clsW.hIcon = 0;
7188     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7189     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7190     clsW.lpszMenuName = NULL;
7191     clsW.lpszClassName = testWindowClassW;
7192     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7193
7194     return TRUE;
7195 }
7196
7197 static BOOL is_our_logged_class(HWND hwnd)
7198 {
7199     char buf[256];
7200
7201     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7202     {
7203         if (!lstrcmpiA(buf, "TestWindowClass") ||
7204             !lstrcmpiA(buf, "ShowWindowClass") ||
7205             !lstrcmpiA(buf, "TestParentClass") ||
7206             !lstrcmpiA(buf, "TestPopupClass") ||
7207             !lstrcmpiA(buf, "SimpleWindowClass") ||
7208             !lstrcmpiA(buf, "TestDialogClass") ||
7209             !lstrcmpiA(buf, "MDI_frame_class") ||
7210             !lstrcmpiA(buf, "MDI_client_class") ||
7211             !lstrcmpiA(buf, "MDI_child_class") ||
7212             !lstrcmpiA(buf, "my_button_class") ||
7213             !lstrcmpiA(buf, "my_edit_class") ||
7214             !lstrcmpiA(buf, "static") ||
7215             !lstrcmpiA(buf, "ListBox") ||
7216             !lstrcmpiA(buf, "ComboBox") ||
7217             !lstrcmpiA(buf, "MyDialogClass") ||
7218             !lstrcmpiA(buf, "#32770") ||
7219             !lstrcmpiA(buf, "#32768"))
7220         return TRUE;
7221     }
7222     return FALSE;
7223 }
7224
7225 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7226
7227     HWND hwnd;
7228
7229     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7230
7231     if (nCode == HCBT_CLICKSKIPPED)
7232     {
7233         /* ignore this event, XP sends it a lot when switching focus between windows */
7234         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7235     }
7236
7237     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7238     {
7239         struct recvd_message msg;
7240
7241         msg.hwnd = 0;
7242         msg.message = nCode;
7243         msg.flags = hook|wparam|lparam;
7244         msg.wParam = wParam;
7245         msg.lParam = lParam;
7246         msg.descr = "CBT";
7247         add_message(&msg);
7248
7249         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7250     }
7251
7252     if (nCode == HCBT_DESTROYWND)
7253     {
7254         if (test_DestroyWindow_flag)
7255         {
7256             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7257             if (style & WS_CHILD)
7258                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7259             else if (style & WS_POPUP)
7260                 lParam = WND_POPUP_ID;
7261             else
7262                 lParam = WND_PARENT_ID;
7263         }
7264     }
7265
7266     /* Log also SetFocus(0) calls */
7267     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7268
7269     if (is_our_logged_class(hwnd))
7270     {
7271         struct recvd_message msg;
7272
7273         msg.hwnd = hwnd;
7274         msg.message = nCode;
7275         msg.flags = hook|wparam|lparam;
7276         msg.wParam = wParam;
7277         msg.lParam = lParam;
7278         msg.descr = "CBT";
7279         add_message(&msg);
7280     }
7281     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7282 }
7283
7284 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7285                                     DWORD event,
7286                                     HWND hwnd,
7287                                     LONG object_id,
7288                                     LONG child_id,
7289                                     DWORD thread_id,
7290                                     DWORD event_time)
7291 {
7292     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7293
7294     /* ignore mouse cursor events */
7295     if (object_id == OBJID_CURSOR) return;
7296
7297     if (!hwnd || is_our_logged_class(hwnd))
7298     {
7299         struct recvd_message msg;
7300
7301         msg.hwnd = hwnd;
7302         msg.message = event;
7303         msg.flags = winevent_hook|wparam|lparam;
7304         msg.wParam = object_id;
7305         msg.lParam = child_id;
7306         msg.descr = "WEH";
7307         add_message(&msg);
7308     }
7309 }
7310
7311 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7312 static const WCHAR wszAnsi[] = {'U',0};
7313
7314 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7315 {
7316     switch (uMsg)
7317     {
7318     case CB_FINDSTRINGEXACT:
7319         trace("String: %p\n", (LPCWSTR)lParam);
7320         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7321             return 1;
7322         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7323             return 0;
7324         return -1;
7325     }
7326     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7327 }
7328
7329 static const struct message WmGetTextLengthAfromW[] = {
7330     { WM_GETTEXTLENGTH, sent },
7331     { WM_GETTEXT, sent|optional },
7332     { 0 }
7333 };
7334
7335 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7336
7337 /* dummy window proc for WM_GETTEXTLENGTH test */
7338 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7339 {
7340     switch(msg)
7341     {
7342     case WM_GETTEXTLENGTH:
7343         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7344     case WM_GETTEXT:
7345         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7346         return lstrlenW( (LPWSTR)lp );
7347     default:
7348         return DefWindowProcW( hwnd, msg, wp, lp );
7349     }
7350 }
7351
7352 static void test_message_conversion(void)
7353 {
7354     static const WCHAR wszMsgConversionClass[] =
7355         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7356     WNDCLASSW cls;
7357     LRESULT lRes;
7358     HWND hwnd;
7359     WNDPROC wndproc, newproc;
7360     BOOL ret;
7361
7362     cls.style = 0;
7363     cls.lpfnWndProc = MsgConversionProcW;
7364     cls.cbClsExtra = 0;
7365     cls.cbWndExtra = 0;
7366     cls.hInstance = GetModuleHandleW(NULL);
7367     cls.hIcon = NULL;
7368     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7369     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7370     cls.lpszMenuName = NULL;
7371     cls.lpszClassName = wszMsgConversionClass;
7372     /* this call will fail on Win9x, but that doesn't matter as this test is
7373      * meaningless on those platforms */
7374     if(!RegisterClassW(&cls)) return;
7375
7376     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7377                            100, 100, 200, 200, 0, 0, 0, NULL);
7378     ok(hwnd != NULL, "Window creation failed\n");
7379
7380     /* {W, A} -> A */
7381
7382     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7383     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7384     ok(lRes == 0, "String should have been converted\n");
7385     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7386     ok(lRes == 1, "String shouldn't have been converted\n");
7387
7388     /* {W, A} -> W */
7389
7390     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7391     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7392     ok(lRes == 1, "String shouldn't have been converted\n");
7393     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7394     ok(lRes == 1, "String shouldn't have been converted\n");
7395
7396     /* Synchronous messages */
7397
7398     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7399     ok(lRes == 0, "String should have been converted\n");
7400     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7401     ok(lRes == 1, "String shouldn't have been converted\n");
7402
7403     /* Asynchronous messages */
7404
7405     SetLastError(0);
7406     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7407     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7408         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7409     SetLastError(0);
7410     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7411     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7412         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7413     SetLastError(0);
7414     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7415     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7416         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7417     SetLastError(0);
7418     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7419     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7420         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7421     SetLastError(0);
7422     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7423     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7424         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7425     SetLastError(0);
7426     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7427     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7428         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7429     SetLastError(0);
7430     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7431     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7432         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7433     SetLastError(0);
7434     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7435     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7436         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7437
7438     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7439
7440     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7441                           WS_OVERLAPPEDWINDOW,
7442                           100, 100, 200, 200, 0, 0, 0, NULL);
7443     assert(hwnd);
7444     flush_sequence();
7445     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7446     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7447     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7448         "got bad length %ld\n", lRes );
7449
7450     flush_sequence();
7451     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7452                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7453     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7454     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7455         "got bad length %ld\n", lRes );
7456
7457     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7458     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7459     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7460     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7461                                      NULL, 0, NULL, NULL ) ||
7462         broken(lRes == lstrlenW(dummy_window_text) + 37),
7463         "got bad length %ld\n", lRes );
7464
7465     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7466     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7467     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7468                                      NULL, 0, NULL, NULL ) ||
7469         broken(lRes == lstrlenW(dummy_window_text) + 37),
7470         "got bad length %ld\n", lRes );
7471
7472     ret = DestroyWindow(hwnd);
7473     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7474 }
7475
7476 struct timer_info
7477 {
7478     HWND hWnd;
7479     HANDLE handles[2];
7480     DWORD id;
7481 };
7482
7483 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7484 {
7485 }
7486
7487 #define TIMER_ID  0x19
7488
7489 static DWORD WINAPI timer_thread_proc(LPVOID x)
7490 {
7491     struct timer_info *info = x;
7492     DWORD r;
7493
7494     r = KillTimer(info->hWnd, 0x19);
7495     ok(r,"KillTimer failed in thread\n");
7496     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7497     ok(r,"SetTimer failed in thread\n");
7498     ok(r==TIMER_ID,"SetTimer id different\n");
7499     r = SetEvent(info->handles[0]);
7500     ok(r,"SetEvent failed in thread\n");
7501     return 0;
7502 }
7503
7504 static void test_timers(void)
7505 {
7506     struct timer_info info;
7507     DWORD id;
7508
7509     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7510        WS_OVERLAPPEDWINDOW ,
7511        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7512        NULL, NULL, 0);
7513
7514     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7515     ok(info.id, "SetTimer failed\n");
7516     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7517     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7518     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7519
7520     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7521
7522     WaitForSingleObject(info.handles[1], INFINITE);
7523
7524     CloseHandle(info.handles[0]);
7525     CloseHandle(info.handles[1]);
7526
7527     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7528
7529     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7530 }
7531
7532 static int count = 0;
7533 static VOID CALLBACK callback_count(
7534     HWND hwnd,
7535     UINT uMsg,
7536     UINT_PTR idEvent,
7537     DWORD dwTime
7538 )
7539 {
7540     count++;
7541 }
7542
7543 static void test_timers_no_wnd(void)
7544 {
7545     UINT_PTR id, id2;
7546     MSG msg;
7547
7548     count = 0;
7549     id = SetTimer(NULL, 0, 100, callback_count);
7550     ok(id != 0, "did not get id from SetTimer.\n");
7551     id2 = SetTimer(NULL, id, 200, callback_count);
7552     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7553     Sleep(150);
7554     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7555     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7556     Sleep(150);
7557     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7558     ok(count == 1, "did not get one count as expected (%i).\n", count);
7559     KillTimer(NULL, id);
7560     Sleep(250);
7561     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7562     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7563 }
7564
7565 /* Various win events with arbitrary parameters */
7566 static const struct message WmWinEventsSeq[] = {
7567     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7568     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7569     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7570     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7571     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7572     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7573     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7574     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7575     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7576     /* our win event hook ignores OBJID_CURSOR events */
7577     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7578     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7579     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7580     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7581     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7582     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7583     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7584     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7585     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7586     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7587     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7588     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7589     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7590     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7591     { 0 }
7592 };
7593 static const struct message WmWinEventCaretSeq[] = {
7594     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7595     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7596     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7597     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7598     { 0 }
7599 };
7600 static const struct message WmWinEventCaretSeq_2[] = {
7601     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7602     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7603     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7604     { 0 }
7605 };
7606 static const struct message WmWinEventAlertSeq[] = {
7607     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7608     { 0 }
7609 };
7610 static const struct message WmWinEventAlertSeq_2[] = {
7611     /* create window in the thread proc */
7612     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7613     /* our test event */
7614     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7615     { 0 }
7616 };
7617 static const struct message WmGlobalHookSeq_1[] = {
7618     /* create window in the thread proc */
7619     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7620     /* our test events */
7621     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7622     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7623     { 0 }
7624 };
7625 static const struct message WmGlobalHookSeq_2[] = {
7626     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7627     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7628     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7629     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7630     { 0 }
7631 };
7632
7633 static const struct message WmMouseLLHookSeq[] = {
7634     { WM_MOUSEMOVE, hook },
7635     { WM_LBUTTONUP, hook },
7636     { WM_MOUSEMOVE, hook },
7637     { 0 }
7638 };
7639
7640 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7641                                          DWORD event,
7642                                          HWND hwnd,
7643                                          LONG object_id,
7644                                          LONG child_id,
7645                                          DWORD thread_id,
7646                                          DWORD event_time)
7647 {
7648     char buf[256];
7649
7650     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7651     {
7652         if (!lstrcmpiA(buf, "TestWindowClass") ||
7653             !lstrcmpiA(buf, "static"))
7654         {
7655             struct recvd_message msg;
7656
7657             msg.hwnd = hwnd;
7658             msg.message = event;
7659             msg.flags = winevent_hook|wparam|lparam;
7660             msg.wParam = object_id;
7661             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7662             msg.descr = "WEH_2";
7663             add_message(&msg);
7664         }
7665     }
7666 }
7667
7668 static HHOOK hCBT_global_hook;
7669 static DWORD cbt_global_hook_thread_id;
7670
7671 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7672
7673     HWND hwnd;
7674     char buf[256];
7675
7676     if (nCode == HCBT_SYSCOMMAND)
7677     {
7678         struct recvd_message msg;
7679
7680         msg.hwnd = 0;
7681         msg.message = nCode;
7682         msg.flags = hook|wparam|lparam;
7683         msg.wParam = wParam;
7684         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7685         msg.descr = "CBT_2";
7686         add_message(&msg);
7687
7688         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7689     }
7690     /* WH_MOUSE_LL hook */
7691     if (nCode == HC_ACTION)
7692     {
7693         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7694
7695         /* we can't test for real mouse events */
7696         if (mhll->flags & LLMHF_INJECTED)
7697         {
7698             struct recvd_message msg;
7699
7700             memset (&msg, 0, sizeof (msg));
7701             msg.message = wParam;
7702             msg.flags = hook;
7703             msg.descr = "CBT_2";
7704             add_message(&msg);
7705         }
7706         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7707     }
7708
7709     /* Log also SetFocus(0) calls */
7710     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7711
7712     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7713     {
7714         if (!lstrcmpiA(buf, "TestWindowClass") ||
7715             !lstrcmpiA(buf, "static"))
7716         {
7717             struct recvd_message msg;
7718
7719             msg.hwnd = hwnd;
7720             msg.message = nCode;
7721             msg.flags = hook|wparam|lparam;
7722             msg.wParam = wParam;
7723             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7724             msg.descr = "CBT_2";
7725             add_message(&msg);
7726         }
7727     }
7728     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7729 }
7730
7731 static DWORD WINAPI win_event_global_thread_proc(void *param)
7732 {
7733     HWND hwnd;
7734     MSG msg;
7735     HANDLE hevent = *(HANDLE *)param;
7736
7737     assert(pNotifyWinEvent);
7738
7739     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7740     assert(hwnd);
7741     trace("created thread window %p\n", hwnd);
7742
7743     *(HWND *)param = hwnd;
7744
7745     flush_sequence();
7746     /* this event should be received only by our new hook proc,
7747      * an old one does not expect an event from another thread.
7748      */
7749     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7750     SetEvent(hevent);
7751
7752     while (GetMessage(&msg, 0, 0, 0))
7753     {
7754         TranslateMessage(&msg);
7755         DispatchMessage(&msg);
7756     }
7757     return 0;
7758 }
7759
7760 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7761 {
7762     HWND hwnd;
7763     MSG msg;
7764     HANDLE hevent = *(HANDLE *)param;
7765
7766     flush_sequence();
7767     /* these events should be received only by our new hook proc,
7768      * an old one does not expect an event from another thread.
7769      */
7770
7771     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7772     assert(hwnd);
7773     trace("created thread window %p\n", hwnd);
7774
7775     *(HWND *)param = hwnd;
7776
7777     /* Windows doesn't like when a thread plays games with the focus,
7778        that leads to all kinds of misbehaviours and failures to activate
7779        a window. So, better keep next lines commented out.
7780     SetFocus(0);
7781     SetFocus(hwnd);*/
7782
7783     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7784     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7785
7786     SetEvent(hevent);
7787
7788     while (GetMessage(&msg, 0, 0, 0))
7789     {
7790         TranslateMessage(&msg);
7791         DispatchMessage(&msg);
7792     }
7793     return 0;
7794 }
7795
7796 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7797 {
7798     HWND hwnd;
7799     MSG msg;
7800     HANDLE hevent = *(HANDLE *)param;
7801
7802     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7803     assert(hwnd);
7804     trace("created thread window %p\n", hwnd);
7805
7806     *(HWND *)param = hwnd;
7807
7808     flush_sequence();
7809
7810     /* Windows doesn't like when a thread plays games with the focus,
7811      * that leads to all kinds of misbehaviours and failures to activate
7812      * a window. So, better don't generate a mouse click message below.
7813      */
7814     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7815     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7816     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7817
7818     SetEvent(hevent);
7819     while (GetMessage(&msg, 0, 0, 0))
7820     {
7821         TranslateMessage(&msg);
7822         DispatchMessage(&msg);
7823     }
7824     return 0;
7825 }
7826
7827 static void test_winevents(void)
7828 {
7829     BOOL ret;
7830     MSG msg;
7831     HWND hwnd, hwnd2;
7832     UINT i;
7833     HANDLE hthread, hevent;
7834     DWORD tid;
7835     HWINEVENTHOOK hhook;
7836     const struct message *events = WmWinEventsSeq;
7837
7838     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7839                            WS_OVERLAPPEDWINDOW,
7840                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7841                            NULL, NULL, 0);
7842     assert(hwnd);
7843
7844     /****** start of global hook test *************/
7845     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7846     if (!hCBT_global_hook)
7847     {
7848         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7849         skip( "cannot set global hook\n" );
7850         return;
7851     }
7852
7853     hevent = CreateEventA(NULL, 0, 0, NULL);
7854     assert(hevent);
7855     hwnd2 = (HWND)hevent;
7856
7857     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7858     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7859
7860     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7861
7862     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7863
7864     flush_sequence();
7865     /* this one should be received only by old hook proc */
7866     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7867     /* this one should be received only by old hook proc */
7868     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7869
7870     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7871
7872     ret = UnhookWindowsHookEx(hCBT_global_hook);
7873     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7874
7875     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7876     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7877     CloseHandle(hthread);
7878     CloseHandle(hevent);
7879     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7880     /****** end of global hook test *************/
7881
7882     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7883     {
7884         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7885         return;
7886     }
7887
7888     flush_sequence();
7889
7890     if (0)
7891     {
7892     /* this test doesn't pass under Win9x */
7893     /* win2k ignores events with hwnd == 0 */
7894     SetLastError(0xdeadbeef);
7895     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7896     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7897        GetLastError() == 0xdeadbeef, /* Win9x */
7898        "unexpected error %d\n", GetLastError());
7899     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7900     }
7901
7902     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7903         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7904
7905     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7906
7907     /****** start of event filtering test *************/
7908     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7909         EVENT_OBJECT_SHOW, /* 0x8002 */
7910         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7911         GetModuleHandleA(0), win_event_global_hook_proc,
7912         GetCurrentProcessId(), 0,
7913         WINEVENT_INCONTEXT);
7914     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7915
7916     hevent = CreateEventA(NULL, 0, 0, NULL);
7917     assert(hevent);
7918     hwnd2 = (HWND)hevent;
7919
7920     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7921     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7922
7923     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7924
7925     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7926
7927     flush_sequence();
7928     /* this one should be received only by old hook proc */
7929     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7930     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7931     /* this one should be received only by old hook proc */
7932     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7933
7934     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7935
7936     ret = pUnhookWinEvent(hhook);
7937     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7938
7939     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7940     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7941     CloseHandle(hthread);
7942     CloseHandle(hevent);
7943     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7944     /****** end of event filtering test *************/
7945
7946     /****** start of out of context event test *************/
7947     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7948         EVENT_MIN, EVENT_MAX,
7949         0, win_event_global_hook_proc,
7950         GetCurrentProcessId(), 0,
7951         WINEVENT_OUTOFCONTEXT);
7952     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7953
7954     hevent = CreateEventA(NULL, 0, 0, NULL);
7955     assert(hevent);
7956     hwnd2 = (HWND)hevent;
7957
7958     flush_sequence();
7959
7960     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7961     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7962
7963     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7964
7965     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7966     /* process pending winevent messages */
7967     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7968     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7969
7970     flush_sequence();
7971     /* this one should be received only by old hook proc */
7972     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7973     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7974     /* this one should be received only by old hook proc */
7975     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7976
7977     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7978     /* process pending winevent messages */
7979     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7980     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7981
7982     ret = pUnhookWinEvent(hhook);
7983     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7984
7985     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7986     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7987     CloseHandle(hthread);
7988     CloseHandle(hevent);
7989     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7990     /****** end of out of context event test *************/
7991
7992     /****** start of MOUSE_LL hook test *************/
7993     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7994     /* WH_MOUSE_LL is not supported on Win9x platforms */
7995     if (!hCBT_global_hook)
7996     {
7997         trace("Skipping WH_MOUSE_LL test on this platform\n");
7998         goto skip_mouse_ll_hook_test;
7999     }
8000
8001     hevent = CreateEventA(NULL, 0, 0, NULL);
8002     assert(hevent);
8003     hwnd2 = (HWND)hevent;
8004
8005     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8006     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8007
8008     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8009         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8010
8011     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8012     flush_sequence();
8013
8014     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8015     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8016     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8017
8018     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8019
8020     ret = UnhookWindowsHookEx(hCBT_global_hook);
8021     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8022
8023     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8024     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8025     CloseHandle(hthread);
8026     CloseHandle(hevent);
8027     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8028     /****** end of MOUSE_LL hook test *************/
8029 skip_mouse_ll_hook_test:
8030
8031     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8032 }
8033
8034 static void test_set_hook(void)
8035 {
8036     BOOL ret;
8037     HHOOK hhook;
8038     HWINEVENTHOOK hwinevent_hook;
8039
8040     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8041     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8042     UnhookWindowsHookEx(hhook);
8043
8044     if (0)
8045     {
8046     /* this test doesn't pass under Win9x: BUG! */
8047     SetLastError(0xdeadbeef);
8048     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8049     ok(!hhook, "global hook requires hModule != 0\n");
8050     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8051     }
8052
8053     SetLastError(0xdeadbeef);
8054     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8055     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8056     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8057        GetLastError() == 0xdeadbeef, /* Win9x */
8058        "unexpected error %d\n", GetLastError());
8059
8060     SetLastError(0xdeadbeef);
8061     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8062     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8063        GetLastError() == 0xdeadbeef, /* Win9x */
8064        "unexpected error %d\n", GetLastError());
8065
8066     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8067
8068     /* even process local incontext hooks require hmodule */
8069     SetLastError(0xdeadbeef);
8070     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8071         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8072     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8073     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8074        GetLastError() == 0xdeadbeef, /* Win9x */
8075        "unexpected error %d\n", GetLastError());
8076
8077     /* even thread local incontext hooks require hmodule */
8078     SetLastError(0xdeadbeef);
8079     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8080         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8081     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8082     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8083        GetLastError() == 0xdeadbeef, /* Win9x */
8084        "unexpected error %d\n", GetLastError());
8085
8086     if (0)
8087     {
8088     /* these 3 tests don't pass under Win9x */
8089     SetLastError(0xdeadbeef);
8090     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
8091         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8092     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8093     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8094
8095     SetLastError(0xdeadbeef);
8096     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
8097         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8098     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8099     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8100
8101     SetLastError(0xdeadbeef);
8102     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8103         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8104     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8105     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8106     }
8107
8108     SetLastError(0xdeadbeef);
8109     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
8110         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8111     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8112     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8113     ret = pUnhookWinEvent(hwinevent_hook);
8114     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8115
8116 todo_wine {
8117     /* This call succeeds under win2k SP4, but fails under Wine.
8118        Does win2k test/use passed process id? */
8119     SetLastError(0xdeadbeef);
8120     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8121         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8122     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8123     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8124     ret = pUnhookWinEvent(hwinevent_hook);
8125     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8126 }
8127
8128     SetLastError(0xdeadbeef);
8129     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8130     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8131         GetLastError() == 0xdeadbeef, /* Win9x */
8132         "unexpected error %d\n", GetLastError());
8133 }
8134
8135 static const struct message ScrollWindowPaint1[] = {
8136     { WM_PAINT, sent },
8137     { WM_ERASEBKGND, sent|beginpaint },
8138     { 0 }
8139 };
8140
8141 static const struct message ScrollWindowPaint2[] = {
8142     { WM_PAINT, sent },
8143     { 0 }
8144 };
8145
8146 static void test_scrollwindowex(void)
8147 {
8148     HWND hwnd, hchild;
8149     RECT rect={0,0,130,130};
8150
8151     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8152             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8153             100, 100, 200, 200, 0, 0, 0, NULL);
8154     ok (hwnd != 0, "Failed to create overlapped window\n");
8155     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8156             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8157             10, 10, 150, 150, hwnd, 0, 0, NULL);
8158     ok (hchild != 0, "Failed to create child\n");
8159     UpdateWindow(hwnd);
8160     flush_events();
8161     flush_sequence();
8162
8163     /* scroll without the child window */
8164     trace("start scroll\n");
8165     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8166             SW_ERASE|SW_INVALIDATE);
8167     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8168     trace("end scroll\n");
8169     flush_sequence();
8170     flush_events();
8171     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8172     flush_events();
8173     flush_sequence();
8174
8175     /* Now without the SW_ERASE flag */
8176     trace("start scroll\n");
8177     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8178     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8179     trace("end scroll\n");
8180     flush_sequence();
8181     flush_events();
8182     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8183     flush_events();
8184     flush_sequence();
8185
8186     /* now scroll the child window as well */
8187     trace("start scroll\n");
8188     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8189             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8190     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8191     /* windows sometimes a WM_MOVE */
8192     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8193     trace("end scroll\n");
8194     flush_sequence();
8195     flush_events();
8196     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8197     flush_events();
8198     flush_sequence();
8199
8200     /* now scroll with ScrollWindow() */
8201     trace("start scroll with ScrollWindow\n");
8202     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8203     trace("end scroll\n");
8204     flush_sequence();
8205     flush_events();
8206     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8207
8208     ok(DestroyWindow(hchild), "failed to destroy window\n");
8209     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8210     flush_sequence();
8211 }
8212
8213 static const struct message destroy_window_with_children[] = {
8214     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8215     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8216     { 0x0090, sent|optional },
8217     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8218     { 0x0090, sent|optional },
8219     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8220     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8221     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8222     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8223     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8224     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8225     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8226     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8227     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8228     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8229     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8230     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8231     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8232     { 0 }
8233 };
8234
8235 static void test_DestroyWindow(void)
8236 {
8237     BOOL ret;
8238     HWND parent, child1, child2, child3, child4, test;
8239     UINT_PTR child_id = WND_CHILD_ID + 1;
8240
8241     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8242                              100, 100, 200, 200, 0, 0, 0, NULL);
8243     assert(parent != 0);
8244     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8245                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8246     assert(child1 != 0);
8247     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8248                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8249     assert(child2 != 0);
8250     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8251                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8252     assert(child3 != 0);
8253     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8254                              0, 0, 50, 50, parent, 0, 0, NULL);
8255     assert(child4 != 0);
8256
8257     /* test owner/parent of child2 */
8258     test = GetParent(child2);
8259     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8260     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8261     if(pGetAncestor) {
8262         test = pGetAncestor(child2, GA_PARENT);
8263         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8264     }
8265     test = GetWindow(child2, GW_OWNER);
8266     ok(!test, "wrong owner %p\n", test);
8267
8268     test = SetParent(child2, parent);
8269     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8270
8271     /* test owner/parent of the parent */
8272     test = GetParent(parent);
8273     ok(!test, "wrong parent %p\n", test);
8274     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8275     if(pGetAncestor) {
8276         test = pGetAncestor(parent, GA_PARENT);
8277         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8278     }
8279     test = GetWindow(parent, GW_OWNER);
8280     ok(!test, "wrong owner %p\n", test);
8281
8282     /* test owner/parent of child1 */
8283     test = GetParent(child1);
8284     ok(test == parent, "wrong parent %p\n", test);
8285     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8286     if(pGetAncestor) {
8287         test = pGetAncestor(child1, GA_PARENT);
8288         ok(test == parent, "wrong parent %p\n", test);
8289     }
8290     test = GetWindow(child1, GW_OWNER);
8291     ok(!test, "wrong owner %p\n", test);
8292
8293     /* test owner/parent of child2 */
8294     test = GetParent(child2);
8295     ok(test == parent, "wrong parent %p\n", test);
8296     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8297     if(pGetAncestor) {
8298         test = pGetAncestor(child2, GA_PARENT);
8299         ok(test == parent, "wrong parent %p\n", test);
8300     }
8301     test = GetWindow(child2, GW_OWNER);
8302     ok(!test, "wrong owner %p\n", test);
8303
8304     /* test owner/parent of child3 */
8305     test = GetParent(child3);
8306     ok(test == child1, "wrong parent %p\n", test);
8307     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8308     if(pGetAncestor) {
8309         test = pGetAncestor(child3, GA_PARENT);
8310         ok(test == child1, "wrong parent %p\n", test);
8311     }
8312     test = GetWindow(child3, GW_OWNER);
8313     ok(!test, "wrong owner %p\n", test);
8314
8315     /* test owner/parent of child4 */
8316     test = GetParent(child4);
8317     ok(test == parent, "wrong parent %p\n", test);
8318     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8319     if(pGetAncestor) {
8320         test = pGetAncestor(child4, GA_PARENT);
8321         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8322     }
8323     test = GetWindow(child4, GW_OWNER);
8324     ok(test == parent, "wrong owner %p\n", test);
8325
8326     flush_sequence();
8327
8328     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8329            parent, child1, child2, child3, child4);
8330
8331     SetCapture(child4);
8332     test = GetCapture();
8333     ok(test == child4, "wrong capture window %p\n", test);
8334
8335     test_DestroyWindow_flag = TRUE;
8336     ret = DestroyWindow(parent);
8337     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8338     test_DestroyWindow_flag = FALSE;
8339     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8340
8341     ok(!IsWindow(parent), "parent still exists\n");
8342     ok(!IsWindow(child1), "child1 still exists\n");
8343     ok(!IsWindow(child2), "child2 still exists\n");
8344     ok(!IsWindow(child3), "child3 still exists\n");
8345     ok(!IsWindow(child4), "child4 still exists\n");
8346
8347     test = GetCapture();
8348     ok(!test, "wrong capture window %p\n", test);
8349 }
8350
8351
8352 static const struct message WmDispatchPaint[] = {
8353     { WM_NCPAINT, sent },
8354     { WM_GETTEXT, sent|defwinproc|optional },
8355     { WM_GETTEXT, sent|defwinproc|optional },
8356     { WM_ERASEBKGND, sent },
8357     { 0 }
8358 };
8359
8360 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8361 {
8362     if (message == WM_PAINT) return 0;
8363     return MsgCheckProcA( hwnd, message, wParam, lParam );
8364 }
8365
8366 static void test_DispatchMessage(void)
8367 {
8368     RECT rect;
8369     MSG msg;
8370     int count;
8371     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8372                                100, 100, 200, 200, 0, 0, 0, NULL);
8373     ShowWindow( hwnd, SW_SHOW );
8374     UpdateWindow( hwnd );
8375     flush_events();
8376     flush_sequence();
8377     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8378
8379     SetRect( &rect, -5, -5, 5, 5 );
8380     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8381     count = 0;
8382     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8383     {
8384         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8385         else
8386         {
8387             flush_sequence();
8388             DispatchMessage( &msg );
8389             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8390             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8391             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8392             if (++count > 10) break;
8393         }
8394     }
8395     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8396
8397     trace("now without DispatchMessage\n");
8398     flush_sequence();
8399     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8400     count = 0;
8401     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8402     {
8403         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8404         else
8405         {
8406             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8407             flush_sequence();
8408             /* this will send WM_NCCPAINT just like DispatchMessage does */
8409             GetUpdateRgn( hwnd, hrgn, TRUE );
8410             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8411             DeleteObject( hrgn );
8412             GetClientRect( hwnd, &rect );
8413             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8414             ok( !count, "Got multiple WM_PAINTs\n" );
8415             if (++count > 10) break;
8416         }
8417     }
8418     DestroyWindow(hwnd);
8419 }
8420
8421
8422 static const struct message WmUser[] = {
8423     { WM_USER, sent },
8424     { 0 }
8425 };
8426
8427 struct sendmsg_info
8428 {
8429     HWND  hwnd;
8430     DWORD timeout;
8431     DWORD ret;
8432 };
8433
8434 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8435 {
8436     struct sendmsg_info *info = arg;
8437     SetLastError( 0xdeadbeef );
8438     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8439     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8440                         broken(GetLastError() == 0),  /* win9x */
8441                         "unexpected error %d\n", GetLastError());
8442     return 0;
8443 }
8444
8445 static void wait_for_thread( HANDLE thread )
8446 {
8447     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8448     {
8449         MSG msg;
8450         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8451     }
8452 }
8453
8454 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8455 {
8456     if (message == WM_USER) Sleep(200);
8457     return MsgCheckProcA( hwnd, message, wParam, lParam );
8458 }
8459
8460 static void test_SendMessageTimeout(void)
8461 {
8462     HANDLE thread;
8463     struct sendmsg_info info;
8464     DWORD tid;
8465     BOOL is_win9x;
8466
8467     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8468                                100, 100, 200, 200, 0, 0, 0, NULL);
8469     flush_events();
8470     flush_sequence();
8471
8472     info.timeout = 1000;
8473     info.ret = 0xdeadbeef;
8474     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8475     wait_for_thread( thread );
8476     CloseHandle( thread );
8477     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8478     ok_sequence( WmUser, "WmUser", FALSE );
8479
8480     info.timeout = 1;
8481     info.ret = 0xdeadbeef;
8482     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8483     Sleep(100);  /* SendMessageTimeout should time out here */
8484     wait_for_thread( thread );
8485     CloseHandle( thread );
8486     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8487     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8488
8489     /* 0 means infinite timeout (but not on win9x) */
8490     info.timeout = 0;
8491     info.ret = 0xdeadbeef;
8492     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8493     Sleep(100);
8494     wait_for_thread( thread );
8495     CloseHandle( thread );
8496     is_win9x = !info.ret;
8497     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8498     else ok_sequence( WmUser, "WmUser", FALSE );
8499
8500     /* timeout is treated as signed despite the prototype (but not on win9x) */
8501     info.timeout = 0x7fffffff;
8502     info.ret = 0xdeadbeef;
8503     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8504     Sleep(100);
8505     wait_for_thread( thread );
8506     CloseHandle( thread );
8507     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8508     ok_sequence( WmUser, "WmUser", FALSE );
8509
8510     info.timeout = 0x80000000;
8511     info.ret = 0xdeadbeef;
8512     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8513     Sleep(100);
8514     wait_for_thread( thread );
8515     CloseHandle( thread );
8516     if (is_win9x)
8517     {
8518         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8519         ok_sequence( WmUser, "WmUser", FALSE );
8520     }
8521     else
8522     {
8523         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8524         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8525     }
8526
8527     /* now check for timeout during message processing */
8528     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8529     info.timeout = 100;
8530     info.ret = 0xdeadbeef;
8531     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8532     wait_for_thread( thread );
8533     CloseHandle( thread );
8534     /* we should time out but still get the message */
8535     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8536     ok_sequence( WmUser, "WmUser", FALSE );
8537
8538     DestroyWindow( info.hwnd );
8539 }
8540
8541
8542 /****************** edit message test *************************/
8543 #define ID_EDIT 0x1234
8544 static const struct message sl_edit_setfocus[] =
8545 {
8546     { HCBT_SETFOCUS, hook },
8547     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8548     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8549     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8550     { WM_SETFOCUS, sent|wparam, 0 },
8551     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8552     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8553     { WM_CTLCOLOREDIT, sent|parent },
8554     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8555     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8556     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8557     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8558     { 0 }
8559 };
8560 static const struct message ml_edit_setfocus[] =
8561 {
8562     { HCBT_SETFOCUS, hook },
8563     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8564     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8565     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8566     { WM_SETFOCUS, sent|wparam, 0 },
8567     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8568     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8569     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8570     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8571     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8572     { 0 }
8573 };
8574 static const struct message sl_edit_killfocus[] =
8575 {
8576     { HCBT_SETFOCUS, hook },
8577     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8578     { WM_KILLFOCUS, sent|wparam, 0 },
8579     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8580     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8581     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8582     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8583     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8584     { 0 }
8585 };
8586 static const struct message sl_edit_lbutton_dblclk[] =
8587 {
8588     { WM_LBUTTONDBLCLK, sent },
8589     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8590     { 0 }
8591 };
8592 static const struct message sl_edit_lbutton_down[] =
8593 {
8594     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8595     { HCBT_SETFOCUS, hook },
8596     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8597     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8598     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8599     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8600     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8601     { WM_CTLCOLOREDIT, sent|parent },
8602     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8603     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8604     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8605     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8606     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8607     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8608     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8609     { WM_CTLCOLOREDIT, sent|parent|optional },
8610     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8611     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8612     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8613     { 0 }
8614 };
8615 static const struct message ml_edit_lbutton_down[] =
8616 {
8617     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8618     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8619     { HCBT_SETFOCUS, hook },
8620     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8621     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8622     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8623     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8624     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8625     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8626     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8627     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8628     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8629     { 0 }
8630 };
8631 static const struct message sl_edit_lbutton_up[] =
8632 {
8633     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8634     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8635     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8636     { WM_CAPTURECHANGED, sent|defwinproc },
8637     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8638     { 0 }
8639 };
8640 static const struct message ml_edit_lbutton_up[] =
8641 {
8642     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8643     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8644     { WM_CAPTURECHANGED, sent|defwinproc },
8645     { 0 }
8646 };
8647
8648 static WNDPROC old_edit_proc;
8649
8650 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8651 {
8652     static long defwndproc_counter = 0;
8653     LRESULT ret;
8654     struct recvd_message msg;
8655
8656     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8657
8658     msg.hwnd = hwnd;
8659     msg.message = message;
8660     msg.flags = sent|wparam|lparam;
8661     if (defwndproc_counter) msg.flags |= defwinproc;
8662     msg.wParam = wParam;
8663     msg.lParam = lParam;
8664     msg.descr = "edit";
8665     add_message(&msg);
8666
8667     defwndproc_counter++;
8668     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8669     defwndproc_counter--;
8670
8671     return ret;
8672 }
8673
8674 static void subclass_edit(void)
8675 {
8676     WNDCLASSA cls;
8677
8678     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8679
8680     old_edit_proc = cls.lpfnWndProc;
8681
8682     cls.hInstance = GetModuleHandle(0);
8683     cls.lpfnWndProc = edit_hook_proc;
8684     cls.lpszClassName = "my_edit_class";
8685     UnregisterClass(cls.lpszClassName, cls.hInstance);
8686     if (!RegisterClassA(&cls)) assert(0);
8687 }
8688
8689 static void test_edit_messages(void)
8690 {
8691     HWND hwnd, parent;
8692     DWORD dlg_code;
8693
8694     subclass_edit();
8695     log_all_parent_messages++;
8696
8697     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8698                              100, 100, 200, 200, 0, 0, 0, NULL);
8699     ok (parent != 0, "Failed to create parent window\n");
8700
8701     /* test single line edit */
8702     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8703                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8704     ok(hwnd != 0, "Failed to create edit window\n");
8705
8706     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8707     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8708
8709     ShowWindow(hwnd, SW_SHOW);
8710     UpdateWindow(hwnd);
8711     SetFocus(0);
8712     flush_sequence();
8713
8714     SetFocus(hwnd);
8715     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8716
8717     SetFocus(0);
8718     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8719
8720     SetFocus(0);
8721     ReleaseCapture();
8722     flush_sequence();
8723
8724     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8725     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8726
8727     SetFocus(0);
8728     ReleaseCapture();
8729     flush_sequence();
8730
8731     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8732     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8733
8734     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8735     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8736
8737     DestroyWindow(hwnd);
8738
8739     /* test multiline edit */
8740     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8741                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8742     ok(hwnd != 0, "Failed to create edit window\n");
8743
8744     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8745     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8746        "wrong dlg_code %08x\n", dlg_code);
8747
8748     ShowWindow(hwnd, SW_SHOW);
8749     UpdateWindow(hwnd);
8750     SetFocus(0);
8751     flush_sequence();
8752
8753     SetFocus(hwnd);
8754     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8755
8756     SetFocus(0);
8757     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8758
8759     SetFocus(0);
8760     ReleaseCapture();
8761     flush_sequence();
8762
8763     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8764     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8765
8766     SetFocus(0);
8767     ReleaseCapture();
8768     flush_sequence();
8769
8770     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8771     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8772
8773     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8774     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8775
8776     DestroyWindow(hwnd);
8777     DestroyWindow(parent);
8778
8779     log_all_parent_messages--;
8780 }
8781
8782 /**************************** End of Edit test ******************************/
8783
8784 static const struct message WmKeyDownSkippedSeq[] =
8785 {
8786     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8787     { 0 }
8788 };
8789 static const struct message WmKeyDownWasDownSkippedSeq[] =
8790 {
8791     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8792     { 0 }
8793 };
8794 static const struct message WmKeyUpSkippedSeq[] =
8795 {
8796     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8797     { 0 }
8798 };
8799 static const struct message WmUserKeyUpSkippedSeq[] =
8800 {
8801     { WM_USER, sent },
8802     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8803     { 0 }
8804 };
8805
8806 #define EV_STOP 0
8807 #define EV_SENDMSG 1
8808 #define EV_ACK 2
8809
8810 struct peekmsg_info
8811 {
8812     HWND  hwnd;
8813     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8814 };
8815
8816 static DWORD CALLBACK send_msg_thread_2(void *param)
8817 {
8818     DWORD ret;
8819     struct peekmsg_info *info = param;
8820
8821     trace("thread: looping\n");
8822     SetEvent(info->hevent[EV_ACK]);
8823
8824     while (1)
8825     {
8826         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8827
8828         switch (ret)
8829         {
8830         case WAIT_OBJECT_0 + EV_STOP:
8831             trace("thread: exiting\n");
8832             return 0;
8833
8834         case WAIT_OBJECT_0 + EV_SENDMSG:
8835             trace("thread: sending message\n");
8836             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8837                 "SendNotifyMessageA failed error %u\n", GetLastError());
8838             SetEvent(info->hevent[EV_ACK]);
8839             break;
8840
8841         default:
8842             trace("unexpected return: %04x\n", ret);
8843             assert(0);
8844             break;
8845         }
8846     }
8847     return 0;
8848 }
8849
8850 static void test_PeekMessage(void)
8851 {
8852     MSG msg;
8853     HANDLE hthread;
8854     DWORD tid, qstatus;
8855     UINT qs_all_input = QS_ALLINPUT;
8856     UINT qs_input = QS_INPUT;
8857     BOOL ret;
8858     struct peekmsg_info info;
8859
8860     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8861                               100, 100, 200, 200, 0, 0, 0, NULL);
8862     assert(info.hwnd);
8863     ShowWindow(info.hwnd, SW_SHOW);
8864     UpdateWindow(info.hwnd);
8865     SetFocus(info.hwnd);
8866
8867     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8868     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8869     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8870
8871     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8872     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8873
8874     flush_events();
8875     flush_sequence();
8876
8877     SetLastError(0xdeadbeef);
8878     qstatus = GetQueueStatus(qs_all_input);
8879     if (GetLastError() == ERROR_INVALID_FLAGS)
8880     {
8881         trace("QS_RAWINPUT not supported on this platform\n");
8882         qs_all_input &= ~QS_RAWINPUT;
8883         qs_input &= ~QS_RAWINPUT;
8884     }
8885     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8886
8887     trace("signalling to send message\n");
8888     SetEvent(info.hevent[EV_SENDMSG]);
8889     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8890
8891     /* pass invalid QS_xxxx flags */
8892     SetLastError(0xdeadbeef);
8893     qstatus = GetQueueStatus(0xffffffff);
8894     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8895     if (!qstatus)
8896     {
8897         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8898         qstatus = GetQueueStatus(qs_all_input);
8899     }
8900     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8901        "wrong qstatus %08x\n", qstatus);
8902
8903     msg.message = 0;
8904     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8905     ok(!ret,
8906        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8907         msg.message);
8908     ok_sequence(WmUser, "WmUser", FALSE);
8909
8910     qstatus = GetQueueStatus(qs_all_input);
8911     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8912
8913     keybd_event('N', 0, 0, 0);
8914     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8915     qstatus = GetQueueStatus(qs_all_input);
8916     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8917        "wrong qstatus %08x\n", qstatus);
8918
8919     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8920     qstatus = GetQueueStatus(qs_all_input);
8921     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8922        "wrong qstatus %08x\n", qstatus);
8923
8924     InvalidateRect(info.hwnd, NULL, FALSE);
8925     qstatus = GetQueueStatus(qs_all_input);
8926     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8927        "wrong qstatus %08x\n", qstatus);
8928
8929     trace("signalling to send message\n");
8930     SetEvent(info.hevent[EV_SENDMSG]);
8931     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8932
8933     qstatus = GetQueueStatus(qs_all_input);
8934     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8935        "wrong qstatus %08x\n", qstatus);
8936
8937     msg.message = 0;
8938     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8939     if (ret && msg.message == WM_CHAR)
8940     {
8941         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8942         goto done;
8943     }
8944     ok(!ret,
8945        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8946         msg.message);
8947     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
8948     {
8949         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8950         goto done;
8951     }
8952     ok_sequence(WmUser, "WmUser", FALSE);
8953
8954     qstatus = GetQueueStatus(qs_all_input);
8955     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8956        "wrong qstatus %08x\n", qstatus);
8957
8958     trace("signalling to send message\n");
8959     SetEvent(info.hevent[EV_SENDMSG]);
8960     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8961
8962     qstatus = GetQueueStatus(qs_all_input);
8963     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8964        "wrong qstatus %08x\n", qstatus);
8965
8966     msg.message = 0;
8967     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
8968     ok(!ret,
8969        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8970         msg.message);
8971     ok_sequence(WmUser, "WmUser", FALSE);
8972
8973     qstatus = GetQueueStatus(qs_all_input);
8974     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8975        "wrong qstatus %08x\n", qstatus);
8976
8977     msg.message = 0;
8978     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8979     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8980        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8981        ret, msg.message, msg.wParam);
8982     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8983
8984     qstatus = GetQueueStatus(qs_all_input);
8985     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8986        "wrong qstatus %08x\n", qstatus);
8987
8988     msg.message = 0;
8989     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8990     ok(!ret,
8991        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8992         msg.message);
8993     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8994
8995     qstatus = GetQueueStatus(qs_all_input);
8996     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8997        "wrong qstatus %08x\n", qstatus);
8998
8999     msg.message = 0;
9000     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9001     ok(ret && msg.message == WM_PAINT,
9002        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9003     DispatchMessageA(&msg);
9004     ok_sequence(WmPaint, "WmPaint", FALSE);
9005
9006     qstatus = GetQueueStatus(qs_all_input);
9007     ok(qstatus == MAKELONG(0, QS_KEY),
9008        "wrong qstatus %08x\n", qstatus);
9009
9010     msg.message = 0;
9011     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9012     ok(!ret,
9013        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9014         msg.message);
9015     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9016
9017     qstatus = GetQueueStatus(qs_all_input);
9018     ok(qstatus == MAKELONG(0, QS_KEY),
9019        "wrong qstatus %08x\n", qstatus);
9020
9021     trace("signalling to send message\n");
9022     SetEvent(info.hevent[EV_SENDMSG]);
9023     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9024
9025     qstatus = GetQueueStatus(qs_all_input);
9026     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9027        "wrong qstatus %08x\n", qstatus);
9028
9029     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9030
9031     qstatus = GetQueueStatus(qs_all_input);
9032     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9033        "wrong qstatus %08x\n", qstatus);
9034
9035     msg.message = 0;
9036     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9037     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9038        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9039        ret, msg.message, msg.wParam);
9040     ok_sequence(WmUser, "WmUser", FALSE);
9041
9042     qstatus = GetQueueStatus(qs_all_input);
9043     ok(qstatus == MAKELONG(0, QS_KEY),
9044        "wrong qstatus %08x\n", qstatus);
9045
9046     msg.message = 0;
9047     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9048     ok(!ret,
9049        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9050         msg.message);
9051     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9052
9053     qstatus = GetQueueStatus(qs_all_input);
9054     ok(qstatus == MAKELONG(0, QS_KEY),
9055        "wrong qstatus %08x\n", qstatus);
9056
9057     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9058
9059     qstatus = GetQueueStatus(qs_all_input);
9060     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9061        "wrong qstatus %08x\n", qstatus);
9062
9063     trace("signalling to send message\n");
9064     SetEvent(info.hevent[EV_SENDMSG]);
9065     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9066
9067     qstatus = GetQueueStatus(qs_all_input);
9068     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9069        "wrong qstatus %08x\n", qstatus);
9070
9071     msg.message = 0;
9072     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9073     ok(!ret,
9074        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9075         msg.message);
9076     ok_sequence(WmUser, "WmUser", FALSE);
9077
9078     qstatus = GetQueueStatus(qs_all_input);
9079     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9080        "wrong qstatus %08x\n", qstatus);
9081
9082     msg.message = 0;
9083     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9084         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9085     else /* workaround for a missing QS_RAWINPUT support */
9086         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9087     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9088        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9089        ret, msg.message, msg.wParam);
9090     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9091
9092     qstatus = GetQueueStatus(qs_all_input);
9093     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9094        "wrong qstatus %08x\n", qstatus);
9095
9096     msg.message = 0;
9097     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9098         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9099     else /* workaround for a missing QS_RAWINPUT support */
9100         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9101     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9102        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9103        ret, msg.message, msg.wParam);
9104     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9105
9106     qstatus = GetQueueStatus(qs_all_input);
9107     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9108        "wrong qstatus %08x\n", qstatus);
9109
9110     msg.message = 0;
9111     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9112     ok(!ret,
9113        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9114         msg.message);
9115     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9116
9117     qstatus = GetQueueStatus(qs_all_input);
9118     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9119        "wrong qstatus %08x\n", qstatus);
9120
9121     msg.message = 0;
9122     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9123     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9124        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9125        ret, msg.message, msg.wParam);
9126     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9127
9128     qstatus = GetQueueStatus(qs_all_input);
9129     ok(qstatus == 0,
9130        "wrong qstatus %08x\n", qstatus);
9131
9132     msg.message = 0;
9133     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9134     ok(!ret,
9135        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9136         msg.message);
9137     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9138
9139     qstatus = GetQueueStatus(qs_all_input);
9140     ok(qstatus == 0,
9141        "wrong qstatus %08x\n", qstatus);
9142
9143     /* test whether presence of the quit flag in the queue affects
9144      * the queue state
9145      */
9146     PostQuitMessage(0x1234abcd);
9147
9148     qstatus = GetQueueStatus(qs_all_input);
9149     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9150        "wrong qstatus %08x\n", qstatus);
9151
9152     PostMessageA(info.hwnd, WM_USER, 0, 0);
9153
9154     qstatus = GetQueueStatus(qs_all_input);
9155     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9156        "wrong qstatus %08x\n", qstatus);
9157
9158     msg.message = 0;
9159     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9160     ok(ret && msg.message == WM_USER,
9161        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9162     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9163
9164     qstatus = GetQueueStatus(qs_all_input);
9165     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9166        "wrong qstatus %08x\n", qstatus);
9167
9168     msg.message = 0;
9169     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9170     ok(ret && msg.message == WM_QUIT,
9171        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9172     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9173     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9174     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9175
9176     qstatus = GetQueueStatus(qs_all_input);
9177 todo_wine {
9178     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9179        "wrong qstatus %08x\n", qstatus);
9180 }
9181
9182     msg.message = 0;
9183     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9184     ok(!ret,
9185        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9186         msg.message);
9187     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9188
9189     qstatus = GetQueueStatus(qs_all_input);
9190     ok(qstatus == 0,
9191        "wrong qstatus %08x\n", qstatus);
9192
9193     /* some GetMessage tests */
9194
9195     keybd_event('N', 0, 0, 0);
9196     qstatus = GetQueueStatus(qs_all_input);
9197     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9198
9199     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9200     qstatus = GetQueueStatus(qs_all_input);
9201     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9202
9203     if (qstatus)
9204     {
9205         ret = GetMessageA( &msg, 0, 0, 0 );
9206         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9207            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9208            ret, msg.message, msg.wParam);
9209         qstatus = GetQueueStatus(qs_all_input);
9210         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9211     }
9212
9213     if (qstatus)
9214     {
9215         ret = GetMessageA( &msg, 0, 0, 0 );
9216         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9217            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9218            ret, msg.message, msg.wParam);
9219         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9220         qstatus = GetQueueStatus(qs_all_input);
9221         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9222     }
9223
9224     keybd_event('N', 0, 0, 0);
9225     qstatus = GetQueueStatus(qs_all_input);
9226     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9227
9228     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9229     qstatus = GetQueueStatus(qs_all_input);
9230     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9231
9232     if (qstatus & (QS_KEY << 16))
9233     {
9234         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9235         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9236            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9237            ret, msg.message, msg.wParam);
9238         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9239         qstatus = GetQueueStatus(qs_all_input);
9240         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9241     }
9242
9243     if (qstatus)
9244     {
9245         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9246         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9247            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9248            ret, msg.message, msg.wParam);
9249         qstatus = GetQueueStatus(qs_all_input);
9250         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9251     }
9252
9253     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9254     qstatus = GetQueueStatus(qs_all_input);
9255     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9256
9257     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9258     qstatus = GetQueueStatus(qs_all_input);
9259     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9260
9261     trace("signalling to send message\n");
9262     SetEvent(info.hevent[EV_SENDMSG]);
9263     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9264     qstatus = GetQueueStatus(qs_all_input);
9265     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9266        "wrong qstatus %08x\n", qstatus);
9267
9268     if (qstatus & (QS_KEY << 16))
9269     {
9270         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9271         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9272            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9273            ret, msg.message, msg.wParam);
9274         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9275         qstatus = GetQueueStatus(qs_all_input);
9276         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9277     }
9278
9279     if (qstatus)
9280     {
9281         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9282         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9283            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9284            ret, msg.message, msg.wParam);
9285         qstatus = GetQueueStatus(qs_all_input);
9286         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9287     }
9288 done:
9289     trace("signalling to exit\n");
9290     SetEvent(info.hevent[EV_STOP]);
9291
9292     WaitForSingleObject(hthread, INFINITE);
9293
9294     CloseHandle(hthread);
9295     CloseHandle(info.hevent[0]);
9296     CloseHandle(info.hevent[1]);
9297     CloseHandle(info.hevent[2]);
9298
9299     DestroyWindow(info.hwnd);
9300 }
9301
9302 static void wait_move_event(HWND hwnd, int x, int y)
9303 {
9304     MSG msg;
9305     DWORD time;
9306     BOOL  ret;
9307     int go = 0;
9308
9309     time = GetTickCount();
9310     while (GetTickCount() - time < 200 && !go) {
9311         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9312         go  = ret && msg.pt.x > x && msg.pt.y > y;
9313         if (ret && !go) PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9314     }
9315 }
9316
9317 #define STEP 20
9318 static void test_PeekMessage2(void)
9319 {
9320     HWND hwnd;
9321     BOOL ret;
9322     MSG msg;
9323     UINT message;
9324     DWORD time1, time2, time3;
9325     int x1, y1, x2, y2, x3, y3;
9326     POINT pos;
9327
9328     time1 = time2 = time3 = 0;
9329     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9330
9331     /* Initialise window and make sure it is ready for events */
9332     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9333                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9334     assert(hwnd);
9335     trace("Window for test_PeekMessage2 %p\n", hwnd);
9336     ShowWindow(hwnd, SW_SHOW);
9337     UpdateWindow(hwnd);
9338     SetFocus(hwnd);
9339     GetCursorPos(&pos);
9340     SetCursorPos(100, 100);
9341     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9342     flush_events();
9343
9344     /* Do initial mousemove, wait until we can see it
9345        and then do our test peek with PM_NOREMOVE. */
9346     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9347     wait_move_event(hwnd, 80, 80);
9348
9349     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9350     ok(ret, "no message available\n");
9351     if (ret) {
9352         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9353         message = msg.message;
9354         time1 = msg.time;
9355         x1 = msg.pt.x;
9356         y1 = msg.pt.y;
9357         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9358         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9359     }
9360
9361     /* Allow time to advance a bit, and then simulate the user moving their
9362      * mouse around. After that we peek again with PM_NOREMOVE.
9363      * Although the previous mousemove message was never removed, the
9364      * mousemove we now peek should reflect the recent mouse movements
9365      * because the input queue will merge the move events. */
9366     Sleep(2);
9367     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9368     wait_move_event(hwnd, x1, y1);
9369
9370     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9371     ok(ret, "no message available\n");
9372     if (ret) {
9373         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9374         message = msg.message;
9375         time2 = msg.time;
9376         x2 = msg.pt.x;
9377         y2 = msg.pt.y;
9378         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9379         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9380         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9381         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9382     }
9383
9384     /* Have another go, to drive the point home */
9385     Sleep(2);
9386     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9387     wait_move_event(hwnd, x2, y2);
9388
9389     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9390     ok(ret, "no message available\n");
9391     if (ret) {
9392         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9393         message = msg.message;
9394         time3 = msg.time;
9395         x3 = msg.pt.x;
9396         y3 = msg.pt.y;
9397         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9398         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9399         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9400     }
9401
9402     DestroyWindow(hwnd);
9403     SetCursorPos(pos.x, pos.y);
9404     flush_events();
9405 }
9406
9407 static void test_quit_message(void)
9408 {
9409     MSG msg;
9410     BOOL ret;
9411
9412     /* test using PostQuitMessage */
9413     flush_events();
9414     PostQuitMessage(0xbeef);
9415
9416     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9417     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9418     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9419     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9420
9421     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9422     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9423
9424     ret = GetMessage(&msg, NULL, 0, 0);
9425     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9426     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9427
9428     /* note: WM_QUIT message received after WM_USER message */
9429     ret = GetMessage(&msg, NULL, 0, 0);
9430     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9431     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9432     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9433
9434     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9435     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9436
9437     /* now test with PostThreadMessage - different behaviour! */
9438     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9439
9440     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9441     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9442     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9443     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9444
9445     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9446     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9447
9448     /* note: we receive the WM_QUIT message first this time */
9449     ret = GetMessage(&msg, NULL, 0, 0);
9450     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9451     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9452     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9453
9454     ret = GetMessage(&msg, NULL, 0, 0);
9455     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9456     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9457 }
9458
9459 static const struct message WmMouseHoverSeq[] = {
9460     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9461     { WM_MOUSEACTIVATE, sent|optional },
9462     { WM_TIMER, sent|optional }, /* XP sends it */
9463     { WM_SYSTIMER, sent },
9464     { WM_MOUSEHOVER, sent|wparam, 0 },
9465     { 0 }
9466 };
9467
9468 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9469 {
9470     MSG msg;
9471     DWORD start_ticks, end_ticks;
9472
9473     start_ticks = GetTickCount();
9474     /* add some deviation (50%) to cover not expected delays */
9475     start_ticks += timeout / 2;
9476
9477     do
9478     {
9479         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9480         {
9481             /* Timer proc messages are not dispatched to the window proc,
9482              * and therefore not logged.
9483              */
9484             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9485             {
9486                 struct recvd_message s_msg;
9487
9488                 s_msg.hwnd = msg.hwnd;
9489                 s_msg.message = msg.message;
9490                 s_msg.flags = sent|wparam|lparam;
9491                 s_msg.wParam = msg.wParam;
9492                 s_msg.lParam = msg.lParam;
9493                 s_msg.descr = "msg_loop";
9494                 add_message(&s_msg);
9495             }
9496             DispatchMessage(&msg);
9497         }
9498
9499         end_ticks = GetTickCount();
9500
9501         /* inject WM_MOUSEMOVE to see how it changes tracking */
9502         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9503         {
9504             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9505             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9506
9507             inject_mouse_move = FALSE;
9508         }
9509     } while (start_ticks + timeout >= end_ticks);
9510 }
9511
9512 static void test_TrackMouseEvent(void)
9513 {
9514     TRACKMOUSEEVENT tme;
9515     BOOL ret;
9516     HWND hwnd, hchild;
9517     RECT rc_parent, rc_child;
9518     UINT default_hover_time, hover_width = 0, hover_height = 0;
9519
9520 #define track_hover(track_hwnd, track_hover_time) \
9521     tme.cbSize = sizeof(tme); \
9522     tme.dwFlags = TME_HOVER; \
9523     tme.hwndTrack = track_hwnd; \
9524     tme.dwHoverTime = track_hover_time; \
9525     SetLastError(0xdeadbeef); \
9526     ret = pTrackMouseEvent(&tme); \
9527     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9528
9529 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9530     tme.cbSize = sizeof(tme); \
9531     tme.dwFlags = TME_QUERY; \
9532     tme.hwndTrack = (HWND)0xdeadbeef; \
9533     tme.dwHoverTime = 0xdeadbeef; \
9534     SetLastError(0xdeadbeef); \
9535     ret = pTrackMouseEvent(&tme); \
9536     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9537     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9538     ok(tme.dwFlags == (expected_track_flags), \
9539        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9540     ok(tme.hwndTrack == (expected_track_hwnd), \
9541        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9542     ok(tme.dwHoverTime == (expected_hover_time), \
9543        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9544
9545 #define track_hover_cancel(track_hwnd) \
9546     tme.cbSize = sizeof(tme); \
9547     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9548     tme.hwndTrack = track_hwnd; \
9549     tme.dwHoverTime = 0xdeadbeef; \
9550     SetLastError(0xdeadbeef); \
9551     ret = pTrackMouseEvent(&tme); \
9552     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9553
9554     default_hover_time = 0xdeadbeef;
9555     SetLastError(0xdeadbeef);
9556     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9557     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9558        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9559     if (!ret) default_hover_time = 400;
9560     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9561
9562     SetLastError(0xdeadbeef);
9563     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9564     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9565        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9566     if (!ret) hover_width = 4;
9567     SetLastError(0xdeadbeef);
9568     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9569     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9570        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9571     if (!ret) hover_height = 4;
9572     trace("hover rect is %u x %d\n", hover_width, hover_height);
9573
9574     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9575                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9576                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9577                           NULL, NULL, 0);
9578     assert(hwnd);
9579
9580     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9581                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9582                           50, 50, 200, 200, hwnd,
9583                           NULL, NULL, 0);
9584     assert(hchild);
9585
9586     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9587     flush_events();
9588     flush_sequence();
9589
9590     tme.cbSize = 0;
9591     tme.dwFlags = TME_QUERY;
9592     tme.hwndTrack = (HWND)0xdeadbeef;
9593     tme.dwHoverTime = 0xdeadbeef;
9594     SetLastError(0xdeadbeef);
9595     ret = pTrackMouseEvent(&tme);
9596     ok(!ret, "TrackMouseEvent should fail\n");
9597     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9598        "not expected error %u\n", GetLastError());
9599
9600     tme.cbSize = sizeof(tme);
9601     tme.dwFlags = TME_HOVER;
9602     tme.hwndTrack = (HWND)0xdeadbeef;
9603     tme.dwHoverTime = 0xdeadbeef;
9604     SetLastError(0xdeadbeef);
9605     ret = pTrackMouseEvent(&tme);
9606     ok(!ret, "TrackMouseEvent should fail\n");
9607     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9608        "not expected error %u\n", GetLastError());
9609
9610     tme.cbSize = sizeof(tme);
9611     tme.dwFlags = TME_HOVER | TME_CANCEL;
9612     tme.hwndTrack = (HWND)0xdeadbeef;
9613     tme.dwHoverTime = 0xdeadbeef;
9614     SetLastError(0xdeadbeef);
9615     ret = pTrackMouseEvent(&tme);
9616     ok(!ret, "TrackMouseEvent should fail\n");
9617     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9618        "not expected error %u\n", GetLastError());
9619
9620     GetWindowRect(hwnd, &rc_parent);
9621     GetWindowRect(hchild, &rc_child);
9622     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9623
9624     /* Process messages so that the system updates its internal current
9625      * window and hittest, otherwise TrackMouseEvent calls don't have any
9626      * effect.
9627      */
9628     flush_events();
9629     flush_sequence();
9630
9631     track_query(0, NULL, 0);
9632     track_hover(hchild, 0);
9633     track_query(0, NULL, 0);
9634
9635     flush_events();
9636     flush_sequence();
9637
9638     track_hover(hwnd, 0);
9639     track_query(TME_HOVER, hwnd, default_hover_time);
9640
9641     pump_msg_loop_timeout(default_hover_time, FALSE);
9642     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9643
9644     track_query(0, NULL, 0);
9645
9646     track_hover(hwnd, HOVER_DEFAULT);
9647     track_query(TME_HOVER, hwnd, default_hover_time);
9648
9649     Sleep(default_hover_time / 2);
9650     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9651     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9652
9653     track_query(TME_HOVER, hwnd, default_hover_time);
9654
9655     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9656     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9657
9658     track_query(0, NULL, 0);
9659
9660     track_hover(hwnd, HOVER_DEFAULT);
9661     track_query(TME_HOVER, hwnd, default_hover_time);
9662
9663     pump_msg_loop_timeout(default_hover_time, TRUE);
9664     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9665
9666     track_query(0, NULL, 0);
9667
9668     track_hover(hwnd, HOVER_DEFAULT);
9669     track_query(TME_HOVER, hwnd, default_hover_time);
9670     track_hover_cancel(hwnd);
9671
9672     DestroyWindow(hwnd);
9673
9674 #undef track_hover
9675 #undef track_query
9676 #undef track_hover_cancel
9677 }
9678
9679
9680 static const struct message WmSetWindowRgn[] = {
9681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9682     { WM_NCCALCSIZE, sent|wparam, 1 },
9683     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9684     { WM_GETTEXT, sent|defwinproc|optional },
9685     { WM_ERASEBKGND, sent|optional },
9686     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9687     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9688     { 0 }
9689 };
9690
9691 static const struct message WmSetWindowRgn_no_redraw[] = {
9692     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9693     { WM_NCCALCSIZE, sent|wparam, 1 },
9694     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9695     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9696     { 0 }
9697 };
9698
9699 static const struct message WmSetWindowRgn_clear[] = {
9700     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9701     { WM_NCCALCSIZE, sent|wparam, 1 },
9702     { WM_NCPAINT, sent|optional },
9703     { WM_GETTEXT, sent|defwinproc|optional },
9704     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9705     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9706     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9707     { WM_NCPAINT, sent|optional },
9708     { WM_GETTEXT, sent|defwinproc|optional },
9709     { WM_ERASEBKGND, sent|optional },
9710     { WM_WINDOWPOSCHANGING, sent|optional },
9711     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9712     { WM_NCPAINT, sent|optional },
9713     { WM_GETTEXT, sent|defwinproc|optional },
9714     { WM_ERASEBKGND, sent|optional },
9715     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9716     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9717     { WM_NCPAINT, sent|optional },
9718     { WM_GETTEXT, sent|defwinproc|optional },
9719     { WM_ERASEBKGND, sent|optional },
9720     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9721     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9722     { 0 }
9723 };
9724
9725 static void test_SetWindowRgn(void)
9726 {
9727     HRGN hrgn;
9728     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9729                                 100, 100, 200, 200, 0, 0, 0, NULL);
9730     ok( hwnd != 0, "Failed to create overlapped window\n" );
9731
9732     ShowWindow( hwnd, SW_SHOW );
9733     UpdateWindow( hwnd );
9734     flush_events();
9735     flush_sequence();
9736
9737     trace("testing SetWindowRgn\n");
9738     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9739     SetWindowRgn( hwnd, hrgn, TRUE );
9740     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9741
9742     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9743     SetWindowRgn( hwnd, hrgn, FALSE );
9744     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9745
9746     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9747     SetWindowRgn( hwnd, hrgn, TRUE );
9748     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9749
9750     SetWindowRgn( hwnd, 0, TRUE );
9751     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9752
9753     DestroyWindow( hwnd );
9754 }
9755
9756 /*************************** ShowWindow() test ******************************/
9757 static const struct message WmShowNormal[] = {
9758     { WM_SHOWWINDOW, sent|wparam, 1 },
9759     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9760     { HCBT_ACTIVATE, hook },
9761     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9762     { HCBT_SETFOCUS, hook },
9763     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9764     { 0 }
9765 };
9766 static const struct message WmShow[] = {
9767     { WM_SHOWWINDOW, sent|wparam, 1 },
9768     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9769     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9770     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9771     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9772     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9773     { 0 }
9774 };
9775 static const struct message WmShowNoActivate_1[] = {
9776     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9777     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9778     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9779     { WM_MOVE, sent|defwinproc|optional },
9780     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9781     { 0 }
9782 };
9783 static const struct message WmShowNoActivate_2[] = {
9784     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9785     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9786     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9787     { WM_MOVE, sent|defwinproc },
9788     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9789     { HCBT_SETFOCUS, hook|optional },
9790     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9791     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9792     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9793     { 0 }
9794 };
9795 static const struct message WmShowNA_1[] = {
9796     { WM_SHOWWINDOW, sent|wparam, 1 },
9797     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9798     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9799     { 0 }
9800 };
9801 static const struct message WmShowNA_2[] = {
9802     { WM_SHOWWINDOW, sent|wparam, 1 },
9803     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9804     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9805     { 0 }
9806 };
9807 static const struct message WmRestore_1[] = {
9808     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9809     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9810     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9811     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9812     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9813     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9814     { WM_MOVE, sent|defwinproc },
9815     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9816     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9817     { 0 }
9818 };
9819 static const struct message WmRestore_2[] = {
9820     { WM_SHOWWINDOW, sent|wparam, 1 },
9821     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9822     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9823     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9824     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9825     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9826     { 0 }
9827 };
9828 static const struct message WmRestore_3[] = {
9829     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9830     { WM_GETMINMAXINFO, sent },
9831     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9832     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9833     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9834     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9835     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9836     { WM_MOVE, sent|defwinproc },
9837     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9838     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9839     { 0 }
9840 };
9841 static const struct message WmRestore_4[] = {
9842     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9843     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9844     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9845     { WM_MOVE, sent|defwinproc|optional },
9846     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9847     { 0 }
9848 };
9849 static const struct message WmRestore_5[] = {
9850     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9851     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9852     { HCBT_ACTIVATE, hook|optional },
9853     { HCBT_SETFOCUS, hook|optional },
9854     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9855     { WM_MOVE, sent|defwinproc|optional },
9856     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9857     { 0 }
9858 };
9859 static const struct message WmHide_1[] = {
9860     { WM_SHOWWINDOW, sent|wparam, 0 },
9861     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9862     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9863     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9864     { 0 }
9865 };
9866 static const struct message WmHide_2[] = {
9867     { WM_SHOWWINDOW, sent|wparam, 0 },
9868     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9869     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9870     { 0 }
9871 };
9872 static const struct message WmHide_3[] = {
9873     { WM_SHOWWINDOW, sent|wparam, 0 },
9874     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9875     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9876     { HCBT_SETFOCUS, hook|optional },
9877     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9878     { 0 }
9879 };
9880 static const struct message WmShowMinimized_1[] = {
9881     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9882     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9883     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9884     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9885     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9886     { WM_MOVE, sent|defwinproc },
9887     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9888     { 0 }
9889 };
9890 static const struct message WmMinimize_1[] = {
9891     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9892     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9893     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9894     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9895     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9896     { WM_MOVE, sent|defwinproc },
9897     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9898     { 0 }
9899 };
9900 static const struct message WmMinimize_2[] = {
9901     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9902     { HCBT_SETFOCUS, hook|optional },
9903     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9904     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9905     { WM_MOVE, sent|defwinproc },
9906     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9907     { 0 }
9908 };
9909 static const struct message WmMinimize_3[] = {
9910     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9911     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9912     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9913     { WM_MOVE, sent|defwinproc },
9914     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9915     { 0 }
9916 };
9917 static const struct message WmShowMinNoActivate[] = {
9918     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9920     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9921     { 0 }
9922 };
9923 static const struct message WmMinMax_1[] = {
9924     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9925     { 0 }
9926 };
9927 static const struct message WmMinMax_2[] = {
9928     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9929     { WM_GETMINMAXINFO, sent|optional },
9930     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
9931     { HCBT_ACTIVATE, hook|optional },
9932     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
9933     { HCBT_SETFOCUS, hook|optional },
9934     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9935     { WM_MOVE, sent|defwinproc|optional },
9936     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
9937     { HCBT_SETFOCUS, hook|optional },
9938     { 0 }
9939 };
9940 static const struct message WmMinMax_3[] = {
9941     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9942     { 0 }
9943 };
9944 static const struct message WmMinMax_4[] = {
9945     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9946     { 0 }
9947 };
9948 static const struct message WmShowMaximized_1[] = {
9949     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9950     { WM_GETMINMAXINFO, sent },
9951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9952     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9953     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9954     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9955     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9956     { WM_MOVE, sent|defwinproc },
9957     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9958     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9959     { 0 }
9960 };
9961 static const struct message WmShowMaximized_2[] = {
9962     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9963     { WM_GETMINMAXINFO, sent },
9964     { WM_WINDOWPOSCHANGING, sent|optional },
9965     { HCBT_ACTIVATE, hook|optional },
9966     { WM_WINDOWPOSCHANGED, sent|optional },
9967     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9968     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9969     { WM_WINDOWPOSCHANGING, sent },
9970     { HCBT_SETFOCUS, hook|optional },
9971     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9972     { WM_MOVE, sent|defwinproc },
9973     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9974     { HCBT_SETFOCUS, hook|optional },
9975     { 0 }
9976 };
9977 static const struct message WmShowMaximized_3[] = {
9978     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9979     { WM_GETMINMAXINFO, sent },
9980     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9981     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9982     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9983     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9984     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9985     { WM_MOVE, sent|defwinproc|optional },
9986     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9987     { 0 }
9988 };
9989
9990 static void test_ShowWindow(void)
9991 {
9992     /* ShowWindow commands in random order */
9993     static const struct
9994     {
9995         INT cmd; /* ShowWindow command */
9996         LPARAM ret; /* ShowWindow return value */
9997         DWORD style; /* window style after the command */
9998         const struct message *msg; /* message sequence the command produces */
9999         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10000     } sw[] =
10001     {
10002 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10003 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10004 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10005 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10006 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10007 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10008 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10009 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10010 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10011 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10012 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10013 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10014 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10015 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10016 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10017 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10018 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10019 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10020 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10021 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10022 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10023 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10024 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10025 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10026 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10027 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10028 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10029 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10030 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10031 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10032 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10033 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10034 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10035 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10036 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10037 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10038 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10039 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10040 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10041 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10042 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10043 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
10044 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10045 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10046 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10047 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10048 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10049 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10050 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10051 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10052 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10053 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10054 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10055 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10056 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10057 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10058 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10059     };
10060     HWND hwnd;
10061     DWORD style;
10062     LPARAM ret;
10063     INT i;
10064
10065 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10066     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10067                           120, 120, 90, 90,
10068                           0, 0, 0, NULL);
10069     assert(hwnd);
10070
10071     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10072     ok(style == 0, "expected style 0, got %08x\n", style);
10073
10074     flush_events();
10075     flush_sequence();
10076
10077     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10078     {
10079         static const char * const sw_cmd_name[13] =
10080         {
10081             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10082             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10083             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10084             "SW_NORMALNA" /* 0xCC */
10085         };
10086         char comment[64];
10087         INT idx; /* index into the above array of names */
10088
10089         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10090
10091         style = GetWindowLong(hwnd, GWL_STYLE);
10092         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10093         ret = ShowWindow(hwnd, sw[i].cmd);
10094         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10095         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10096         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10097
10098         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10099         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10100
10101         flush_events();
10102         flush_sequence();
10103     }
10104
10105     DestroyWindow(hwnd);
10106 }
10107
10108 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10109 {
10110     struct recvd_message msg;
10111
10112     switch (message)
10113     {
10114     case WM_GETICON:
10115     case WM_GETOBJECT:
10116         return 0;  /* ignore them */
10117     }
10118
10119     msg.hwnd = hwnd;
10120     msg.message = message;
10121     msg.flags = sent|wparam|lparam;
10122     msg.wParam = wParam;
10123     msg.lParam = lParam;
10124     msg.descr = "dialog";
10125     add_message(&msg);
10126
10127     /* calling DefDlgProc leads to a recursion under XP */
10128
10129     switch (message)
10130     {
10131     case WM_INITDIALOG:
10132     case WM_GETDLGCODE:
10133         return 0;
10134     }
10135     return 1;
10136 }
10137
10138 static const struct message WmDefDlgSetFocus_1[] = {
10139     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10140     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10141     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10142     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10143     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10144     { HCBT_SETFOCUS, hook },
10145     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10146     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10147     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10148     { WM_SETFOCUS, sent|wparam, 0 },
10149     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10150     { WM_CTLCOLOREDIT, sent },
10151     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10152     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10153     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10154     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10155     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10156     { 0 }
10157 };
10158 static const struct message WmDefDlgSetFocus_2[] = {
10159     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10160     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10161     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10162     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10163     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10164     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10165     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10166     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10167     { 0 }
10168 };
10169 /* Creation of a dialog */
10170 static const struct message WmCreateDialogParamSeq_1[] = {
10171     { HCBT_CREATEWND, hook },
10172     { WM_NCCREATE, sent },
10173     { WM_NCCALCSIZE, sent|wparam, 0 },
10174     { WM_CREATE, sent },
10175     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10176     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10177     { WM_MOVE, sent },
10178     { WM_SETFONT, sent },
10179     { WM_INITDIALOG, sent },
10180     { WM_CHANGEUISTATE, sent|optional },
10181     { 0 }
10182 };
10183 /* Creation of a dialog */
10184 static const struct message WmCreateDialogParamSeq_2[] = {
10185     { HCBT_CREATEWND, hook },
10186     { WM_NCCREATE, sent },
10187     { WM_NCCALCSIZE, sent|wparam, 0 },
10188     { WM_CREATE, sent },
10189     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10190     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10191     { WM_MOVE, sent },
10192     { WM_CHANGEUISTATE, sent|optional },
10193     { 0 }
10194 };
10195
10196 static void test_dialog_messages(void)
10197 {
10198     WNDCLASS cls;
10199     HWND hdlg, hedit1, hedit2, hfocus;
10200     LRESULT ret;
10201
10202 #define set_selection(hctl, start, end) \
10203     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10204     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10205
10206 #define check_selection(hctl, start, end) \
10207     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10208     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10209
10210     subclass_edit();
10211
10212     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10213                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10214                           0, 0, 100, 100, 0, 0, 0, NULL);
10215     ok(hdlg != 0, "Failed to create custom dialog window\n");
10216
10217     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10218                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10219                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10220     ok(hedit1 != 0, "Failed to create edit control\n");
10221     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10222                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10223                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10224     ok(hedit2 != 0, "Failed to create edit control\n");
10225
10226     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10227     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10228
10229     hfocus = GetFocus();
10230     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10231
10232     SetFocus(hedit2);
10233     hfocus = GetFocus();
10234     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10235
10236     check_selection(hedit1, 0, 0);
10237     check_selection(hedit2, 0, 0);
10238
10239     set_selection(hedit2, 0, -1);
10240     check_selection(hedit2, 0, 3);
10241
10242     SetFocus(0);
10243     hfocus = GetFocus();
10244     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10245
10246     flush_sequence();
10247     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10248     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10249     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10250
10251     hfocus = GetFocus();
10252     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10253
10254     check_selection(hedit1, 0, 5);
10255     check_selection(hedit2, 0, 3);
10256
10257     flush_sequence();
10258     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10259     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10260     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10261
10262     hfocus = GetFocus();
10263     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10264
10265     check_selection(hedit1, 0, 5);
10266     check_selection(hedit2, 0, 3);
10267
10268     EndDialog(hdlg, 0);
10269     DestroyWindow(hedit1);
10270     DestroyWindow(hedit2);
10271     DestroyWindow(hdlg);
10272     flush_sequence();
10273
10274 #undef set_selection
10275 #undef check_selection
10276
10277     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10278     cls.lpszClassName = "MyDialogClass";
10279     cls.hInstance = GetModuleHandle(0);
10280     /* need a cast since a dlgproc is used as a wndproc */
10281     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10282     if (!RegisterClass(&cls)) assert(0);
10283
10284     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10285     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10286     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10287     EndDialog(hdlg, 0);
10288     DestroyWindow(hdlg);
10289     flush_sequence();
10290
10291     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10292     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10293     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10294     EndDialog(hdlg, 0);
10295     DestroyWindow(hdlg);
10296     flush_sequence();
10297
10298     UnregisterClass(cls.lpszClassName, cls.hInstance);
10299 }
10300
10301 static void test_nullCallback(void)
10302 {
10303     HWND hwnd;
10304
10305     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10306                            100, 100, 200, 200, 0, 0, 0, NULL);
10307     ok (hwnd != 0, "Failed to create overlapped window\n");
10308
10309     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10310     flush_events();
10311     DestroyWindow(hwnd);
10312 }
10313
10314 /* SetActiveWindow( 0 ) hwnd visible */
10315 static const struct message SetActiveWindowSeq0[] =
10316 {
10317     { HCBT_ACTIVATE, hook },
10318     { WM_NCACTIVATE, sent|wparam, 0 },
10319     { WM_GETTEXT, sent|defwinproc|optional },
10320     { WM_ACTIVATE, sent|wparam, 0 },
10321     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10322     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10323     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10324     { WM_NCACTIVATE, sent|wparam, 1 },
10325     { WM_GETTEXT, sent|defwinproc|optional },
10326     { WM_ACTIVATE, sent|wparam, 1 },
10327     { HCBT_SETFOCUS, hook },
10328     { WM_KILLFOCUS, sent|defwinproc },
10329     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10330     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10331     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10332     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10333     { WM_SETFOCUS, sent|defwinproc },
10334     { WM_GETTEXT, sent|optional },
10335     { 0 }
10336 };
10337 /* SetActiveWindow( hwnd ) hwnd visible */
10338 static const struct message SetActiveWindowSeq1[] =
10339 {
10340     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10341     { 0 }
10342 };
10343 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10344 static const struct message SetActiveWindowSeq2[] =
10345 {
10346     { HCBT_ACTIVATE, hook },
10347     { WM_NCACTIVATE, sent|wparam, 0 },
10348     { WM_GETTEXT, sent|defwinproc|optional },
10349     { WM_ACTIVATE, sent|wparam, 0 },
10350     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10351     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10352     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10353     { WM_NCPAINT, sent|optional },
10354     { WM_GETTEXT, sent|defwinproc|optional },
10355     { WM_ERASEBKGND, sent|optional },
10356     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10357     { WM_NCACTIVATE, sent|wparam, 1 },
10358     { WM_GETTEXT, sent|defwinproc|optional },
10359     { WM_ACTIVATE, sent|wparam, 1 },
10360     { HCBT_SETFOCUS, hook },
10361     { WM_KILLFOCUS, sent|defwinproc },
10362     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10363     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10364     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10365     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10366     { WM_SETFOCUS, sent|defwinproc },
10367     { WM_GETTEXT, sent|optional },
10368     { 0 }
10369 };
10370
10371 /* SetActiveWindow( hwnd ) hwnd not visible */
10372 static const struct message SetActiveWindowSeq3[] =
10373 {
10374     { HCBT_ACTIVATE, hook },
10375     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10376     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10377     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10378     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10379     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10380     { WM_ACTIVATEAPP, sent|wparam, 1 },
10381     { WM_ACTIVATEAPP, sent|wparam, 1 },
10382     { WM_NCACTIVATE, sent|wparam, 1 },
10383     { WM_ACTIVATE, sent|wparam, 1 },
10384     { HCBT_SETFOCUS, hook },
10385     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10386     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10387     { WM_SETFOCUS, sent|defwinproc },
10388     { 0 }
10389 };
10390 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10391 static const struct message SetActiveWindowSeq4[] =
10392 {
10393     { HCBT_ACTIVATE, hook },
10394     { WM_NCACTIVATE, sent|wparam, 0 },
10395     { WM_GETTEXT, sent|defwinproc|optional },
10396     { WM_ACTIVATE, sent|wparam, 0 },
10397     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10398     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10399     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10400     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10401     { WM_NCACTIVATE, sent|wparam, 1 },
10402     { WM_GETTEXT, sent|defwinproc|optional },
10403     { WM_ACTIVATE, sent|wparam, 1 },
10404     { HCBT_SETFOCUS, hook },
10405     { WM_KILLFOCUS, sent|defwinproc },
10406     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10407     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10408     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10409     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10410     { WM_SETFOCUS, sent|defwinproc },
10411     { 0 }
10412 };
10413
10414
10415 static void test_SetActiveWindow(void)
10416 {
10417     HWND hwnd, popup, ret;
10418
10419     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10420                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10421                            100, 100, 200, 200, 0, 0, 0, NULL);
10422
10423     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10424                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10425                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10426
10427     ok(hwnd != 0, "Failed to create overlapped window\n");
10428     ok(popup != 0, "Failed to create popup window\n");
10429     SetForegroundWindow( popup );
10430     flush_sequence();
10431
10432     trace("SetActiveWindow(0)\n");
10433     ret = SetActiveWindow(0);
10434     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10435     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10436     flush_sequence();
10437
10438     trace("SetActiveWindow(hwnd), hwnd visible\n");
10439     ret = SetActiveWindow(hwnd);
10440     todo_wine
10441     {
10442         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10443     }
10444     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10445     flush_sequence();
10446
10447     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10448     ret = SetActiveWindow(popup);
10449     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10450     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10451     flush_sequence();
10452
10453     ShowWindow(hwnd, SW_HIDE);
10454     ShowWindow(popup, SW_HIDE);
10455     flush_sequence();
10456
10457     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10458     ret = SetActiveWindow(hwnd);
10459     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10460     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10461     flush_sequence();
10462
10463     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10464     ret = SetActiveWindow(popup);
10465     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10466     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10467     flush_sequence();
10468
10469     trace("done\n");
10470
10471     DestroyWindow(hwnd);
10472 }
10473
10474 static const struct message SetForegroundWindowSeq[] =
10475 {
10476     { WM_NCACTIVATE, sent|wparam, 0 },
10477     { WM_GETTEXT, sent|defwinproc|optional },
10478     { WM_ACTIVATE, sent|wparam, 0 },
10479     { WM_ACTIVATEAPP, sent|wparam, 0 },
10480     { WM_KILLFOCUS, sent },
10481     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10482     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10483     { 0 }
10484 };
10485
10486 static void test_SetForegroundWindow(void)
10487 {
10488     HWND hwnd;
10489
10490     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10491                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10492                            100, 100, 200, 200, 0, 0, 0, NULL);
10493     ok (hwnd != 0, "Failed to create overlapped window\n");
10494     flush_sequence();
10495
10496     trace("SetForegroundWindow( 0 )\n");
10497     SetForegroundWindow( 0 );
10498     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10499     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10500     SetForegroundWindow( GetDesktopWindow() );
10501     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10502                                         "foreground top level window", FALSE);
10503     trace("done\n");
10504
10505     DestroyWindow(hwnd);
10506 }
10507
10508 static void test_dbcs_wm_char(void)
10509 {
10510     BYTE dbch[2];
10511     WCHAR wch, bad_wch;
10512     HWND hwnd, hwnd2;
10513     MSG msg;
10514     DWORD time;
10515     POINT pt;
10516     DWORD_PTR res;
10517     CPINFOEXA cpinfo;
10518     UINT i, j, k;
10519     struct message wmCharSeq[2];
10520
10521     if (!pGetCPInfoExA)
10522     {
10523         skip("GetCPInfoExA is not available\n");
10524         return;
10525     }
10526
10527     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10528     if (cpinfo.MaxCharSize != 2)
10529     {
10530         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10531         return;
10532     }
10533
10534     dbch[0] = dbch[1] = 0;
10535     wch = 0;
10536     bad_wch = cpinfo.UnicodeDefaultChar;
10537     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10538         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10539             for (k = 128; k <= 255; k++)
10540             {
10541                 char str[2];
10542                 WCHAR wstr[2];
10543                 str[0] = j;
10544                 str[1] = k;
10545                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10546                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10547                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10548                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10549                 {
10550                     dbch[0] = j;
10551                     dbch[1] = k;
10552                     wch = wstr[0];
10553                     break;
10554                 }
10555             }
10556
10557     if (!wch)
10558     {
10559         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10560         return;
10561     }
10562     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10563            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10564
10565     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10566                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10567     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10568                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10569     ok (hwnd != 0, "Failed to create overlapped window\n");
10570     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10571     flush_sequence();
10572
10573     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10574     wmCharSeq[0].message = WM_CHAR;
10575     wmCharSeq[0].flags = sent|wparam;
10576     wmCharSeq[0].wParam = wch;
10577
10578     /* posted message */
10579     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10580     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10581     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10582     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10583     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10584     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10585     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10586
10587     /* posted thread message */
10588     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10589     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10590     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10591     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10592     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10593     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10594     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10595
10596     /* sent message */
10597     flush_sequence();
10598     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10599     ok_sequence( WmEmptySeq, "no messages", FALSE );
10600     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10601     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10602     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10603
10604     /* sent message with timeout */
10605     flush_sequence();
10606     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10607     ok_sequence( WmEmptySeq, "no messages", FALSE );
10608     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10609     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10610     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10611
10612     /* sent message with timeout and callback */
10613     flush_sequence();
10614     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10615     ok_sequence( WmEmptySeq, "no messages", FALSE );
10616     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10617     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10618     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10619
10620     /* sent message with callback */
10621     flush_sequence();
10622     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10623     ok_sequence( WmEmptySeq, "no messages", FALSE );
10624     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10625     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10626     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10627
10628     /* direct window proc call */
10629     flush_sequence();
10630     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10631     ok_sequence( WmEmptySeq, "no messages", FALSE );
10632     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10633     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10634
10635     /* dispatch message */
10636     msg.hwnd = hwnd;
10637     msg.message = WM_CHAR;
10638     msg.wParam = dbch[0];
10639     msg.lParam = 0;
10640     DispatchMessageA( &msg );
10641     ok_sequence( WmEmptySeq, "no messages", FALSE );
10642     msg.wParam = dbch[1];
10643     DispatchMessageA( &msg );
10644     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10645
10646     /* window handle is irrelevant */
10647     flush_sequence();
10648     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10649     ok_sequence( WmEmptySeq, "no messages", FALSE );
10650     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10651     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10652     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10653
10654     /* interleaved post and send */
10655     flush_sequence();
10656     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10657     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10658     ok_sequence( WmEmptySeq, "no messages", FALSE );
10659     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10660     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10661     ok_sequence( WmEmptySeq, "no messages", FALSE );
10662     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10663     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10664     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10665     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10666     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10667     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10668     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10669
10670     /* interleaved sent message and winproc */
10671     flush_sequence();
10672     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10673     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10674     ok_sequence( WmEmptySeq, "no messages", FALSE );
10675     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10676     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10677     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10678     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10679
10680     /* interleaved winproc and dispatch */
10681     msg.hwnd = hwnd;
10682     msg.message = WM_CHAR;
10683     msg.wParam = dbch[0];
10684     msg.lParam = 0;
10685     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10686     DispatchMessageA( &msg );
10687     ok_sequence( WmEmptySeq, "no messages", FALSE );
10688     msg.wParam = dbch[1];
10689     DispatchMessageA( &msg );
10690     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10691     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10692     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10693
10694     /* interleaved sends */
10695     flush_sequence();
10696     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10697     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10698     ok_sequence( WmEmptySeq, "no messages", FALSE );
10699     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10700     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10701     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10702     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10703
10704     /* dbcs WM_CHAR */
10705     flush_sequence();
10706     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10707     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10708     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10709
10710     /* other char messages are not magic */
10711     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10712     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10713     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10714     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10715     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10716     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10717     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10718     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10719     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10720     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10721
10722     /* test retrieving messages */
10723
10724     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10725     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10726     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10727     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10728     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10729     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10730     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10731     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10732     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10733     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10734
10735     /* message filters */
10736     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10737     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10738     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10739     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10740     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10741     /* message id is filtered, hwnd is not */
10742     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10743     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10744     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10745     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10746     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10747     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10748
10749     /* mixing GetMessage and PostMessage */
10750     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10751     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10752     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10753     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10754     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10755     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10756     time = msg.time;
10757     pt = msg.pt;
10758     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10759     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10760     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10761     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10762     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10763     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10764     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10765     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 );
10766     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10767
10768     /* without PM_REMOVE */
10769     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10770     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10771     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10772     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10773     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10774     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10775     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10776     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10777     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10778     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10779     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10780     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10781     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10782     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10783     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10784     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10785     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10786     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10787
10788     DestroyWindow(hwnd);
10789 }
10790
10791 #define ID_LISTBOX 0x000f
10792
10793 static const struct message wm_lb_setcursel_0[] =
10794 {
10795     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10796     { WM_CTLCOLORLISTBOX, sent|parent },
10797     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10798     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10799     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10800     { 0 }
10801 };
10802 static const struct message wm_lb_setcursel_1[] =
10803 {
10804     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10805     { WM_CTLCOLORLISTBOX, sent|parent },
10806     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10807     { WM_CTLCOLORLISTBOX, sent|parent },
10808     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10809     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10810     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10811     { 0 }
10812 };
10813 static const struct message wm_lb_setcursel_2[] =
10814 {
10815     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10816     { WM_CTLCOLORLISTBOX, sent|parent },
10817     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10818     { WM_CTLCOLORLISTBOX, sent|parent },
10819     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10820     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10821     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10822     { 0 }
10823 };
10824 static const struct message wm_lb_click_0[] =
10825 {
10826     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10827     { HCBT_SETFOCUS, hook },
10828     { WM_KILLFOCUS, sent|parent },
10829     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10830     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10831     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10832     { WM_SETFOCUS, sent|defwinproc },
10833
10834     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10835     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10836     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10837     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10838     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10839
10840     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10841     { WM_CTLCOLORLISTBOX, sent|parent },
10842     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10843     { WM_CTLCOLORLISTBOX, sent|parent },
10844     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10845     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10846
10847     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10848     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10849
10850     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10851     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10852     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10853     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10854     { 0 }
10855 };
10856
10857 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10858
10859 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10860
10861 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10862 {
10863     static long defwndproc_counter = 0;
10864     LRESULT ret;
10865     struct recvd_message msg;
10866
10867     /* do not log painting messages */
10868     if (message != WM_PAINT &&
10869         message != WM_NCPAINT &&
10870         message != WM_SYNCPAINT &&
10871         message != WM_ERASEBKGND &&
10872         message != WM_NCHITTEST &&
10873         message != WM_GETTEXT &&
10874         message != WM_GETOBJECT &&
10875         message != WM_GETICON &&
10876         message != WM_DEVICECHANGE)
10877     {
10878         msg.hwnd = hwnd;
10879         msg.message = message;
10880         msg.flags = sent|wparam|lparam;
10881         if (defwndproc_counter) msg.flags |= defwinproc;
10882         msg.wParam = wp;
10883         msg.lParam = lp;
10884         msg.descr = "listbox";
10885         add_message(&msg);
10886     }
10887
10888     defwndproc_counter++;
10889     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10890     defwndproc_counter--;
10891
10892     return ret;
10893 }
10894
10895 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10896                                int caret_index, int top_index, int line)
10897 {
10898     LRESULT ret;
10899
10900     /* calling an orig proc helps to avoid unnecessary message logging */
10901     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10902     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10903     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10904     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10905     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10906     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10907     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10908     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10909 }
10910
10911 static void test_listbox_messages(void)
10912 {
10913     HWND parent, listbox;
10914     LRESULT ret;
10915
10916     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10917                              100, 100, 200, 200, 0, 0, 0, NULL);
10918     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10919                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10920                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10921     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10922
10923     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10924
10925     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10926     ok(ret == 0, "expected 0, got %ld\n", ret);
10927     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10928     ok(ret == 1, "expected 1, got %ld\n", ret);
10929     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10930     ok(ret == 2, "expected 2, got %ld\n", ret);
10931
10932     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10933
10934     flush_sequence();
10935
10936     log_all_parent_messages++;
10937
10938     trace("selecting item 0\n");
10939     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10940     ok(ret == 0, "expected 0, got %ld\n", ret);
10941     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10942     check_lb_state(listbox, 3, 0, 0, 0);
10943     flush_sequence();
10944
10945     trace("selecting item 1\n");
10946     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10947     ok(ret == 1, "expected 1, got %ld\n", ret);
10948     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10949     check_lb_state(listbox, 3, 1, 1, 0);
10950
10951     trace("selecting item 2\n");
10952     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10953     ok(ret == 2, "expected 2, got %ld\n", ret);
10954     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10955     check_lb_state(listbox, 3, 2, 2, 0);
10956
10957     trace("clicking on item 0\n");
10958     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10959     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10960     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10961     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10962     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10963     check_lb_state(listbox, 3, 0, 0, 0);
10964     flush_sequence();
10965
10966     log_all_parent_messages--;
10967
10968     DestroyWindow(listbox);
10969     DestroyWindow(parent);
10970 }
10971
10972 /*************************** Menu test ******************************/
10973 static const struct message wm_popup_menu_1[] =
10974 {
10975     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10976     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10977     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
10978     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
10979     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
10980     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
10981     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10982     { WM_INITMENU, sent|lparam, 0, 0 },
10983     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
10984     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
10985     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
10986     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
10987     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
10988     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10989     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10990     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
10991     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10992     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10993     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10994     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
10995     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10996     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10997     { 0 }
10998 };
10999 static const struct message wm_popup_menu_2[] =
11000 {
11001     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11002     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11003     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11004     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11005     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11006     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11007     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11008     { WM_INITMENU, sent|lparam, 0, 0 },
11009     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11010     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11011     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11012     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11013     { HCBT_CREATEWND, hook },
11014     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11015                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11016     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11017     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11018     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11019     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11020     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11021     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11022     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11023     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11024     { HCBT_DESTROYWND, hook },
11025     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11026     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11027     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11028     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11029     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11030     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11031     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11032     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11033     { 0 }
11034 };
11035 static const struct message wm_popup_menu_3[] =
11036 {
11037     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11038     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11039     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11040     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11041     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11042     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11043     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11044     { WM_INITMENU, sent|lparam, 0, 0 },
11045     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11046     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11047     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11048     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11049     { HCBT_CREATEWND, hook },
11050     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11051                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11052     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11053     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11054     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11055     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11056     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11057     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11058     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11059     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11060     { HCBT_DESTROYWND, hook },
11061     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11062     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11063     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11064     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11065     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11066     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11067     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11068     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11069     { 0 }
11070 };
11071
11072 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11073 {
11074     if (message == WM_ENTERIDLE ||
11075         message == WM_INITMENU ||
11076         message == WM_INITMENUPOPUP ||
11077         message == WM_MENUSELECT ||
11078         message == WM_PARENTNOTIFY ||
11079         message == WM_ENTERMENULOOP ||
11080         message == WM_EXITMENULOOP ||
11081         message == WM_UNINITMENUPOPUP ||
11082         message == WM_KEYDOWN ||
11083         message == WM_KEYUP ||
11084         message == WM_CHAR ||
11085         message == WM_SYSKEYDOWN ||
11086         message == WM_SYSKEYUP ||
11087         message == WM_SYSCHAR ||
11088         message == WM_COMMAND ||
11089         message == WM_MENUCOMMAND)
11090     {
11091         struct recvd_message msg;
11092
11093         msg.hwnd = hwnd;
11094         msg.message = message;
11095         msg.flags = sent|wparam|lparam;
11096         msg.wParam = wp;
11097         msg.lParam = lp;
11098         msg.descr = "parent_menu_proc";
11099         add_message(&msg);
11100     }
11101
11102     return DefWindowProcA(hwnd, message, wp, lp);
11103 }
11104
11105 static void set_menu_style(HMENU hmenu, DWORD style)
11106 {
11107     MENUINFO mi;
11108     BOOL ret;
11109
11110     mi.cbSize = sizeof(mi);
11111     mi.fMask = MIM_STYLE;
11112     mi.dwStyle = style;
11113     SetLastError(0xdeadbeef);
11114     ret = pSetMenuInfo(hmenu, &mi);
11115     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11116 }
11117
11118 static DWORD get_menu_style(HMENU hmenu)
11119 {
11120     MENUINFO mi;
11121     BOOL ret;
11122
11123     mi.cbSize = sizeof(mi);
11124     mi.fMask = MIM_STYLE;
11125     mi.dwStyle = 0;
11126     SetLastError(0xdeadbeef);
11127     ret = pGetMenuInfo(hmenu, &mi);
11128     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11129
11130     return mi.dwStyle;
11131 }
11132
11133 static void test_menu_messages(void)
11134 {
11135     MSG msg;
11136     WNDCLASSA cls;
11137     HMENU hmenu, hmenu_popup;
11138     HWND hwnd;
11139     DWORD style;
11140
11141     if (!pGetMenuInfo || !pSetMenuInfo)
11142     {
11143         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11144         return;
11145     }
11146     cls.style = 0;
11147     cls.lpfnWndProc = parent_menu_proc;
11148     cls.cbClsExtra = 0;
11149     cls.cbWndExtra = 0;
11150     cls.hInstance = GetModuleHandleA(0);
11151     cls.hIcon = 0;
11152     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11153     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11154     cls.lpszMenuName = NULL;
11155     cls.lpszClassName = "TestMenuClass";
11156     UnregisterClass(cls.lpszClassName, cls.hInstance);
11157     if (!RegisterClassA(&cls)) assert(0);
11158
11159     SetLastError(0xdeadbeef);
11160     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11161                            100, 100, 200, 200, 0, 0, 0, NULL);
11162     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11163
11164     SetLastError(0xdeadbeef);
11165     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11166     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11167
11168     SetMenu(hwnd, hmenu);
11169     SetForegroundWindow( hwnd );
11170
11171     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11172     style = get_menu_style(hmenu);
11173     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11174
11175     hmenu_popup = GetSubMenu(hmenu, 0);
11176     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11177     style = get_menu_style(hmenu_popup);
11178     ok(style == 0, "expected 0, got %u\n", style);
11179
11180     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11181     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11182     style = get_menu_style(hmenu_popup);
11183     ok(style == 0, "expected 0, got %u\n", style);
11184
11185     /* Alt+E, Enter */
11186     trace("testing a popup menu command\n");
11187     flush_sequence();
11188     keybd_event(VK_MENU, 0, 0, 0);
11189     keybd_event('E', 0, 0, 0);
11190     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11191     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11192     keybd_event(VK_RETURN, 0, 0, 0);
11193     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11194     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11195     {
11196         TranslateMessage(&msg);
11197         DispatchMessage(&msg);
11198     }
11199     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11200
11201     /* Alt+F, Right, Enter */
11202     trace("testing submenu of a popup menu command\n");
11203     flush_sequence();
11204     keybd_event(VK_MENU, 0, 0, 0);
11205     keybd_event('F', 0, 0, 0);
11206     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11207     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11208     keybd_event(VK_RIGHT, 0, 0, 0);
11209     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11210     keybd_event(VK_RETURN, 0, 0, 0);
11211     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11212     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11213     {
11214         TranslateMessage(&msg);
11215         DispatchMessage(&msg);
11216     }
11217     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11218
11219     set_menu_style(hmenu, 0);
11220     style = get_menu_style(hmenu);
11221     ok(style == 0, "expected 0, got %u\n", style);
11222
11223     hmenu_popup = GetSubMenu(hmenu, 0);
11224     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11225     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11226     style = get_menu_style(hmenu_popup);
11227     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11228
11229     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11230     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11231     style = get_menu_style(hmenu_popup);
11232     ok(style == 0, "expected 0, got %u\n", style);
11233
11234     /* Alt+F, Right, Enter */
11235     trace("testing submenu of a popup menu command\n");
11236     flush_sequence();
11237     keybd_event(VK_MENU, 0, 0, 0);
11238     keybd_event('F', 0, 0, 0);
11239     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11240     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11241     keybd_event(VK_RIGHT, 0, 0, 0);
11242     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11243     keybd_event(VK_RETURN, 0, 0, 0);
11244     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11245     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11246     {
11247         TranslateMessage(&msg);
11248         DispatchMessage(&msg);
11249     }
11250     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11251
11252     DestroyWindow(hwnd);
11253     DestroyMenu(hmenu);
11254 }
11255
11256
11257 static void test_paintingloop(void)
11258 {
11259     HWND hwnd;
11260
11261     paint_loop_done = 0;
11262     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11263                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11264                                 100, 100, 100, 100, 0, 0, 0, NULL );
11265     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11266     ShowWindow(hwnd,SW_NORMAL);
11267     SetFocus(hwnd);
11268
11269     while (!paint_loop_done)
11270     {
11271         MSG msg;
11272         if (PeekMessageA(&msg, 0, 0, 0, 1))
11273         {
11274             TranslateMessage(&msg);
11275             DispatchMessage(&msg);
11276         }
11277     }
11278     DestroyWindow(hwnd);
11279 }
11280
11281 START_TEST(msg)
11282 {
11283     BOOL ret;
11284     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11285
11286     init_procs();
11287
11288     if (!RegisterWindowClasses()) assert(0);
11289
11290     if (pSetWinEventHook)
11291     {
11292         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11293                                                       GetModuleHandleA(0),
11294                                                       win_event_proc,
11295                                                       0,
11296                                                       GetCurrentThreadId(),
11297                                                       WINEVENT_INCONTEXT);
11298         assert(hEvent_hook);
11299
11300         if (pIsWinEventHookInstalled)
11301         {
11302             UINT event;
11303             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11304                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11305         }
11306     }
11307
11308     cbt_hook_thread_id = GetCurrentThreadId();
11309     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11310     if (!hCBT_hook) skip( "cannot set global hook, will skip hook tests\n" );
11311
11312     test_winevents();
11313
11314     /* Fix message sequences before removing 4 lines below */
11315 #if 1
11316     if (pUnhookWinEvent && hEvent_hook)
11317     {
11318         ret = pUnhookWinEvent(hEvent_hook);
11319         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11320         pUnhookWinEvent = 0;
11321     }
11322     hEvent_hook = 0;
11323 #endif
11324
11325     test_ShowWindow();
11326     test_PeekMessage();
11327     test_PeekMessage2();
11328     test_scrollwindowex();
11329     test_messages();
11330     test_setwindowpos();
11331     test_showwindow();
11332     invisible_parent_tests();
11333     test_mdi_messages();
11334     test_button_messages();
11335     test_static_messages();
11336     test_listbox_messages();
11337     test_combobox_messages();
11338     test_wmime_keydown_message();
11339     test_paint_messages();
11340     test_interthread_messages();
11341     test_message_conversion();
11342     test_accelerators();
11343     test_timers();
11344     test_timers_no_wnd();
11345     test_set_hook();
11346     test_DestroyWindow();
11347     test_DispatchMessage();
11348     test_SendMessageTimeout();
11349     test_edit_messages();
11350     test_quit_message();
11351     test_SetActiveWindow();
11352
11353     if (!pTrackMouseEvent)
11354         skip("TrackMouseEvent is not available\n");
11355     else
11356         test_TrackMouseEvent();
11357
11358     test_SetWindowRgn();
11359     test_sys_menu();
11360     test_dialog_messages();
11361     test_nullCallback();
11362     test_dbcs_wm_char();
11363     test_menu_messages();
11364     test_paintingloop();
11365     /* keep it the last test, under Windows it tends to break the tests
11366      * which rely on active/foreground windows being correct.
11367      */
11368     test_SetForegroundWindow();
11369
11370     UnhookWindowsHookEx(hCBT_hook);
11371     if (pUnhookWinEvent)
11372     {
11373         ret = pUnhookWinEvent(hEvent_hook);
11374         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11375         SetLastError(0xdeadbeef);
11376         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11377         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11378            GetLastError() == 0xdeadbeef, /* Win9x */
11379            "unexpected error %d\n", GetLastError());
11380     }
11381     else
11382         skip("UnhookWinEvent is not available\n");
11383 }