user32/tests: Fix some window test failures on various Windows platforms.
[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_NCPAINT, sent|wparam|defwinproc|optional, 1 },
658     { WM_ERASEBKGND, sent|defwinproc|optional },
659     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
660     { 0 }
661 };
662 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
663 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
664     { HCBT_CREATEWND, hook },
665     { WM_NCCREATE, sent },
666     { WM_NCCALCSIZE, sent|wparam, 0 },
667     { WM_CREATE, sent },
668     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
669     { WM_SIZE, sent|wparam, SIZE_RESTORED },
670     { WM_MOVE, sent },
671     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
672     { WM_GETMINMAXINFO, sent },
673     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
674     { WM_NCCALCSIZE, sent|wparam, TRUE },
675     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
676     { WM_MOVE, sent|defwinproc },
677     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
678     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
679     { 0 }
680 };
681 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
682 static const struct message WmShowMaxPopupResizedSeq[] = {
683     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
684     { WM_GETMINMAXINFO, sent },
685     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
686     { WM_NCCALCSIZE, sent|wparam, TRUE },
687     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
688     { HCBT_ACTIVATE, hook },
689     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
690     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
691     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
692     { WM_NCPAINT, sent|wparam|optional, 1 },
693     { WM_ERASEBKGND, sent|optional },
694     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
695     { WM_ACTIVATEAPP, sent|wparam, 1 },
696     { WM_NCACTIVATE, sent|wparam, 1 },
697     { WM_ACTIVATE, sent|wparam, 1 },
698     { HCBT_SETFOCUS, hook },
699     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
700     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
701     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
702     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
703     { WM_GETTEXT, sent|optional },
704     { WM_NCPAINT, sent|wparam|optional, 1 },
705     { WM_ERASEBKGND, sent|optional },
706     { WM_WINDOWPOSCHANGED, sent },
707     /* WinNT4.0 sends WM_MOVE */
708     { WM_MOVE, sent|defwinproc|optional },
709     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
710     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
711     { 0 }
712 };
713 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
714 static const struct message WmShowMaxPopupSeq[] = {
715     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
716     { WM_GETMINMAXINFO, sent },
717     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
718     { WM_NCCALCSIZE, sent|wparam, TRUE },
719     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
720     { HCBT_ACTIVATE, hook },
721     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
722     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
723     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
724     { WM_ACTIVATEAPP, sent|wparam, 1 },
725     { WM_NCACTIVATE, sent|wparam, 1 },
726     { WM_ACTIVATE, sent|wparam, 1 },
727     { HCBT_SETFOCUS, hook },
728     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
729     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
730     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
731     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
732     { WM_GETTEXT, sent|optional },
733     { WM_SYNCPAINT, sent|wparam|optional, 4 },
734     { WM_NCPAINT, sent|wparam|optional, 1 },
735     { WM_ERASEBKGND, sent|optional },
736     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
737     { WM_ERASEBKGND, sent|defwinproc|optional },
738     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
739     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
740     { 0 }
741 };
742 /* CreateWindow(WS_VISIBLE) for popup window */
743 static const struct message WmCreatePopupSeq[] = {
744     { HCBT_CREATEWND, hook },
745     { WM_NCCREATE, sent },
746     { WM_NCCALCSIZE, sent|wparam, 0 },
747     { WM_CREATE, sent },
748     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
749     { WM_SIZE, sent|wparam, SIZE_RESTORED },
750     { WM_MOVE, sent },
751     { WM_SHOWWINDOW, sent|wparam, 1 },
752     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
753     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
754     { HCBT_ACTIVATE, hook },
755     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
756     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
757     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
758     { WM_NCPAINT, sent|wparam|optional, 1 },
759     { WM_ERASEBKGND, sent|optional },
760     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
761     { WM_ACTIVATEAPP, sent|wparam, 1 },
762     { WM_NCACTIVATE, sent|wparam, 1 },
763     { WM_ACTIVATE, sent|wparam, 1 },
764     { HCBT_SETFOCUS, hook },
765     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
766     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
767     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
768     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
769     { WM_GETTEXT, sent|optional },
770     { WM_SYNCPAINT, sent|wparam|optional, 4 },
771     { WM_NCPAINT, sent|wparam|optional, 1 },
772     { WM_ERASEBKGND, sent|optional },
773     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
774     { 0 }
775 };
776 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
777 static const struct message WmShowVisMaxPopupSeq[] = {
778     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
779     { WM_GETMINMAXINFO, sent },
780     { WM_GETTEXT, sent|optional },
781     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
782     { WM_GETTEXT, sent|optional },
783     { WM_NCCALCSIZE, sent|wparam, TRUE },
784     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
785     { WM_NCPAINT, sent|wparam|optional, 1 },
786     { WM_ERASEBKGND, sent|optional },
787     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
788     { WM_MOVE, sent|defwinproc },
789     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
790     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
791     { 0 }
792 };
793 /* CreateWindow (for a child popup window, not initially visible) */
794 static const struct message WmCreateChildPopupSeq[] = {
795     { HCBT_CREATEWND, hook },
796     { WM_NCCREATE, sent }, 
797     { WM_NCCALCSIZE, sent|wparam, 0 },
798     { WM_CREATE, sent },
799     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
800     { WM_SIZE, sent|wparam, SIZE_RESTORED },
801     { WM_MOVE, sent },
802     { 0 }
803 };
804 /* CreateWindow (for a popup window, not initially visible,
805  * which sets WS_VISIBLE in WM_CREATE handler)
806  */
807 static const struct message WmCreateInvisiblePopupSeq[] = {
808     { HCBT_CREATEWND, hook },
809     { WM_NCCREATE, sent }, 
810     { WM_NCCALCSIZE, sent|wparam, 0 },
811     { WM_CREATE, sent },
812     { WM_STYLECHANGING, sent },
813     { WM_STYLECHANGED, sent },
814     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
815     { WM_SIZE, sent|wparam, SIZE_RESTORED },
816     { WM_MOVE, sent },
817     { 0 }
818 };
819 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
820  * for a popup window with WS_VISIBLE style set
821  */
822 static const struct message WmShowVisiblePopupSeq_2[] = {
823     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
824     { 0 }
825 };
826 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
827  * for a popup window with WS_VISIBLE style set
828  */
829 static const struct message WmShowVisiblePopupSeq_3[] = {
830     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
831     { HCBT_ACTIVATE, hook },
832     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
833     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
834     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
835     { WM_NCACTIVATE, sent|wparam, 1 },
836     { WM_ACTIVATE, sent|wparam, 1 },
837     { HCBT_SETFOCUS, hook },
838     { WM_KILLFOCUS, sent|parent },
839     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
840     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
841     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
842     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
843     { WM_SETFOCUS, sent|defwinproc },
844     { WM_GETTEXT, sent|optional },
845     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
846     { 0 }
847 };
848 /* CreateWindow (for child window, not initially visible) */
849 static const struct message WmCreateChildSeq[] = {
850     { HCBT_CREATEWND, hook },
851     { WM_NCCREATE, sent }, 
852     /* child is inserted into parent's child list after WM_NCCREATE returns */
853     { WM_NCCALCSIZE, sent|wparam, 0 },
854     { WM_CREATE, sent },
855     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
856     { WM_SIZE, sent|wparam, SIZE_RESTORED },
857     { WM_MOVE, sent },
858     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
859     { 0 }
860 };
861 /* CreateWindow (for maximized child window, not initially visible) */
862 static const struct message WmCreateMaximizedChildSeq[] = {
863     { HCBT_CREATEWND, hook },
864     { WM_NCCREATE, sent }, 
865     { WM_NCCALCSIZE, sent|wparam, 0 },
866     { WM_CREATE, sent },
867     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
868     { WM_SIZE, sent|wparam, SIZE_RESTORED },
869     { WM_MOVE, sent },
870     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
871     { WM_GETMINMAXINFO, sent },
872     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
873     { WM_NCCALCSIZE, sent|wparam, 1 },
874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
875     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
876     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
877     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
878     { 0 }
879 };
880 /* CreateWindow (for a child window, initially visible) */
881 static const struct message WmCreateVisibleChildSeq[] = {
882     { HCBT_CREATEWND, hook },
883     { WM_NCCREATE, sent }, 
884     /* child is inserted into parent's child list after WM_NCCREATE returns */
885     { WM_NCCALCSIZE, sent|wparam, 0 },
886     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
887     { WM_CREATE, sent },
888     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
889     { WM_SIZE, sent|wparam, SIZE_RESTORED },
890     { WM_MOVE, sent },
891     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
892     { WM_SHOWWINDOW, sent|wparam, 1 },
893     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
894     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
895     { WM_ERASEBKGND, sent|parent|optional },
896     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
897     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
898     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
899     { 0 }
900 };
901 /* ShowWindow(SW_SHOW) for a not visible child window */
902 static const struct message WmShowChildSeq[] = {
903     { WM_SHOWWINDOW, sent|wparam, 1 },
904     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
905     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
906     { WM_ERASEBKGND, sent|parent|optional },
907     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
908     { 0 }
909 };
910 /* ShowWindow(SW_HIDE) for a visible child window */
911 static const struct message WmHideChildSeq[] = {
912     { WM_SHOWWINDOW, sent|wparam, 0 },
913     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
914     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
915     { WM_ERASEBKGND, sent|parent|optional },
916     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
917     { 0 }
918 };
919 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
920 static const struct message WmHideChildSeq2[] = {
921     { WM_SHOWWINDOW, sent|wparam, 0 },
922     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
923     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
924     { WM_ERASEBKGND, sent|parent|optional },
925     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
926     { 0 }
927 };
928 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
929  * for a not visible child window
930  */
931 static const struct message WmShowChildSeq_2[] = {
932     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
933     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
934     { WM_CHILDACTIVATE, sent },
935     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
936     { 0 }
937 };
938 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
939  * for a not visible child window
940  */
941 static const struct message WmShowChildSeq_3[] = {
942     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
943     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
944     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
945     { 0 }
946 };
947 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
948  * for a visible child window with a caption
949  */
950 static const struct message WmShowChildSeq_4[] = {
951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
952     { WM_CHILDACTIVATE, sent },
953     { 0 }
954 };
955 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
956 static const struct message WmShowChildInvisibleParentSeq_1[] = {
957     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
958     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
959     { WM_NCCALCSIZE, sent|wparam, 1 },
960     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
961     { WM_CHILDACTIVATE, sent|optional },
962     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
963     { WM_MOVE, sent|defwinproc },
964     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
965     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
966     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
967     /* FIXME: Wine creates an icon/title window while Windows doesn't */
968     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
969     { WM_GETTEXT, sent|optional },
970     { 0 }
971 };
972 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
973 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
974     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
975     { 0 }
976 };
977 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
978 static const struct message WmShowChildInvisibleParentSeq_2[] = {
979     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
980     { WM_GETMINMAXINFO, sent },
981     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
982     { WM_NCCALCSIZE, sent|wparam, 1 },
983     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
984     { WM_CHILDACTIVATE, sent },
985     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
986     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
987     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
988     { 0 }
989 };
990 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
991 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
992     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
993     { 0 }
994 };
995 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
996 static const struct message WmShowChildInvisibleParentSeq_3[] = {
997     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
998     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
999     { WM_NCCALCSIZE, sent|wparam, 1 },
1000     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1001     { WM_CHILDACTIVATE, sent },
1002     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1003     { WM_MOVE, sent|defwinproc },
1004     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1005     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1006     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1007     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1008     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1009     { WM_GETTEXT, sent|optional },
1010     { 0 }
1011 };
1012 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1013 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1014     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1015     { 0 }
1016 };
1017 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1018 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1019     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1020     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1021     { WM_NCCALCSIZE, sent|wparam, 1 },
1022     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1023     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1024     { WM_MOVE, sent|defwinproc },
1025     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1026     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1027     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1028     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1029     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1030     { WM_GETTEXT, sent|optional },
1031     { 0 }
1032 };
1033 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1034 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1035     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1036     { 0 }
1037 };
1038 /* ShowWindow(SW_SHOW) for child with invisible parent */
1039 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1040     { WM_SHOWWINDOW, sent|wparam, 1 },
1041     { 0 }
1042 };
1043 /* ShowWindow(SW_HIDE) for child with invisible parent */
1044 static const struct message WmHideChildInvisibleParentSeq[] = {
1045     { WM_SHOWWINDOW, sent|wparam, 0 },
1046     { 0 }
1047 };
1048 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1049 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1050     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1051     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1052     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1053     { 0 }
1054 };
1055 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1056 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1057     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1058     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1059     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1060     { 0 }
1061 };
1062 /* DestroyWindow for a visible child window */
1063 static const struct message WmDestroyChildSeq[] = {
1064     { HCBT_DESTROYWND, hook },
1065     { 0x0090, sent|optional },
1066     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1067     { WM_SHOWWINDOW, sent|wparam, 0 },
1068     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1069     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1070     { WM_ERASEBKGND, sent|parent|optional },
1071     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1072     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1073     { WM_KILLFOCUS, sent },
1074     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1075     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1076     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1077     { WM_SETFOCUS, sent|parent },
1078     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1079     { WM_DESTROY, sent },
1080     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1081     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1082     { WM_NCDESTROY, sent },
1083     { 0 }
1084 };
1085 /* DestroyWindow for a visible child window with invisible parent */
1086 static const struct message WmDestroyInvisibleChildSeq[] = {
1087     { HCBT_DESTROYWND, hook },
1088     { 0x0090, sent|optional },
1089     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1090     { WM_SHOWWINDOW, sent|wparam, 0 },
1091     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1092     { WM_DESTROY, sent },
1093     { WM_NCDESTROY, sent },
1094     { 0 }
1095 };
1096 /* Moving the mouse in nonclient area */
1097 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1098     { WM_NCHITTEST, sent },
1099     { WM_SETCURSOR, sent },
1100     { WM_NCMOUSEMOVE, posted },
1101     { 0 }
1102 };
1103 /* Moving the mouse in client area */
1104 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1105     { WM_NCHITTEST, sent },
1106     { WM_SETCURSOR, sent },
1107     { WM_MOUSEMOVE, posted },
1108     { 0 }
1109 };
1110 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1111 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1112     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1113     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1114     { WM_GETMINMAXINFO, sent|defwinproc },
1115     { WM_ENTERSIZEMOVE, sent|defwinproc },
1116     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1117     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1118     { WM_MOVE, sent|defwinproc },
1119     { WM_EXITSIZEMOVE, sent|defwinproc },
1120     { 0 }
1121 };
1122 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1123 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1124     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1125     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1126     { WM_GETMINMAXINFO, sent|defwinproc },
1127     { WM_ENTERSIZEMOVE, sent|defwinproc },
1128     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1129     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1130     { WM_GETMINMAXINFO, sent|defwinproc },
1131     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1132     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1133     { WM_GETTEXT, sent|defwinproc },
1134     { WM_ERASEBKGND, sent|defwinproc },
1135     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1136     { WM_MOVE, sent|defwinproc },
1137     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1138     { WM_EXITSIZEMOVE, sent|defwinproc },
1139     { 0 }
1140 };
1141 /* Resizing child window with MoveWindow (32) */
1142 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1143     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1144     { WM_NCCALCSIZE, sent|wparam, 1 },
1145     { WM_ERASEBKGND, sent|parent|optional },
1146     { WM_ERASEBKGND, sent|optional },
1147     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1148     { WM_MOVE, sent|defwinproc },
1149     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1150     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1151     { 0 }
1152 };
1153 /* Clicking on inactive button */
1154 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1155     { WM_NCHITTEST, sent },
1156     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1157     { WM_MOUSEACTIVATE, sent },
1158     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1159     { WM_SETCURSOR, sent },
1160     { WM_SETCURSOR, sent|parent|defwinproc },
1161     { WM_LBUTTONDOWN, posted },
1162     { WM_KILLFOCUS, posted|parent },
1163     { WM_SETFOCUS, posted },
1164     { WM_CTLCOLORBTN, posted|parent },
1165     { BM_SETSTATE, posted },
1166     { WM_CTLCOLORBTN, posted|parent },
1167     { WM_LBUTTONUP, posted },
1168     { BM_SETSTATE, posted },
1169     { WM_CTLCOLORBTN, posted|parent },
1170     { WM_COMMAND, posted|parent },
1171     { 0 }
1172 };
1173 /* Reparenting a button (16/32) */
1174 /* The last child (button) reparented gets topmost for its new parent. */
1175 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1176     { WM_SHOWWINDOW, sent|wparam, 0 },
1177     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1178     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1179     { WM_ERASEBKGND, sent|parent },
1180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1181     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1182     { WM_CHILDACTIVATE, sent },
1183     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1184     { WM_MOVE, sent|defwinproc },
1185     { WM_SHOWWINDOW, sent|wparam, 1 },
1186     { 0 }
1187 };
1188 /* Creation of a custom dialog (32) */
1189 static const struct message WmCreateCustomDialogSeq[] = {
1190     { HCBT_CREATEWND, hook },
1191     { WM_GETMINMAXINFO, sent },
1192     { WM_NCCREATE, sent },
1193     { WM_NCCALCSIZE, sent|wparam, 0 },
1194     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1195     { WM_CREATE, sent },
1196     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1197     { WM_NOTIFYFORMAT, sent|optional },
1198     { WM_QUERYUISTATE, sent|optional },
1199     { WM_WINDOWPOSCHANGING, sent|optional },
1200     { WM_GETMINMAXINFO, sent|optional },
1201     { WM_NCCALCSIZE, sent|optional },
1202     { WM_WINDOWPOSCHANGED, sent|optional },
1203     { WM_SHOWWINDOW, sent|wparam, 1 },
1204     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1205     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1206     { HCBT_ACTIVATE, hook },
1207     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1208
1209
1210     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1211
1212     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1213
1214     { WM_NCACTIVATE, sent|wparam, 1 },
1215     { WM_GETTEXT, sent|optional|defwinproc },
1216     { WM_GETTEXT, sent|optional|defwinproc },
1217     { WM_GETTEXT, sent|optional|defwinproc },
1218     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1219     { WM_ACTIVATE, sent|wparam, 1 },
1220     { WM_GETTEXT, sent|optional },
1221     { WM_KILLFOCUS, sent|parent },
1222     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1223     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1224     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1225     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1226     { WM_SETFOCUS, sent },
1227     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1228     { WM_NCPAINT, sent|wparam, 1 },
1229     { WM_GETTEXT, sent|optional|defwinproc },
1230     { WM_GETTEXT, sent|optional|defwinproc },
1231     { WM_ERASEBKGND, sent },
1232     { WM_CTLCOLORDLG, sent|defwinproc },
1233     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1234     { WM_GETTEXT, sent|optional },
1235     { WM_GETTEXT, sent|optional },
1236     { WM_NCCALCSIZE, sent|optional },
1237     { WM_NCPAINT, sent|optional },
1238     { WM_GETTEXT, sent|optional|defwinproc },
1239     { WM_GETTEXT, sent|optional|defwinproc },
1240     { WM_ERASEBKGND, sent|optional },
1241     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1242     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1243     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1244     { WM_MOVE, sent },
1245     { 0 }
1246 };
1247 /* Calling EndDialog for a custom dialog (32) */
1248 static const struct message WmEndCustomDialogSeq[] = {
1249     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1250     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1251     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1252     { WM_GETTEXT, sent|optional },
1253     { HCBT_ACTIVATE, hook },
1254     { WM_NCACTIVATE, sent|wparam, 0 },
1255     { WM_GETTEXT, sent|optional|defwinproc },
1256     { WM_GETTEXT, sent|optional|defwinproc },
1257     { WM_ACTIVATE, sent|wparam, 0 },
1258     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1259     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1260     { HCBT_SETFOCUS, hook },
1261     { WM_KILLFOCUS, sent },
1262     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1263     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1264     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1265     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1266     { WM_SETFOCUS, sent|parent|defwinproc },
1267     { 0 }
1268 };
1269 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1270 static const struct message WmShowCustomDialogSeq[] = {
1271     { WM_SHOWWINDOW, sent|wparam, 1 },
1272     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1273     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1274     { HCBT_ACTIVATE, hook },
1275     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1276
1277     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1278
1279     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1280     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1281     { WM_NCACTIVATE, sent|wparam, 1 },
1282     { WM_ACTIVATE, sent|wparam, 1 },
1283     { WM_GETTEXT, sent|optional },
1284
1285     { WM_KILLFOCUS, sent|parent },
1286     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1287     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1288     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1289     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1290     { WM_SETFOCUS, sent },
1291     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1292     { WM_NCPAINT, sent|wparam, 1 },
1293     { WM_ERASEBKGND, sent },
1294     { WM_CTLCOLORDLG, sent|defwinproc },
1295     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1296     { 0 }
1297 };
1298 /* Creation and destruction of a modal dialog (32) */
1299 static const struct message WmModalDialogSeq[] = {
1300     { WM_CANCELMODE, sent|parent },
1301     { HCBT_SETFOCUS, hook },
1302     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1303     { WM_KILLFOCUS, sent|parent },
1304     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1305     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1306     { WM_ENABLE, sent|parent|wparam, 0 },
1307     { HCBT_CREATEWND, hook },
1308     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1309     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1310     { WM_SETFONT, sent },
1311     { WM_INITDIALOG, sent },
1312     { WM_CHANGEUISTATE, sent|optional },
1313     { WM_UPDATEUISTATE, sent|optional },
1314     { WM_SHOWWINDOW, sent },
1315     { HCBT_ACTIVATE, hook },
1316     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1317     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1318     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1319     { WM_NCACTIVATE, sent|wparam, 1 },
1320     { WM_GETTEXT, sent|optional },
1321     { WM_ACTIVATE, sent|wparam, 1 },
1322     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1323     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1324     { WM_NCPAINT, sent },
1325     { WM_GETTEXT, sent|optional },
1326     { WM_ERASEBKGND, sent },
1327     { WM_CTLCOLORDLG, sent },
1328     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1329     { WM_GETTEXT, sent|optional },
1330     { WM_NCCALCSIZE, sent|optional },
1331     { WM_NCPAINT, sent|optional },
1332     { WM_GETTEXT, sent|optional },
1333     { WM_ERASEBKGND, sent|optional },
1334     { WM_CTLCOLORDLG, sent|optional },
1335     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1336     { WM_PAINT, sent|optional },
1337     { WM_CTLCOLORBTN, sent },
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_ENTERIDLE, sent|parent|optional },
1351     { WM_ENTERIDLE, sent|parent|optional },
1352     { WM_ENTERIDLE, sent|parent|optional },
1353     { WM_ENTERIDLE, sent|parent|optional },
1354     { WM_ENTERIDLE, sent|parent|optional },
1355     { WM_ENTERIDLE, sent|parent|optional },
1356     { WM_ENTERIDLE, sent|parent|optional },
1357     { WM_ENTERIDLE, sent|parent|optional },
1358     { WM_TIMER, sent },
1359     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1360     { WM_ENABLE, sent|parent|wparam, 1 },
1361     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1362     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1363     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1364     { WM_GETTEXT, sent|optional },
1365     { HCBT_ACTIVATE, hook },
1366     { WM_NCACTIVATE, sent|wparam, 0 },
1367     { WM_GETTEXT, sent|optional },
1368     { WM_ACTIVATE, sent|wparam, 0 },
1369     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1370     { WM_WINDOWPOSCHANGING, sent|optional },
1371     { WM_WINDOWPOSCHANGED, sent|optional },
1372     { HCBT_SETFOCUS, hook },
1373     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1374     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1375     { WM_SETFOCUS, sent|parent|defwinproc },
1376     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1377     { HCBT_DESTROYWND, hook },
1378     { 0x0090, sent|optional },
1379     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1380     { WM_DESTROY, sent },
1381     { WM_NCDESTROY, sent },
1382     { 0 }
1383 };
1384 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1385 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1386     /* (inside dialog proc, handling WM_INITDIALOG) */
1387     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1388     { WM_NCCALCSIZE, sent },
1389     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1390     { WM_GETTEXT, sent|defwinproc },
1391     { WM_ACTIVATE, sent|parent|wparam, 0 },
1392     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1393     { WM_WINDOWPOSCHANGING, sent|parent },
1394     { WM_NCACTIVATE, sent|wparam, 1 },
1395     { WM_ACTIVATE, sent|wparam, 1 },
1396     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1397     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1398     /* (setting focus) */
1399     { WM_SHOWWINDOW, sent|wparam, 1 },
1400     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1401     { WM_NCPAINT, sent },
1402     { WM_GETTEXT, sent|defwinproc },
1403     { WM_ERASEBKGND, sent },
1404     { WM_CTLCOLORDLG, sent|defwinproc },
1405     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1406     { WM_PAINT, sent },
1407     /* (bunch of WM_CTLCOLOR* for each control) */
1408     { WM_PAINT, sent|parent },
1409     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1410     { WM_SETCURSOR, sent|parent },
1411     { 0 }
1412 };
1413 /* SetMenu for NonVisible windows with size change*/
1414 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1415     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1416     { WM_NCCALCSIZE, sent|wparam, 1 },
1417     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1418     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1419     { WM_MOVE, sent|defwinproc },
1420     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1421     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1422     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1423     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1424     { WM_GETTEXT, sent|optional },
1425     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1426     { 0 }
1427 };
1428 /* SetMenu for NonVisible windows with no size change */
1429 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1430     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1431     { WM_NCCALCSIZE, sent|wparam, 1 },
1432     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1433     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1434     { 0 }
1435 };
1436 /* SetMenu for Visible windows with size change */
1437 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1438     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1439     { WM_NCCALCSIZE, sent|wparam, 1 },
1440     { 0x0093, sent|defwinproc|optional },
1441     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1442     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1443     { 0x0093, sent|defwinproc|optional },
1444     { 0x0093, sent|defwinproc|optional },
1445     { 0x0091, sent|defwinproc|optional },
1446     { 0x0092, sent|defwinproc|optional },
1447     { WM_GETTEXT, sent|defwinproc|optional },
1448     { WM_ERASEBKGND, sent|optional },
1449     { WM_ACTIVATE, sent|optional },
1450     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1451     { WM_MOVE, sent|defwinproc },
1452     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1453     { 0x0093, sent|optional },
1454     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1455     { 0x0093, sent|defwinproc|optional },
1456     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1457     { 0x0093, sent|defwinproc|optional },
1458     { 0x0093, sent|defwinproc|optional },
1459     { 0x0091, sent|defwinproc|optional },
1460     { 0x0092, sent|defwinproc|optional },
1461     { WM_ERASEBKGND, sent|optional },
1462     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1463     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1464     { 0 }
1465 };
1466 /* SetMenu for Visible windows with no size change */
1467 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1468     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1469     { WM_NCCALCSIZE, sent|wparam, 1 },
1470     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1471     { WM_GETTEXT, sent|defwinproc|optional },
1472     { WM_ERASEBKGND, sent|optional },
1473     { WM_ACTIVATE, sent|optional },
1474     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1475     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1476     { 0 }
1477 };
1478 /* DrawMenuBar for a visible window */
1479 static const struct message WmDrawMenuBarSeq[] =
1480 {
1481     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1482     { WM_NCCALCSIZE, sent|wparam, 1 },
1483     { 0x0093, sent|defwinproc|optional },
1484     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1485     { 0x0093, sent|defwinproc|optional },
1486     { 0x0093, sent|defwinproc|optional },
1487     { 0x0091, sent|defwinproc|optional },
1488     { 0x0092, sent|defwinproc|optional },
1489     { WM_GETTEXT, sent|defwinproc|optional },
1490     { WM_ERASEBKGND, sent|optional },
1491     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1492     { 0x0093, sent|optional },
1493     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1494     { 0 }
1495 };
1496
1497 static const struct message WmSetRedrawFalseSeq[] =
1498 {
1499     { WM_SETREDRAW, sent|wparam, 0 },
1500     { 0 }
1501 };
1502
1503 static const struct message WmSetRedrawTrueSeq[] =
1504 {
1505     { WM_SETREDRAW, sent|wparam, 1 },
1506     { 0 }
1507 };
1508
1509 static const struct message WmEnableWindowSeq_1[] =
1510 {
1511     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1512     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1513     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1514     { 0 }
1515 };
1516
1517 static const struct message WmEnableWindowSeq_2[] =
1518 {
1519     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1520     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1521     { 0 }
1522 };
1523
1524 static const struct message WmGetScrollRangeSeq[] =
1525 {
1526     { SBM_GETRANGE, sent },
1527     { 0 }
1528 };
1529 static const struct message WmGetScrollInfoSeq[] =
1530 {
1531     { SBM_GETSCROLLINFO, sent },
1532     { 0 }
1533 };
1534 static const struct message WmSetScrollRangeSeq[] =
1535 {
1536     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1537        sends SBM_SETSCROLLINFO.
1538      */
1539     { SBM_SETSCROLLINFO, sent },
1540     { 0 }
1541 };
1542 /* SetScrollRange for a window without a non-client area */
1543 static const struct message WmSetScrollRangeHSeq_empty[] =
1544 {
1545     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1546     { 0 }
1547 };
1548 static const struct message WmSetScrollRangeVSeq_empty[] =
1549 {
1550     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1551     { 0 }
1552 };
1553 static const struct message WmSetScrollRangeHVSeq[] =
1554 {
1555     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1556     { WM_NCCALCSIZE, sent|wparam, 1 },
1557     { WM_GETTEXT, sent|defwinproc|optional },
1558     { WM_ERASEBKGND, sent|optional },
1559     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1560     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1561     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1562     { 0 }
1563 };
1564 /* SetScrollRange for a window with a non-client area */
1565 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1566 {
1567     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1568     { WM_NCCALCSIZE, sent|wparam, 1 },
1569     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1570     { WM_NCPAINT, sent|optional },
1571     { WM_STYLECHANGING, sent|defwinproc|optional },
1572     { WM_STYLECHANGED, sent|defwinproc|optional },
1573     { WM_STYLECHANGING, sent|defwinproc|optional },
1574     { WM_STYLECHANGED, sent|defwinproc|optional },
1575     { WM_STYLECHANGING, sent|defwinproc|optional },
1576     { WM_STYLECHANGED, sent|defwinproc|optional },
1577     { WM_STYLECHANGING, sent|defwinproc|optional },
1578     { WM_STYLECHANGED, sent|defwinproc|optional },
1579     { WM_GETTEXT, sent|defwinproc|optional },
1580     { WM_GETTEXT, sent|defwinproc|optional },
1581     { WM_ERASEBKGND, sent|optional },
1582     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1583     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1584     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1585     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1586     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1587     { WM_GETTEXT, sent|optional },
1588     { WM_GETTEXT, sent|optional },
1589     { WM_GETTEXT, sent|optional },
1590     { WM_GETTEXT, sent|optional },
1591     { 0 }
1592 };
1593 /* test if we receive the right sequence of messages */
1594 /* after calling ShowWindow( SW_SHOWNA) */
1595 static const struct message WmSHOWNAChildInvisParInvis[] = {
1596     { WM_SHOWWINDOW, sent|wparam, 1 },
1597     { 0 }
1598 };
1599 static const struct message WmSHOWNAChildVisParInvis[] = {
1600     { WM_SHOWWINDOW, sent|wparam, 1 },
1601     { 0 }
1602 };
1603 static const struct message WmSHOWNAChildVisParVis[] = {
1604     { WM_SHOWWINDOW, sent|wparam, 1 },
1605     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1606     { 0 }
1607 };
1608 static const struct message WmSHOWNAChildInvisParVis[] = {
1609     { WM_SHOWWINDOW, sent|wparam, 1 },
1610     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1611     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1612     { WM_ERASEBKGND, sent|optional },
1613     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1614     { 0 }
1615 };
1616 static const struct message WmSHOWNATopVisible[] = {
1617     { WM_SHOWWINDOW, sent|wparam, 1 },
1618     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1619     { WM_NCPAINT, sent|wparam|optional, 1 },
1620     { WM_GETTEXT, sent|defwinproc|optional },
1621     { WM_ERASEBKGND, sent|optional },
1622     { WM_WINDOWPOSCHANGED, sent|optional },
1623     { 0 }
1624 };
1625 static const struct message WmSHOWNATopInvisible[] = {
1626     { WM_NOTIFYFORMAT, sent|optional },
1627     { WM_QUERYUISTATE, sent|optional },
1628     { WM_WINDOWPOSCHANGING, sent|optional },
1629     { WM_GETMINMAXINFO, sent|optional },
1630     { WM_NCCALCSIZE, sent|optional },
1631     { WM_WINDOWPOSCHANGED, sent|optional },
1632     { WM_SHOWWINDOW, sent|wparam, 1 },
1633     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1634     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1635     { WM_NCPAINT, sent|wparam, 1 },
1636     { WM_GETTEXT, sent|defwinproc|optional },
1637     { WM_ERASEBKGND, sent|optional },
1638     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1639     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1640     { WM_NCPAINT, sent|wparam|optional, 1 },
1641     { WM_ERASEBKGND, sent|optional },
1642     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1643     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1644     { WM_MOVE, sent },
1645     { 0 }
1646 };
1647
1648 static int after_end_dialog, test_def_id;
1649 static int sequence_cnt, sequence_size;
1650 static struct recvd_message* sequence;
1651 static int log_all_parent_messages;
1652 static int paint_loop_done;
1653
1654 /* user32 functions */
1655 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1656 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1657 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1658 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1659 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1660 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1661 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1662 /* kernel32 functions */
1663 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1664
1665 static void init_procs(void)
1666 {
1667     HMODULE user32 = GetModuleHandleA("user32.dll");
1668     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1669
1670 #define GET_PROC(dll, func) \
1671     p ## func = (void*)GetProcAddress(dll, #func); \
1672     if(!p ## func) { \
1673       trace("GetProcAddress(%s) failed\n", #func); \
1674     }
1675
1676     GET_PROC(user32, GetAncestor)
1677     GET_PROC(user32, GetMenuInfo)
1678     GET_PROC(user32, NotifyWinEvent)
1679     GET_PROC(user32, SetMenuInfo)
1680     GET_PROC(user32, SetWinEventHook)
1681     GET_PROC(user32, TrackMouseEvent)
1682     GET_PROC(user32, UnhookWinEvent)
1683
1684     GET_PROC(kernel32, GetCPInfoExA)
1685
1686 #undef GET_PROC
1687 }
1688
1689 static const char *get_winpos_flags(UINT flags)
1690 {
1691     static char buffer[300];
1692
1693     buffer[0] = 0;
1694 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1695     DUMP( SWP_SHOWWINDOW );
1696     DUMP( SWP_HIDEWINDOW );
1697     DUMP( SWP_NOACTIVATE );
1698     DUMP( SWP_FRAMECHANGED );
1699     DUMP( SWP_NOCOPYBITS );
1700     DUMP( SWP_NOOWNERZORDER );
1701     DUMP( SWP_NOSENDCHANGING );
1702     DUMP( SWP_DEFERERASE );
1703     DUMP( SWP_ASYNCWINDOWPOS );
1704     DUMP( SWP_NOZORDER );
1705     DUMP( SWP_NOREDRAW );
1706     DUMP( SWP_NOSIZE );
1707     DUMP( SWP_NOMOVE );
1708     DUMP( SWP_NOCLIENTSIZE );
1709     DUMP( SWP_NOCLIENTMOVE );
1710     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1711     return buffer + 1;
1712 #undef DUMP
1713 }
1714
1715
1716 #define add_message(msg) add_message_(__LINE__,msg);
1717 static void add_message_(int line, const struct recvd_message *msg)
1718 {
1719     struct recvd_message *seq;
1720
1721     if (!sequence) 
1722     {
1723         sequence_size = 10;
1724         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1725     }
1726     if (sequence_cnt == sequence_size) 
1727     {
1728         sequence_size *= 2;
1729         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1730     }
1731     assert(sequence);
1732
1733     seq = &sequence[sequence_cnt];
1734     seq->hwnd = msg->hwnd;
1735     seq->message = msg->message;
1736     seq->flags = msg->flags;
1737     seq->wParam = msg->wParam;
1738     seq->lParam = msg->lParam;
1739     seq->line   = line;
1740     seq->descr  = msg->descr;
1741     seq->output[0] = 0;
1742
1743     if (msg->descr)
1744     {
1745         if (msg->flags & hook)
1746         {
1747             static const char * const CBT_code_name[10] =
1748             {
1749                 "HCBT_MOVESIZE",
1750                 "HCBT_MINMAX",
1751                 "HCBT_QS",
1752                 "HCBT_CREATEWND",
1753                 "HCBT_DESTROYWND",
1754                 "HCBT_ACTIVATE",
1755                 "HCBT_CLICKSKIPPED",
1756                 "HCBT_KEYSKIPPED",
1757                 "HCBT_SYSCOMMAND",
1758                 "HCBT_SETFOCUS"
1759             };
1760             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1761
1762             snprintf( seq->output, sizeof(seq->output), "%s: hook %d (%s) wp %08lx lp %08lx",
1763                       msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1764         }
1765         else if (msg->flags & winevent_hook)
1766         {
1767             snprintf( seq->output, sizeof(seq->output), "%s: winevent %p %08x %08lx %08lx",
1768                       msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1769         }
1770         else
1771         {
1772             switch (msg->message)
1773             {
1774             case WM_WINDOWPOSCHANGING:
1775             case WM_WINDOWPOSCHANGED:
1776             {
1777                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1778
1779                 snprintf( seq->output, sizeof(seq->output),
1780                           "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1781                           msg->descr, msg->hwnd,
1782                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1783                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1784                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1785                           get_winpos_flags(winpos->flags) );
1786
1787                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1788                  * in the high word for internal purposes
1789                  */
1790                 seq->wParam = winpos->flags & 0xffff;
1791                 /* We are not interested in the flags that don't match under XP and Win9x */
1792                 seq->wParam &= ~SWP_NOZORDER;
1793                 break;
1794             }
1795
1796             case WM_DRAWITEM:
1797             {
1798                 DRAW_ITEM_STRUCT di;
1799                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1800
1801                 snprintf( seq->output, sizeof(seq->output),
1802                           "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1803                           msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1804                           dis->itemID, dis->itemAction, dis->itemState);
1805
1806                 di.u.item.type = dis->CtlType;
1807                 di.u.item.ctl_id = dis->CtlID;
1808                 di.u.item.item_id = dis->itemID;
1809                 di.u.item.action = dis->itemAction;
1810                 di.u.item.state = dis->itemState;
1811
1812                 seq->lParam = di.u.lp;
1813                 break;
1814             }
1815             default:
1816                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1817                 snprintf( seq->output, sizeof(seq->output), "%s: %p %04x wp %08lx lp %08lx",
1818                           msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1819             }
1820         }
1821     }
1822
1823     sequence_cnt++;
1824 }
1825
1826 /* try to make sure pending X events have been processed before continuing */
1827 static void flush_events(void)
1828 {
1829     MSG msg;
1830     int diff = 200;
1831     int min_timeout = 100;
1832     DWORD time = GetTickCount() + diff;
1833
1834     while (diff > 0)
1835     {
1836         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1837         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1838         diff = time - GetTickCount();
1839         min_timeout = 50;
1840     }
1841 }
1842
1843 static void flush_sequence(void)
1844 {
1845     HeapFree(GetProcessHeap(), 0, sequence);
1846     sequence = 0;
1847     sequence_cnt = sequence_size = 0;
1848 }
1849
1850 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1851 {
1852     const struct recvd_message *actual = sequence;
1853     unsigned int count = 0;
1854
1855     trace_(file, line)("Failed sequence %s:\n", context );
1856     while (expected->message && actual->message)
1857     {
1858         if (actual->output[0])
1859         {
1860             if (expected->flags & hook)
1861             {
1862                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1863                                     count, expected->message, actual->output );
1864             }
1865             else if (expected->flags & winevent_hook)
1866             {
1867                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1868                                     count, expected->message, actual->output );
1869             }
1870             else
1871             {
1872                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1873                                     count, expected->message, actual->output );
1874             }
1875         }
1876
1877         if (expected->message == actual->message)
1878         {
1879             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1880                 (expected->flags & optional))
1881             {
1882                 /* don't match messages if their defwinproc status differs */
1883                 expected++;
1884             }
1885             else
1886             {
1887                 expected++;
1888                 actual++;
1889             }
1890         }
1891         /* silently drop winevent messages if there is no support for them */
1892         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1893             expected++;
1894         else
1895         {
1896             expected++;
1897             actual++;
1898         }
1899         count++;
1900     }
1901
1902     /* optional trailing messages */
1903     while (expected->message && ((expected->flags & optional) ||
1904             ((expected->flags & winevent_hook) && !hEvent_hook)))
1905     {
1906         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1907         expected++;
1908         count++;
1909     }
1910
1911     if (expected->message)
1912         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1913     else if (actual->message && actual->output[0])
1914         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1915 }
1916
1917 #define ok_sequence( exp, contx, todo) \
1918         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1919
1920
1921 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1922                          const char *file, int line)
1923 {
1924     static const struct recvd_message end_of_sequence;
1925     const struct message *expected = expected_list;
1926     const struct recvd_message *actual;
1927     int failcount = 0, dump = 0;
1928     unsigned int count = 0;
1929
1930     add_message(&end_of_sequence);
1931
1932     actual = sequence;
1933
1934     while (expected->message && actual->message)
1935     {
1936         if (expected->message == actual->message)
1937         {
1938             if (expected->flags & wparam)
1939             {
1940                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1941                 {
1942                     todo_wine {
1943                         failcount ++;
1944                         if (strcmp(winetest_platform, "wine")) dump++;
1945                         ok_( file, line) (FALSE,
1946                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1947                             context, count, expected->message, expected->wParam, actual->wParam);
1948                     }
1949                 }
1950                 else
1951                 {
1952                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
1953                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1954                                      context, count, expected->message, expected->wParam, actual->wParam);
1955                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
1956                 }
1957
1958             }
1959             if (expected->flags & lparam)
1960             {
1961                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
1962                 {
1963                     todo_wine {
1964                         failcount ++;
1965                         if (strcmp(winetest_platform, "wine")) dump++;
1966                         ok_( file, line) (FALSE,
1967                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1968                             context, count, expected->message, expected->lParam, actual->lParam);
1969                     }
1970                 }
1971                 else
1972                 {
1973                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
1974                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1975                                      context, count, expected->message, expected->lParam, actual->lParam);
1976                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
1977                 }
1978             }
1979             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1980                 (expected->flags & optional))
1981             {
1982                 /* don't match messages if their defwinproc status differs */
1983                 expected++;
1984                 count++;
1985                 continue;
1986             }
1987             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1988             {
1989                     todo_wine {
1990                         failcount ++;
1991                         if (strcmp(winetest_platform, "wine")) dump++;
1992                         ok_( file, line) (FALSE,
1993                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1994                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1995                     }
1996             }
1997             else
1998             {
1999                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2000                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2001                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2002                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2003             }
2004
2005             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2006                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2007                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2008             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2009
2010             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2011                 "%s: %u: the msg 0x%04x should have been %s\n",
2012                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2013             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2014
2015             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2016                 "%s: %u: the msg 0x%04x was expected in %s\n",
2017                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2018             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2019
2020             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2021                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2022                 context, count, expected->message);
2023             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2024
2025             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2026                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2027                 context, count, expected->message);
2028             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2029
2030             expected++;
2031             actual++;
2032         }
2033         /* silently drop hook messages if there is no support for them */
2034         else if ((expected->flags & optional) ||
2035                  ((expected->flags & hook) && !hCBT_hook) ||
2036                  ((expected->flags & winevent_hook) && !hEvent_hook))
2037             expected++;
2038         else if (todo)
2039         {
2040             failcount++;
2041             todo_wine {
2042                 if (strcmp(winetest_platform, "wine")) dump++;
2043                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2044                                   context, count, expected->message, actual->message);
2045             }
2046             goto done;
2047         }
2048         else
2049         {
2050             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2051                               context, count, expected->message, actual->message);
2052             dump++;
2053             expected++;
2054             actual++;
2055         }
2056         count++;
2057     }
2058
2059     /* skip all optional trailing messages */
2060     while (expected->message && ((expected->flags & optional) ||
2061                                  ((expected->flags & hook) && !hCBT_hook) ||
2062                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2063         expected++;
2064
2065     if (todo)
2066     {
2067         todo_wine {
2068             if (expected->message || actual->message) {
2069                 failcount++;
2070                 if (strcmp(winetest_platform, "wine")) dump++;
2071                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2072                                   context, count, expected->message, actual->message);
2073             }
2074         }
2075     }
2076     else
2077     {
2078         if (expected->message || actual->message)
2079         {
2080             dump++;
2081             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2082                               context, count, expected->message, actual->message);
2083         }
2084     }
2085     if( todo && !failcount) /* succeeded yet marked todo */
2086         todo_wine {
2087             if (!strcmp(winetest_platform, "wine")) dump++;
2088             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2089         }
2090
2091 done:
2092     if (dump) dump_sequence(expected_list, context, file, line);
2093     flush_sequence();
2094 }
2095
2096 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2097
2098 /******************************** MDI test **********************************/
2099
2100 /* CreateWindow for MDI frame window, initially visible */
2101 static const struct message WmCreateMDIframeSeq[] = {
2102     { HCBT_CREATEWND, hook },
2103     { WM_GETMINMAXINFO, sent },
2104     { WM_NCCREATE, sent },
2105     { WM_NCCALCSIZE, sent|wparam, 0 },
2106     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2107     { WM_CREATE, sent },
2108     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2109     { WM_NOTIFYFORMAT, sent|optional },
2110     { WM_QUERYUISTATE, sent|optional },
2111     { WM_WINDOWPOSCHANGING, sent|optional },
2112     { WM_GETMINMAXINFO, sent|optional },
2113     { WM_NCCALCSIZE, sent|optional },
2114     { WM_WINDOWPOSCHANGED, sent|optional },
2115     { WM_SHOWWINDOW, sent|wparam, 1 },
2116     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2117     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2118     { HCBT_ACTIVATE, hook },
2119     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2120     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2121     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2122     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2123     { WM_NCACTIVATE, sent|wparam, 1 },
2124     { WM_GETTEXT, sent|defwinproc|optional },
2125     { WM_ACTIVATE, sent|wparam, 1 },
2126     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2127     { HCBT_SETFOCUS, hook },
2128     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2129     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2130     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2131     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2132     /* Win9x adds SWP_NOZORDER below */
2133     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2134     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2135     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2136     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2137     { WM_MOVE, sent },
2138     { 0 }
2139 };
2140 /* DestroyWindow for MDI frame window, initially visible */
2141 static const struct message WmDestroyMDIframeSeq[] = {
2142     { HCBT_DESTROYWND, hook },
2143     { 0x0090, sent|optional },
2144     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2145     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2146     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2147     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2148     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2149     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2150     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2151     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2152     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2153     { WM_DESTROY, sent },
2154     { WM_NCDESTROY, sent },
2155     { 0 }
2156 };
2157 /* CreateWindow for MDI client window, initially visible */
2158 static const struct message WmCreateMDIclientSeq[] = {
2159     { HCBT_CREATEWND, hook },
2160     { WM_NCCREATE, sent },
2161     { WM_NCCALCSIZE, sent|wparam, 0 },
2162     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2163     { WM_CREATE, sent },
2164     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2165     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2166     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2167     { WM_MOVE, sent },
2168     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2169     { WM_SHOWWINDOW, sent|wparam, 1 },
2170     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2171     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2172     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2173     { 0 }
2174 };
2175 /* ShowWindow(SW_SHOW) for MDI client window */
2176 static const struct message WmShowMDIclientSeq[] = {
2177     { WM_SHOWWINDOW, sent|wparam, 1 },
2178     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2179     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2180     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2181     { 0 }
2182 };
2183 /* ShowWindow(SW_HIDE) for MDI client window */
2184 static const struct message WmHideMDIclientSeq[] = {
2185     { WM_SHOWWINDOW, sent|wparam, 0 },
2186     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2187     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2188     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2189     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2190     { 0 }
2191 };
2192 /* DestroyWindow for MDI client window, initially visible */
2193 static const struct message WmDestroyMDIclientSeq[] = {
2194     { HCBT_DESTROYWND, hook },
2195     { 0x0090, sent|optional },
2196     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2197     { WM_SHOWWINDOW, sent|wparam, 0 },
2198     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2199     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2200     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2201     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2202     { WM_DESTROY, sent },
2203     { WM_NCDESTROY, sent },
2204     { 0 }
2205 };
2206 /* CreateWindow for MDI child window, initially visible */
2207 static const struct message WmCreateMDIchildVisibleSeq[] = {
2208     { HCBT_CREATEWND, hook },
2209     { WM_NCCREATE, sent }, 
2210     { WM_NCCALCSIZE, sent|wparam, 0 },
2211     { WM_CREATE, sent },
2212     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2213     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2214     { WM_MOVE, sent },
2215     /* Win2k sends wparam set to
2216      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2217      * while Win9x doesn't bother to set child window id according to
2218      * CLIENTCREATESTRUCT.idFirstChild
2219      */
2220     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2221     { WM_SHOWWINDOW, sent|wparam, 1 },
2222     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2223     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2224     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2225     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2226     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2227     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2228     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2229
2230     /* Win9x: message sequence terminates here. */
2231
2232     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2233     { HCBT_SETFOCUS, hook }, /* in MDI client */
2234     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2235     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2236     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2237     { WM_SETFOCUS, sent }, /* in MDI client */
2238     { HCBT_SETFOCUS, hook },
2239     { WM_KILLFOCUS, sent }, /* in MDI client */
2240     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2241     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2242     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2243     { WM_SETFOCUS, sent|defwinproc },
2244     { WM_MDIACTIVATE, sent|defwinproc },
2245     { 0 }
2246 };
2247 /* CreateWindow for MDI child window with invisible parent */
2248 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2249     { HCBT_CREATEWND, hook },
2250     { WM_GETMINMAXINFO, sent },
2251     { WM_NCCREATE, sent }, 
2252     { WM_NCCALCSIZE, sent|wparam, 0 },
2253     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2254     { WM_CREATE, sent },
2255     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2256     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2257     { WM_MOVE, sent },
2258     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2259     { WM_SHOWWINDOW, sent|wparam, 1 },
2260     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2261     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2262     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2263     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2264
2265     /* Win9x: message sequence terminates here. */
2266
2267     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2268     { HCBT_SETFOCUS, hook }, /* in MDI client */
2269     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2270     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2271     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2272     { WM_SETFOCUS, sent }, /* in MDI client */
2273     { HCBT_SETFOCUS, hook },
2274     { WM_KILLFOCUS, sent }, /* in MDI client */
2275     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2276     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2277     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2278     { WM_SETFOCUS, sent|defwinproc },
2279     { WM_MDIACTIVATE, sent|defwinproc },
2280     { 0 }
2281 };
2282 /* DestroyWindow for MDI child window, initially visible */
2283 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2284     { HCBT_DESTROYWND, hook },
2285     /* Win2k sends wparam set to
2286      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2287      * while Win9x doesn't bother to set child window id according to
2288      * CLIENTCREATESTRUCT.idFirstChild
2289      */
2290     { 0x0090, sent|optional },
2291     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2292     { WM_SHOWWINDOW, sent|wparam, 0 },
2293     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2294     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2295     { WM_ERASEBKGND, sent|parent|optional },
2296     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2297
2298     /* { WM_DESTROY, sent }
2299      * Win9x: message sequence terminates here.
2300      */
2301
2302     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2303     { WM_KILLFOCUS, sent },
2304     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2305     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2306     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2307     { WM_SETFOCUS, sent }, /* in MDI client */
2308
2309     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2310     { WM_KILLFOCUS, sent }, /* in MDI client */
2311     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2312     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2313     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2314     { WM_SETFOCUS, sent }, /* in MDI client */
2315
2316     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2317
2318     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2319     { WM_KILLFOCUS, sent },
2320     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2321     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2322     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2323     { WM_SETFOCUS, sent }, /* in MDI client */
2324
2325     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2326     { WM_KILLFOCUS, sent }, /* in MDI client */
2327     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2328     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2329     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2330     { WM_SETFOCUS, sent }, /* in MDI client */
2331
2332     { WM_DESTROY, sent },
2333
2334     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2335     { WM_KILLFOCUS, sent },
2336     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2337     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2338     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2339     { WM_SETFOCUS, sent }, /* in MDI client */
2340
2341     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2342     { WM_KILLFOCUS, sent }, /* in MDI client */
2343     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2344     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2345     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2346     { WM_SETFOCUS, sent }, /* in MDI client */
2347
2348     { WM_NCDESTROY, sent },
2349     { 0 }
2350 };
2351 /* CreateWindow for MDI child window, initially invisible */
2352 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2353     { HCBT_CREATEWND, hook },
2354     { WM_NCCREATE, sent }, 
2355     { WM_NCCALCSIZE, sent|wparam, 0 },
2356     { WM_CREATE, sent },
2357     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2358     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2359     { WM_MOVE, sent },
2360     /* Win2k sends wparam set to
2361      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2362      * while Win9x doesn't bother to set child window id according to
2363      * CLIENTCREATESTRUCT.idFirstChild
2364      */
2365     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2366     { 0 }
2367 };
2368 /* DestroyWindow for MDI child window, initially invisible */
2369 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2370     { HCBT_DESTROYWND, hook },
2371     /* Win2k sends wparam set to
2372      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2373      * while Win9x doesn't bother to set child window id according to
2374      * CLIENTCREATESTRUCT.idFirstChild
2375      */
2376     { 0x0090, sent|optional },
2377     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2378     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2379     { WM_DESTROY, sent },
2380     { WM_NCDESTROY, sent },
2381     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2382     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2383     { 0 }
2384 };
2385 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2386 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2387     { HCBT_CREATEWND, hook },
2388     { WM_NCCREATE, sent }, 
2389     { WM_NCCALCSIZE, sent|wparam, 0 },
2390     { WM_CREATE, sent },
2391     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2392     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2393     { WM_MOVE, sent },
2394     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2395     { WM_GETMINMAXINFO, sent },
2396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2397     { WM_NCCALCSIZE, sent|wparam, 1 },
2398     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2399     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2400      /* in MDI frame */
2401     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2402     { WM_NCCALCSIZE, sent|wparam, 1 },
2403     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2404     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2405     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2406     /* Win2k sends wparam set to
2407      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2408      * while Win9x doesn't bother to set child window id according to
2409      * CLIENTCREATESTRUCT.idFirstChild
2410      */
2411     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2412     { WM_SHOWWINDOW, sent|wparam, 1 },
2413     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2414     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2415     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2416     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2417     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2418     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2419     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2420
2421     /* Win9x: message sequence terminates here. */
2422
2423     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2424     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2425     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2426     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2427     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2428     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2429     { HCBT_SETFOCUS, hook|optional },
2430     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2431     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2432     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2433     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2434     { WM_SETFOCUS, sent|defwinproc|optional },
2435     { WM_MDIACTIVATE, sent|defwinproc|optional },
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     { 0 }
2442 };
2443 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2444 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2445     /* restore the 1st MDI child */
2446     { WM_SETREDRAW, sent|wparam, 0 },
2447     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2448     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2449     { WM_NCCALCSIZE, sent|wparam, 1 },
2450     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2451     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2452     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2453      /* in MDI frame */
2454     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2455     { WM_NCCALCSIZE, sent|wparam, 1 },
2456     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2457     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2459     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2460     /* create the 2nd MDI child */
2461     { HCBT_CREATEWND, hook },
2462     { WM_NCCREATE, sent }, 
2463     { WM_NCCALCSIZE, sent|wparam, 0 },
2464     { WM_CREATE, sent },
2465     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2466     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2467     { WM_MOVE, sent },
2468     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2469     { WM_GETMINMAXINFO, sent },
2470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2471     { WM_NCCALCSIZE, sent|wparam, 1 },
2472     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2473     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2474     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2475      /* in MDI frame */
2476     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2477     { WM_NCCALCSIZE, sent|wparam, 1 },
2478     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2479     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2480     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2481     /* Win2k sends wparam set to
2482      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2483      * while Win9x doesn't bother to set child window id according to
2484      * CLIENTCREATESTRUCT.idFirstChild
2485      */
2486     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2487     { WM_SHOWWINDOW, sent|wparam, 1 },
2488     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2489     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2490     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2491     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2492     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2493     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2494
2495     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2496     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2497
2498     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2499
2500     /* Win9x: message sequence terminates here. */
2501
2502     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2503     { HCBT_SETFOCUS, hook },
2504     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2505     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2506     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2507     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2508     { WM_SETFOCUS, sent }, /* in MDI client */
2509     { HCBT_SETFOCUS, hook },
2510     { WM_KILLFOCUS, sent }, /* in MDI client */
2511     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2512     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2513     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2514     { WM_SETFOCUS, sent|defwinproc },
2515
2516     { WM_MDIACTIVATE, sent|defwinproc },
2517      /* in MDI frame */
2518     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2519     { WM_NCCALCSIZE, sent|wparam, 1 },
2520     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2521     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2522     { 0 }
2523 };
2524 /* WM_MDICREATE MDI child window, initially visible and maximized */
2525 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2526     { WM_MDICREATE, sent },
2527     { HCBT_CREATEWND, hook },
2528     { WM_NCCREATE, sent }, 
2529     { WM_NCCALCSIZE, sent|wparam, 0 },
2530     { WM_CREATE, sent },
2531     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2532     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2533     { WM_MOVE, sent },
2534     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2535     { WM_GETMINMAXINFO, sent },
2536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2537     { WM_NCCALCSIZE, sent|wparam, 1 },
2538     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2539     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2540
2541      /* in MDI frame */
2542     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2543     { WM_NCCALCSIZE, sent|wparam, 1 },
2544     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2545     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2546     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2547
2548     /* Win2k sends wparam set to
2549      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2550      * while Win9x doesn't bother to set child window id according to
2551      * CLIENTCREATESTRUCT.idFirstChild
2552      */
2553     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2554     { WM_SHOWWINDOW, sent|wparam, 1 },
2555     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2556
2557     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2558
2559     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2560     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2561     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2562
2563     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2564     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2565
2566     /* Win9x: message sequence terminates here. */
2567
2568     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2569     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2570     { HCBT_SETFOCUS, hook }, /* in MDI client */
2571     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2572     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2573     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2574     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2575     { HCBT_SETFOCUS, hook|optional },
2576     { WM_KILLFOCUS, sent }, /* in MDI client */
2577     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2578     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2579     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2580     { WM_SETFOCUS, sent|defwinproc },
2581
2582     { WM_MDIACTIVATE, sent|defwinproc },
2583
2584      /* in MDI child */
2585     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2586     { WM_NCCALCSIZE, sent|wparam, 1 },
2587     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2588     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2589
2590      /* in MDI frame */
2591     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2592     { WM_NCCALCSIZE, sent|wparam, 1 },
2593     { 0x0093, sent|defwinproc|optional },
2594     { 0x0093, sent|defwinproc|optional },
2595     { 0x0093, sent|defwinproc|optional },
2596     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2597     { WM_MOVE, sent|defwinproc },
2598     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2599
2600      /* in MDI client */
2601     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2602     { WM_NCCALCSIZE, sent|wparam, 1 },
2603     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2604     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2605
2606      /* in MDI child */
2607     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2608     { WM_NCCALCSIZE, sent|wparam, 1 },
2609     { 0x0093, sent|optional },
2610     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2611     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2612
2613     { 0x0093, sent|optional },
2614     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2615     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2616     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2617     { 0x0093, sent|defwinproc|optional },
2618     { 0x0093, sent|defwinproc|optional },
2619     { 0x0093, sent|defwinproc|optional },
2620     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2621     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2622
2623     { 0 }
2624 };
2625 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2626 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2627     { HCBT_CREATEWND, hook },
2628     { WM_GETMINMAXINFO, sent },
2629     { WM_NCCREATE, sent }, 
2630     { WM_NCCALCSIZE, sent|wparam, 0 },
2631     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2632     { WM_CREATE, sent },
2633     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2634     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2635     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2636     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2637     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2638     { WM_MOVE, sent },
2639     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2640     { WM_GETMINMAXINFO, sent },
2641     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2642     { WM_GETMINMAXINFO, sent|defwinproc },
2643     { WM_NCCALCSIZE, sent|wparam, 1 },
2644     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2645     { WM_MOVE, sent|defwinproc },
2646     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2647      /* in MDI frame */
2648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2649     { WM_NCCALCSIZE, sent|wparam, 1 },
2650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2651     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2652     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2653     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2654     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2655     /* Win2k sends wparam set to
2656      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2657      * while Win9x doesn't bother to set child window id according to
2658      * CLIENTCREATESTRUCT.idFirstChild
2659      */
2660     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2661     { 0 }
2662 };
2663 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2664 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2665     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2666     { HCBT_SYSCOMMAND, hook },
2667     { WM_CLOSE, sent|defwinproc },
2668     { WM_MDIDESTROY, sent }, /* in MDI client */
2669
2670     /* bring the 1st MDI child to top */
2671     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2672     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2673
2674     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2675
2676     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2677     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2678     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2679
2680     /* maximize the 1st MDI child */
2681     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2682     { WM_GETMINMAXINFO, sent|defwinproc },
2683     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2684     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2685     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2686     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2687     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2688
2689     /* restore the 2nd MDI child */
2690     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2691     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2692     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2693     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2694
2695     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2696
2697     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2698     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2699
2700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2701
2702     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2703      /* in MDI frame */
2704     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2705     { WM_NCCALCSIZE, sent|wparam, 1 },
2706     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2707     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2708     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2709
2710     /* bring the 1st MDI child to top */
2711     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2712     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2713     { HCBT_SETFOCUS, hook },
2714     { WM_KILLFOCUS, sent|defwinproc },
2715     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2716     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2717     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2718     { WM_SETFOCUS, sent }, /* in MDI client */
2719     { HCBT_SETFOCUS, hook },
2720     { WM_KILLFOCUS, sent }, /* in MDI client */
2721     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2722     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2723     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2724     { WM_SETFOCUS, sent|defwinproc },
2725     { WM_MDIACTIVATE, sent|defwinproc },
2726     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2727
2728     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2729     { WM_SHOWWINDOW, sent|wparam, 1 },
2730     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2731     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2732     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2733     { WM_MDIREFRESHMENU, sent },
2734
2735     { HCBT_DESTROYWND, hook },
2736     /* Win2k sends wparam set to
2737      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2738      * while Win9x doesn't bother to set child window id according to
2739      * CLIENTCREATESTRUCT.idFirstChild
2740      */
2741     { 0x0090, sent|defwinproc|optional },
2742     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2743     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2744     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2745     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2746     { WM_ERASEBKGND, sent|parent|optional },
2747     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2748
2749     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2750     { WM_DESTROY, sent|defwinproc },
2751     { WM_NCDESTROY, sent|defwinproc },
2752     { 0 }
2753 };
2754 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2755 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2756     { WM_MDIDESTROY, sent }, /* in MDI client */
2757     { WM_SHOWWINDOW, sent|wparam, 0 },
2758     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2759     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2760     { WM_ERASEBKGND, sent|parent|optional },
2761     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2762
2763     { HCBT_SETFOCUS, hook },
2764     { WM_KILLFOCUS, sent },
2765     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2766     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2767     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2768     { WM_SETFOCUS, sent }, /* in MDI client */
2769     { HCBT_SETFOCUS, hook },
2770     { WM_KILLFOCUS, sent }, /* in MDI client */
2771     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2772     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2773     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2774     { WM_SETFOCUS, sent },
2775
2776      /* in MDI child */
2777     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2778     { WM_NCCALCSIZE, sent|wparam, 1 },
2779     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2780     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2781
2782      /* in MDI frame */
2783     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2784     { WM_NCCALCSIZE, sent|wparam, 1 },
2785     { 0x0093, sent|defwinproc|optional },
2786     { 0x0093, sent|defwinproc|optional },
2787     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2788     { WM_MOVE, sent|defwinproc },
2789     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2790
2791      /* in MDI client */
2792     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2793     { WM_NCCALCSIZE, sent|wparam, 1 },
2794     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2795     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2796
2797      /* in MDI child */
2798     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2799     { WM_NCCALCSIZE, sent|wparam, 1 },
2800     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2801     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2802
2803      /* in MDI child */
2804     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2805     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2806     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2807     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2808
2809      /* in MDI frame */
2810     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2812     { 0x0093, sent|defwinproc|optional },
2813     { 0x0093, sent|defwinproc|optional },
2814     { 0x0093, sent|defwinproc|optional },
2815     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2816     { WM_MOVE, sent|defwinproc },
2817     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2818
2819      /* in MDI client */
2820     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2821     { WM_NCCALCSIZE, sent|wparam, 1 },
2822     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2823     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2824
2825      /* in MDI child */
2826     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2827     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2828     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2829     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2830     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2831     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2832
2833     { 0x0093, sent|defwinproc|optional },
2834     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2835     { 0x0093, sent|defwinproc|optional },
2836     { 0x0093, sent|defwinproc|optional },
2837     { 0x0093, sent|defwinproc|optional },
2838     { 0x0093, sent|optional },
2839
2840     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2841     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2842     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2843     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2844     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2845
2846      /* in MDI frame */
2847     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2848     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2849     { 0x0093, sent|defwinproc|optional },
2850     { 0x0093, sent|defwinproc|optional },
2851     { 0x0093, sent|defwinproc|optional },
2852     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2853     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2854     { 0x0093, sent|optional },
2855
2856     { WM_NCACTIVATE, sent|wparam, 0 },
2857     { WM_MDIACTIVATE, sent },
2858
2859     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2860     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2861     { WM_NCCALCSIZE, sent|wparam, 1 },
2862
2863     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2864
2865     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2866     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2867     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2868
2869      /* in MDI child */
2870     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2871     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2872     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2874
2875      /* in MDI frame */
2876     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2877     { WM_NCCALCSIZE, sent|wparam, 1 },
2878     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2879     { WM_MOVE, sent|defwinproc },
2880     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2881
2882      /* in MDI client */
2883     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2884     { WM_NCCALCSIZE, sent|wparam, 1 },
2885     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2886     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2887     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2888     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2889     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2890     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2891     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2892
2893     { HCBT_SETFOCUS, hook },
2894     { WM_KILLFOCUS, sent },
2895     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2896     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2897     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2898     { WM_SETFOCUS, sent }, /* in MDI client */
2899
2900     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2901
2902     { HCBT_DESTROYWND, hook },
2903     /* Win2k sends wparam set to
2904      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2905      * while Win9x doesn't bother to set child window id according to
2906      * CLIENTCREATESTRUCT.idFirstChild
2907      */
2908     { 0x0090, sent|optional },
2909     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2910
2911     { WM_SHOWWINDOW, sent|wparam, 0 },
2912     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2913     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2914     { WM_ERASEBKGND, sent|parent|optional },
2915     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2916
2917     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2918     { WM_DESTROY, sent },
2919     { WM_NCDESTROY, sent },
2920     { 0 }
2921 };
2922 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2923 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2924     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2925     { WM_GETMINMAXINFO, sent },
2926     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2927     { WM_NCCALCSIZE, sent|wparam, 1 },
2928     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2929     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2930
2931     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2932     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2933     { HCBT_SETFOCUS, hook|optional },
2934     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2935     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2936     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2937     { HCBT_SETFOCUS, hook|optional },
2938     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2939     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2940     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2941     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2942     { WM_SETFOCUS, sent|optional|defwinproc },
2943     { WM_MDIACTIVATE, sent|optional|defwinproc },
2944     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2945     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2946      /* in MDI frame */
2947     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2948     { WM_NCCALCSIZE, sent|wparam, 1 },
2949     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2950     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2951     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2952     { 0 }
2953 };
2954 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2955 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2956     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2957     { WM_GETMINMAXINFO, sent },
2958     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2959     { WM_GETMINMAXINFO, sent|defwinproc },
2960     { WM_NCCALCSIZE, sent|wparam, 1 },
2961     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2962     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2963
2964     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2965     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2966     { HCBT_SETFOCUS, hook|optional },
2967     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2968     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2969     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2970     { HCBT_SETFOCUS, hook|optional },
2971     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2972     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2973     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2974     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2975     { WM_SETFOCUS, sent|defwinproc|optional },
2976     { WM_MDIACTIVATE, sent|defwinproc|optional },
2977     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2978     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2979     { 0 }
2980 };
2981 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2982 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2983     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2984     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2985     { WM_GETMINMAXINFO, sent },
2986     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2987     { WM_GETMINMAXINFO, sent|defwinproc },
2988     { WM_NCCALCSIZE, sent|wparam, 1 },
2989     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2990     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2991     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2992     { WM_MOVE, sent|defwinproc },
2993     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2994
2995     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2996     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2997     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2998     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2999     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3000     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3001      /* in MDI frame */
3002     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3003     { WM_NCCALCSIZE, sent|wparam, 1 },
3004     { 0x0093, sent|defwinproc|optional },
3005     { 0x0094, sent|defwinproc|optional },
3006     { 0x0094, sent|defwinproc|optional },
3007     { 0x0094, sent|defwinproc|optional },
3008     { 0x0094, sent|defwinproc|optional },
3009     { 0x0093, sent|defwinproc|optional },
3010     { 0x0093, sent|defwinproc|optional },
3011     { 0x0091, sent|defwinproc|optional },
3012     { 0x0092, sent|defwinproc|optional },
3013     { 0x0092, sent|defwinproc|optional },
3014     { 0x0092, sent|defwinproc|optional },
3015     { 0x0092, sent|defwinproc|optional },
3016     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3017     { WM_MOVE, sent|defwinproc },
3018     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3019     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3020      /* in MDI client */
3021     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3022     { WM_NCCALCSIZE, sent|wparam, 1 },
3023     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3024     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3025      /* in MDI child */
3026     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3027     { WM_GETMINMAXINFO, sent|defwinproc },
3028     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3029     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3030     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3032     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3033     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3034     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3035     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3036      /* in MDI frame */
3037     { 0x0093, sent|optional },
3038     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3039     { 0x0093, sent|defwinproc|optional },
3040     { 0x0093, sent|defwinproc|optional },
3041     { 0x0093, sent|defwinproc|optional },
3042     { 0x0091, sent|defwinproc|optional },
3043     { 0x0092, sent|defwinproc|optional },
3044     { 0x0092, sent|defwinproc|optional },
3045     { 0x0092, sent|defwinproc|optional },
3046     { 0x0092, sent|defwinproc|optional },
3047     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3048     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3049     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3050     { 0 }
3051 };
3052 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3053 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3054     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3055     { WM_GETMINMAXINFO, sent },
3056     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3057     { WM_NCCALCSIZE, sent|wparam, 1 },
3058     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3059     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3060     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3061      /* in MDI frame */
3062     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3063     { WM_NCCALCSIZE, sent|wparam, 1 },
3064     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3065     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3066     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3067     { 0 }
3068 };
3069 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3070 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3071     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3072     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3073     { WM_NCCALCSIZE, sent|wparam, 1 },
3074     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3075     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3076     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3077      /* in MDI frame */
3078     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3079     { WM_NCCALCSIZE, sent|wparam, 1 },
3080     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3081     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3082     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3083     { 0 }
3084 };
3085 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3086 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3087     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3088     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3089     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3090     { WM_NCCALCSIZE, sent|wparam, 1 },
3091     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3092     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3093     { WM_MOVE, sent|defwinproc },
3094     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3095     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3096     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3097     { HCBT_SETFOCUS, hook },
3098     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3099     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3100     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3101     { WM_SETFOCUS, sent },
3102     { 0 }
3103 };
3104 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3105 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3106     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3107     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3108     { WM_NCCALCSIZE, sent|wparam, 1 },
3109     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3110     { WM_MOVE, sent|defwinproc },
3111     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3112     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3113     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3114     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3115     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3116     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3117     { 0 }
3118 };
3119 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3120 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3121     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3122     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3123     { WM_NCCALCSIZE, sent|wparam, 1 },
3124     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3125     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3126     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3127     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3128      /* in MDI frame */
3129     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3130     { WM_NCCALCSIZE, sent|wparam, 1 },
3131     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3132     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3133     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3134     { 0 }
3135 };
3136
3137 static HWND mdi_client;
3138 static WNDPROC old_mdi_client_proc;
3139
3140 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3141 {
3142     struct recvd_message msg;
3143
3144     /* do not log painting messages */
3145     if (message != WM_PAINT &&
3146         message != WM_NCPAINT &&
3147         message != WM_SYNCPAINT &&
3148         message != WM_ERASEBKGND &&
3149         message != WM_NCHITTEST &&
3150         message != WM_GETTEXT &&
3151         message != WM_MDIGETACTIVE &&
3152         message != WM_GETICON &&
3153         message != WM_GETOBJECT &&
3154         message != WM_DEVICECHANGE)
3155     {
3156         msg.hwnd = hwnd;
3157         msg.message = message;
3158         msg.flags = sent|wparam|lparam;
3159         msg.wParam = wParam;
3160         msg.lParam = lParam;
3161         msg.descr = "mdi client";
3162         add_message(&msg);
3163     }
3164
3165     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3166 }
3167
3168 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3169 {
3170     static long defwndproc_counter = 0;
3171     LRESULT ret;
3172     struct recvd_message msg;
3173
3174     /* do not log painting messages */
3175     if (message != WM_PAINT &&
3176         message != WM_NCPAINT &&
3177         message != WM_SYNCPAINT &&
3178         message != WM_ERASEBKGND &&
3179         message != WM_NCHITTEST &&
3180         message != WM_GETTEXT &&
3181         message != WM_GETICON &&
3182         message != WM_GETOBJECT &&
3183         message != WM_DEVICECHANGE)
3184     {
3185         switch (message)
3186         {
3187             case WM_MDIACTIVATE:
3188             {
3189                 HWND active, client = GetParent(hwnd);
3190
3191                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3192
3193                 if (hwnd == (HWND)lParam) /* if we are being activated */
3194                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3195                 else
3196                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3197                 break;
3198             }
3199         }
3200
3201         msg.hwnd = hwnd;
3202         msg.message = message;
3203         msg.flags = sent|wparam|lparam;
3204         if (defwndproc_counter) msg.flags |= defwinproc;
3205         msg.wParam = wParam;
3206         msg.lParam = lParam;
3207         msg.descr = "mdi child";
3208         add_message(&msg);
3209     }
3210
3211     defwndproc_counter++;
3212     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3213     defwndproc_counter--;
3214
3215     return ret;
3216 }
3217
3218 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3219 {
3220     static long defwndproc_counter = 0;
3221     LRESULT ret;
3222     struct recvd_message msg;
3223
3224     /* do not log painting messages */
3225     if (message != WM_PAINT &&
3226         message != WM_NCPAINT &&
3227         message != WM_SYNCPAINT &&
3228         message != WM_ERASEBKGND &&
3229         message != WM_NCHITTEST &&
3230         message != WM_GETTEXT &&
3231         message != WM_GETICON &&
3232         message != WM_GETOBJECT &&
3233         message != WM_DEVICECHANGE)
3234     {
3235         msg.hwnd = hwnd;
3236         msg.message = message;
3237         msg.flags = sent|wparam|lparam;
3238         if (defwndproc_counter) msg.flags |= defwinproc;
3239         msg.wParam = wParam;
3240         msg.lParam = lParam;
3241         msg.descr = "mdi frame";
3242         add_message(&msg);
3243     }
3244
3245     defwndproc_counter++;
3246     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3247     defwndproc_counter--;
3248
3249     return ret;
3250 }
3251
3252 static BOOL mdi_RegisterWindowClasses(void)
3253 {
3254     WNDCLASSA cls;
3255
3256     cls.style = 0;
3257     cls.lpfnWndProc = mdi_frame_wnd_proc;
3258     cls.cbClsExtra = 0;
3259     cls.cbWndExtra = 0;
3260     cls.hInstance = GetModuleHandleA(0);
3261     cls.hIcon = 0;
3262     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3263     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3264     cls.lpszMenuName = NULL;
3265     cls.lpszClassName = "MDI_frame_class";
3266     if (!RegisterClassA(&cls)) return FALSE;
3267
3268     cls.lpfnWndProc = mdi_child_wnd_proc;
3269     cls.lpszClassName = "MDI_child_class";
3270     if (!RegisterClassA(&cls)) return FALSE;
3271
3272     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3273     old_mdi_client_proc = cls.lpfnWndProc;
3274     cls.hInstance = GetModuleHandleA(0);
3275     cls.lpfnWndProc = mdi_client_hook_proc;
3276     cls.lpszClassName = "MDI_client_class";
3277     if (!RegisterClassA(&cls)) assert(0);
3278
3279     return TRUE;
3280 }
3281
3282 static void test_mdi_messages(void)
3283 {
3284     MDICREATESTRUCTA mdi_cs;
3285     CLIENTCREATESTRUCT client_cs;
3286     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3287     BOOL zoomed;
3288     HMENU hMenu = CreateMenu();
3289
3290     assert(mdi_RegisterWindowClasses());
3291
3292     flush_sequence();
3293
3294     trace("creating MDI frame window\n");
3295     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3296                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3297                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3298                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3299                                 GetDesktopWindow(), hMenu,
3300                                 GetModuleHandleA(0), NULL);
3301     assert(mdi_frame);
3302     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3303
3304     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3305     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3306
3307     trace("creating MDI client window\n");
3308     client_cs.hWindowMenu = 0;
3309     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3310     mdi_client = CreateWindowExA(0, "MDI_client_class",
3311                                  NULL,
3312                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3313                                  0, 0, 0, 0,
3314                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3315     assert(mdi_client);
3316     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3317
3318     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3319     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3320
3321     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3322     ok(!active_child, "wrong active MDI child %p\n", active_child);
3323     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3324
3325     SetFocus(0);
3326     flush_sequence();
3327
3328     trace("creating invisible MDI child window\n");
3329     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3330                                 WS_CHILD,
3331                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3332                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3333     assert(mdi_child);
3334
3335     flush_sequence();
3336     ShowWindow(mdi_child, SW_SHOWNORMAL);
3337     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) 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     ShowWindow(mdi_child, SW_HIDE);
3350     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3351     flush_sequence();
3352
3353     ShowWindow(mdi_child, SW_SHOW);
3354     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3355
3356     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3357     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3358
3359     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3360     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3361
3362     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3363     ok(!active_child, "wrong active MDI child %p\n", active_child);
3364     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3365
3366     DestroyWindow(mdi_child);
3367     flush_sequence();
3368
3369     trace("creating visible MDI child window\n");
3370     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3371                                 WS_CHILD | WS_VISIBLE,
3372                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3373                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3374     assert(mdi_child);
3375     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3376
3377     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3378     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3379
3380     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3381     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3382
3383     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3384     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3385     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3386     flush_sequence();
3387
3388     DestroyWindow(mdi_child);
3389     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3390
3391     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3392     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3393
3394     /* Win2k: MDI client still returns a just destroyed child as active
3395      * Win9x: MDI client returns 0
3396      */
3397     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3398     ok(active_child == mdi_child || /* win2k */
3399        !active_child, /* win9x */
3400        "wrong active MDI child %p\n", active_child);
3401     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3402
3403     flush_sequence();
3404
3405     trace("creating invisible MDI child window\n");
3406     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3407                                 WS_CHILD,
3408                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3409                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3410     assert(mdi_child2);
3411     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3412
3413     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3414     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3415
3416     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3417     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3418
3419     /* Win2k: MDI client still returns a just destroyed child as active
3420      * Win9x: MDI client returns mdi_child2
3421      */
3422     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3423     ok(active_child == mdi_child || /* win2k */
3424        active_child == mdi_child2, /* win9x */
3425        "wrong active MDI child %p\n", active_child);
3426     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3427     flush_sequence();
3428
3429     ShowWindow(mdi_child2, SW_MAXIMIZE);
3430     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3431
3432     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3433     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3434
3435     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3436     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3437     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3438     flush_sequence();
3439
3440     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3441     ok(GetFocus() == mdi_child2 || /* win2k */
3442        GetFocus() == 0, /* win9x */
3443        "wrong focus window %p\n", GetFocus());
3444
3445     SetFocus(0);
3446     flush_sequence();
3447
3448     ShowWindow(mdi_child2, SW_HIDE);
3449     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3450
3451     ShowWindow(mdi_child2, SW_RESTORE);
3452     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3453     flush_sequence();
3454
3455     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3456     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3457
3458     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3459     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3460     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3461     flush_sequence();
3462
3463     SetFocus(0);
3464     flush_sequence();
3465
3466     ShowWindow(mdi_child2, SW_HIDE);
3467     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3468
3469     ShowWindow(mdi_child2, SW_SHOW);
3470     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3471
3472     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3473     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3474
3475     ShowWindow(mdi_child2, SW_MAXIMIZE);
3476     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3477
3478     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3479     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3480
3481     ShowWindow(mdi_child2, SW_RESTORE);
3482     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3483
3484     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3485     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3486
3487     ShowWindow(mdi_child2, SW_MINIMIZE);
3488     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3489
3490     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3491     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3492
3493     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3494     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3495     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3496     flush_sequence();
3497
3498     ShowWindow(mdi_child2, SW_RESTORE);
3499     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3500
3501     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3502     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3503
3504     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3505     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3506     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3507     flush_sequence();
3508
3509     SetFocus(0);
3510     flush_sequence();
3511
3512     ShowWindow(mdi_child2, SW_HIDE);
3513     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3514
3515     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3516     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3517
3518     DestroyWindow(mdi_child2);
3519     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3520
3521     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3522     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3523
3524     /* test for maximized MDI children */
3525     trace("creating maximized visible MDI child window 1\n");
3526     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3527                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3528                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3529                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3530     assert(mdi_child);
3531     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3532     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3533
3534     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3535     ok(GetFocus() == mdi_child || /* win2k */
3536        GetFocus() == 0, /* win9x */
3537        "wrong focus window %p\n", GetFocus());
3538
3539     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3540     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3541     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3542     flush_sequence();
3543
3544     trace("creating maximized visible MDI child window 2\n");
3545     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3546                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3547                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3548                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3549     assert(mdi_child2);
3550     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3551     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3552     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3553
3554     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3555     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3556
3557     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3558     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3559     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3560     flush_sequence();
3561
3562     trace("destroying maximized visible MDI child window 2\n");
3563     DestroyWindow(mdi_child2);
3564     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3565
3566     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3567
3568     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3569     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3570
3571     /* Win2k: MDI client still returns a just destroyed child as active
3572      * Win9x: MDI client returns 0
3573      */
3574     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3575     ok(active_child == mdi_child2 || /* win2k */
3576        !active_child, /* win9x */
3577        "wrong active MDI child %p\n", active_child);
3578     flush_sequence();
3579
3580     ShowWindow(mdi_child, SW_MAXIMIZE);
3581     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3582     flush_sequence();
3583
3584     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3585     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3586
3587     trace("re-creating maximized visible MDI child window 2\n");
3588     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3589                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3590                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3591                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3592     assert(mdi_child2);
3593     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3594     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3595     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3596
3597     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3598     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3599
3600     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3601     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3602     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3603     flush_sequence();
3604
3605     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3606     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3607     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3608
3609     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3610     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3611     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3612
3613     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3614     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3615     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3616     flush_sequence();
3617
3618     DestroyWindow(mdi_child);
3619     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3620
3621     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3622     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3623
3624     /* Win2k: MDI client still returns a just destroyed child as active
3625      * Win9x: MDI client returns 0
3626      */
3627     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3628     ok(active_child == mdi_child || /* win2k */
3629        !active_child, /* win9x */
3630        "wrong active MDI child %p\n", active_child);
3631     flush_sequence();
3632
3633     trace("creating maximized invisible MDI child window\n");
3634     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3635                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3636                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3637                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3638     assert(mdi_child2);
3639     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3640     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3641     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3642     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3643
3644     /* Win2k: MDI client still returns a just destroyed child as active
3645      * Win9x: MDI client returns 0
3646      */
3647     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3648     ok(active_child == mdi_child || /* win2k */
3649        !active_child, /* win9x */
3650        "wrong active MDI child %p\n", active_child);
3651     flush_sequence();
3652
3653     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3654     ShowWindow(mdi_child2, SW_MAXIMIZE);
3655     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3656     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3657     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3658     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3659
3660     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3661     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3662     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3663     flush_sequence();
3664
3665     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3666     flush_sequence();
3667
3668     /* end of test for maximized MDI children */
3669     SetFocus(0);
3670     flush_sequence();
3671     trace("creating maximized visible MDI child window 1(Switch test)\n");
3672     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3673                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3674                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3675                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3676     assert(mdi_child);
3677     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3678     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3679
3680     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3681     ok(GetFocus() == mdi_child || /* win2k */
3682        GetFocus() == 0, /* win9x */
3683        "wrong focus window %p(Switch test)\n", GetFocus());
3684
3685     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3686     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3687     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3688     flush_sequence();
3689
3690     trace("creating maximized visible MDI child window 2(Switch test)\n");
3691     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3692                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3693                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3694                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3695     assert(mdi_child2);
3696     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3697
3698     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3699     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3700
3701     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3702     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3703
3704     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3705     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3706     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3707     flush_sequence();
3708
3709     trace("Switch child window.\n");
3710     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3711     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3712     trace("end of test for switch maximized MDI children\n");
3713     flush_sequence();
3714
3715     /* Prepare for switching test of not maximized MDI children  */
3716     ShowWindow( mdi_child, SW_NORMAL );
3717     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3718     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3719     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3720     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3721     flush_sequence();
3722
3723     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3724     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3725     trace("end of test for switch not maximized MDI children\n");
3726     flush_sequence();
3727
3728     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3729     flush_sequence();
3730
3731     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3732     flush_sequence();
3733
3734     SetFocus(0);
3735     flush_sequence();
3736     /* end of tests for switch maximized/not maximized MDI children */
3737
3738     mdi_cs.szClass = "MDI_child_Class";
3739     mdi_cs.szTitle = "MDI child";
3740     mdi_cs.hOwner = GetModuleHandleA(0);
3741     mdi_cs.x = 0;
3742     mdi_cs.y = 0;
3743     mdi_cs.cx = CW_USEDEFAULT;
3744     mdi_cs.cy = CW_USEDEFAULT;
3745     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3746     mdi_cs.lParam = 0;
3747     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3748     ok(mdi_child != 0, "MDI child creation failed\n");
3749     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3750
3751     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3752
3753     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3754     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3755
3756     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3757     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3758     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3759
3760     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3761     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3762     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3763     flush_sequence();
3764
3765     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3766     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3767
3768     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3769     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3770     ok(!active_child, "wrong active MDI child %p\n", active_child);
3771
3772     SetFocus(0);
3773     flush_sequence();
3774
3775     DestroyWindow(mdi_client);
3776     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3777
3778     /* test maximization of MDI child with invisible parent */
3779     client_cs.hWindowMenu = 0;
3780     mdi_client = CreateWindow("MDI_client_class",
3781                                  NULL,
3782                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3783                                  0, 0, 660, 430,
3784                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3785     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3786
3787     ShowWindow(mdi_client, SW_HIDE);
3788     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3789
3790     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3791                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3792                                 0, 0, 650, 440,
3793                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3794     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3795
3796     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3797     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3798     zoomed = IsZoomed(mdi_child);
3799     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3800     
3801     ShowWindow(mdi_client, SW_SHOW);
3802     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3803
3804     DestroyWindow(mdi_child);
3805     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3806
3807     /* end of test for maximization of MDI child with invisible parent */
3808
3809     DestroyWindow(mdi_client);
3810     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3811
3812     DestroyWindow(mdi_frame);
3813     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3814 }
3815 /************************* End of MDI test **********************************/
3816
3817 static void test_WM_SETREDRAW(HWND hwnd)
3818 {
3819     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3820
3821     flush_events();
3822     flush_sequence();
3823
3824     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3825     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3826
3827     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3828     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3829
3830     flush_sequence();
3831     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3832     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3833
3834     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3835     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3836
3837     /* restore original WS_VISIBLE state */
3838     SetWindowLongA(hwnd, GWL_STYLE, style);
3839
3840     flush_events();
3841     flush_sequence();
3842 }
3843
3844 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3845 {
3846     struct recvd_message msg;
3847
3848     switch (message)
3849     {
3850         /* ignore */
3851         case WM_GETICON:
3852         case WM_GETOBJECT:
3853         case WM_MOUSEMOVE:
3854         case WM_NCMOUSEMOVE:
3855         case WM_NCMOUSELEAVE:
3856         case WM_SETCURSOR:
3857         case WM_DEVICECHANGE:
3858             return 0;
3859         case WM_NCHITTEST:
3860             return HTCLIENT;
3861     }
3862
3863     msg.hwnd = hwnd;
3864     msg.message = message;
3865     msg.flags = sent|wparam|lparam;
3866     msg.wParam = wParam;
3867     msg.lParam = lParam;
3868     msg.descr = "dialog";
3869     add_message(&msg);
3870
3871     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3872     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3873     return 0;
3874 }
3875
3876 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3877 {
3878     DWORD style, exstyle;
3879     INT xmin, xmax;
3880     BOOL ret;
3881
3882     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3883     style = GetWindowLongA(hwnd, GWL_STYLE);
3884     /* do not be confused by WS_DLGFRAME set */
3885     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3886
3887     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3888     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3889
3890     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3891     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3892     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3893         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3894     else
3895         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3896
3897     style = GetWindowLongA(hwnd, GWL_STYLE);
3898     if (set) ok(style & set, "style %08x should be set\n", set);
3899     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3900
3901     /* a subsequent call should do nothing */
3902     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3903     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3904     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3905
3906     xmin = 0xdeadbeef;
3907     xmax = 0xdeadbeef;
3908     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3909     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3910     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3911     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3912     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3913     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3914 }
3915
3916 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3917 {
3918     DWORD style, exstyle;
3919     SCROLLINFO si;
3920     BOOL ret;
3921
3922     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3923     style = GetWindowLongA(hwnd, GWL_STYLE);
3924     /* do not be confused by WS_DLGFRAME set */
3925     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3926
3927     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3928     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3929
3930     si.cbSize = sizeof(si);
3931     si.fMask = SIF_RANGE;
3932     si.nMin = min;
3933     si.nMax = max;
3934     SetScrollInfo(hwnd, ctl, &si, TRUE);
3935     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3936         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3937     else
3938         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3939
3940     style = GetWindowLongA(hwnd, GWL_STYLE);
3941     if (set) ok(style & set, "style %08x should be set\n", set);
3942     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3943
3944     /* a subsequent call should do nothing */
3945     SetScrollInfo(hwnd, ctl, &si, TRUE);
3946     if (style & WS_HSCROLL)
3947         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3948     else if (style & WS_VSCROLL)
3949         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3950     else
3951         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3952
3953     si.fMask = SIF_PAGE;
3954     si.nPage = 5;
3955     SetScrollInfo(hwnd, ctl, &si, FALSE);
3956     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3957
3958     si.fMask = SIF_POS;
3959     si.nPos = max - 1;
3960     SetScrollInfo(hwnd, ctl, &si, FALSE);
3961     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3962
3963     si.fMask = SIF_RANGE;
3964     si.nMin = 0xdeadbeef;
3965     si.nMax = 0xdeadbeef;
3966     ret = GetScrollInfo(hwnd, ctl, &si);
3967     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3968     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3969     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3970     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3971 }
3972
3973 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3974 static void test_scroll_messages(HWND hwnd)
3975 {
3976     SCROLLINFO si;
3977     INT min, max;
3978     BOOL ret;
3979
3980     flush_events();
3981     flush_sequence();
3982
3983     min = 0xdeadbeef;
3984     max = 0xdeadbeef;
3985     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3986     ok( ret, "GetScrollRange error %d\n", GetLastError());
3987     if (sequence->message != WmGetScrollRangeSeq[0].message)
3988         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3989     /* values of min and max are undefined */
3990     flush_sequence();
3991
3992     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3993     ok( ret, "SetScrollRange error %d\n", GetLastError());
3994     if (sequence->message != WmSetScrollRangeSeq[0].message)
3995         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3996     flush_sequence();
3997
3998     min = 0xdeadbeef;
3999     max = 0xdeadbeef;
4000     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4001     ok( ret, "GetScrollRange error %d\n", GetLastError());
4002     if (sequence->message != WmGetScrollRangeSeq[0].message)
4003         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4004     /* values of min and max are undefined */
4005     flush_sequence();
4006
4007     si.cbSize = sizeof(si);
4008     si.fMask = SIF_RANGE;
4009     si.nMin = 20;
4010     si.nMax = 160;
4011     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4012     if (sequence->message != WmSetScrollRangeSeq[0].message)
4013         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4014     flush_sequence();
4015
4016     si.fMask = SIF_PAGE;
4017     si.nPage = 10;
4018     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4019     if (sequence->message != WmSetScrollRangeSeq[0].message)
4020         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4021     flush_sequence();
4022
4023     si.fMask = SIF_POS;
4024     si.nPos = 20;
4025     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4026     if (sequence->message != WmSetScrollRangeSeq[0].message)
4027         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4028     flush_sequence();
4029
4030     si.fMask = SIF_RANGE;
4031     si.nMin = 0xdeadbeef;
4032     si.nMax = 0xdeadbeef;
4033     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4034     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4035     if (sequence->message != WmGetScrollInfoSeq[0].message)
4036         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4037     /* values of min and max are undefined */
4038     flush_sequence();
4039
4040     /* set WS_HSCROLL */
4041     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4042     /* clear WS_HSCROLL */
4043     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4044
4045     /* set WS_HSCROLL */
4046     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4047     /* clear WS_HSCROLL */
4048     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4049
4050     /* set WS_VSCROLL */
4051     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4052     /* clear WS_VSCROLL */
4053     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4054
4055     /* set WS_VSCROLL */
4056     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4057     /* clear WS_VSCROLL */
4058     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4059 }
4060
4061 static void test_showwindow(void)
4062 {
4063     HWND hwnd, hchild;
4064     RECT rc;
4065
4066     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4067                            100, 100, 200, 200, 0, 0, 0, NULL);
4068     ok (hwnd != 0, "Failed to create overlapped window\n");
4069     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4070                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4071     ok (hchild != 0, "Failed to create child\n");
4072     flush_sequence();
4073
4074     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4075     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4076     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4077     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
4078
4079     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4080     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4081     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4082     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4083     /* back to invisible */
4084     ShowWindow(hchild, SW_HIDE);
4085     ShowWindow(hwnd, SW_HIDE);
4086     flush_sequence();
4087     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4088     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4089     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4090     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4091     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4092     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4093     flush_sequence();
4094     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4095     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4096     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4097     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4098     ShowWindow( hwnd, SW_SHOW);
4099     flush_sequence();
4100     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4101     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4102     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4103
4104     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4105     ShowWindow( hchild, SW_HIDE);
4106     flush_sequence();
4107     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4108     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4109     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4110
4111     SetCapture(hchild);
4112     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4113     DestroyWindow(hchild);
4114     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4115
4116     DestroyWindow(hwnd);
4117     flush_sequence();
4118
4119     /* Popup windows */
4120     /* Test 1:
4121      * 1. Create invisible maximized popup window.
4122      * 2. Move and resize it.
4123      * 3. Show it maximized.
4124      */
4125     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4126     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4127                            100, 100, 200, 200, 0, 0, 0, NULL);
4128     ok (hwnd != 0, "Failed to create popup window\n");
4129     ok(IsZoomed(hwnd), "window should be maximized\n");
4130     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4131
4132     GetWindowRect(hwnd, &rc);
4133     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4134         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4135         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4136         rc.left, rc.top, rc.right, rc.bottom);
4137     /* Reset window's size & position */
4138     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4139     ok(IsZoomed(hwnd), "window should be maximized\n");
4140     flush_sequence();
4141
4142     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4143     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4144     ok(IsZoomed(hwnd), "window should be maximized\n");
4145     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4146
4147     GetWindowRect(hwnd, &rc);
4148     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4149         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4150         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4151         rc.left, rc.top, rc.right, rc.bottom);
4152     DestroyWindow(hwnd);
4153     flush_sequence();
4154
4155     /* Test 2:
4156      * 1. Create invisible maximized popup window.
4157      * 2. Show it maximized.
4158      */
4159     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4160     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4161                            100, 100, 200, 200, 0, 0, 0, NULL);
4162     ok (hwnd != 0, "Failed to create popup window\n");
4163     ok(IsZoomed(hwnd), "window should be maximized\n");
4164     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4165
4166     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4167     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4168     ok(IsZoomed(hwnd), "window should be maximized\n");
4169     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4170     DestroyWindow(hwnd);
4171     flush_sequence();
4172
4173     /* Test 3:
4174      * 1. Create visible maximized popup window.
4175      */
4176     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4177     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4178                            100, 100, 200, 200, 0, 0, 0, NULL);
4179     ok (hwnd != 0, "Failed to create popup window\n");
4180     ok(IsZoomed(hwnd), "window should be maximized\n");
4181     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4182     DestroyWindow(hwnd);
4183     flush_sequence();
4184
4185     /* Test 4:
4186      * 1. Create visible popup window.
4187      * 2. Maximize it.
4188      */
4189     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4190     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4191                            100, 100, 200, 200, 0, 0, 0, NULL);
4192     ok (hwnd != 0, "Failed to create popup window\n");
4193     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4194     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4195
4196     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4197     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4198     ok(IsZoomed(hwnd), "window should be maximized\n");
4199     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4200     DestroyWindow(hwnd);
4201     flush_sequence();
4202 }
4203
4204 static void test_sys_menu(void)
4205 {
4206     HWND hwnd;
4207     HMENU hmenu;
4208     UINT state;
4209
4210     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4211                            100, 100, 200, 200, 0, 0, 0, NULL);
4212     ok (hwnd != 0, "Failed to create overlapped window\n");
4213
4214     flush_sequence();
4215
4216     /* test existing window without CS_NOCLOSE style */
4217     hmenu = GetSystemMenu(hwnd, FALSE);
4218     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4219
4220     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4221     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4222     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4223
4224     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4225     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4226
4227     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4228     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4229     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4230
4231     EnableMenuItem(hmenu, SC_CLOSE, 0);
4232     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4233
4234     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4235     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4236     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4237
4238     /* test whether removing WS_SYSMENU destroys a system menu */
4239     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4240     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4241     flush_sequence();
4242     hmenu = GetSystemMenu(hwnd, FALSE);
4243     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4244
4245     DestroyWindow(hwnd);
4246
4247     /* test new window with CS_NOCLOSE style */
4248     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4249                            100, 100, 200, 200, 0, 0, 0, NULL);
4250     ok (hwnd != 0, "Failed to create overlapped window\n");
4251
4252     hmenu = GetSystemMenu(hwnd, FALSE);
4253     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4254
4255     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4256     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4257
4258     DestroyWindow(hwnd);
4259
4260     /* test new window without WS_SYSMENU style */
4261     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4262                            100, 100, 200, 200, 0, 0, 0, NULL);
4263     ok(hwnd != 0, "Failed to create overlapped window\n");
4264
4265     hmenu = GetSystemMenu(hwnd, FALSE);
4266     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4267
4268     DestroyWindow(hwnd);
4269 }
4270
4271 /* For shown WS_OVERLAPPEDWINDOW */
4272 static const struct message WmSetIcon_1[] = {
4273     { WM_SETICON, sent },
4274     { 0x00AE, sent|defwinproc|optional }, /* XP */
4275     { WM_GETTEXT, sent|defwinproc|optional },
4276     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4277     { 0 }
4278 };
4279
4280 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4281 static const struct message WmSetIcon_2[] = {
4282     { WM_SETICON, sent },
4283     { 0 }
4284 };
4285
4286 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4287 static const struct message WmInitEndSession[] = {
4288     { 0x003B, sent },
4289     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4290     { 0 }
4291 };
4292
4293 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4294 static const struct message WmInitEndSession_2[] = {
4295     { 0x003B, sent },
4296     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4297     { 0 }
4298 };
4299
4300 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4301 static const struct message WmInitEndSession_3[] = {
4302     { 0x003B, sent },
4303     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4304     { 0 }
4305 };
4306
4307 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4308 static const struct message WmInitEndSession_4[] = {
4309     { 0x003B, sent },
4310     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4311     { 0 }
4312 };
4313
4314 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4315 static const struct message WmInitEndSession_5[] = {
4316     { 0x003B, sent },
4317     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4318     { 0 }
4319 };
4320
4321 static const struct message WmOptionalPaint[] = {
4322     { WM_PAINT, sent|optional },
4323     { WM_NCPAINT, sent|beginpaint|optional },
4324     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4325     { WM_ERASEBKGND, sent|beginpaint|optional },
4326     { 0 }
4327 };
4328
4329 static const struct message WmZOrder[] = {
4330     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4331     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4332     { HCBT_ACTIVATE, hook },
4333     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4334     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4335     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4336     { WM_GETTEXT, sent|optional },
4337     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4338     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4339     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4340     { WM_GETTEXT, sent|defwinproc|optional },
4341     { WM_GETTEXT, sent|defwinproc|optional },
4342     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4343     { HCBT_SETFOCUS, hook },
4344     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4345     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4346     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4347     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4348     { WM_GETTEXT, sent|optional },
4349     { WM_NCCALCSIZE, sent|optional },
4350     { 0 }
4351 };
4352
4353 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4354 {
4355     DWORD ret;
4356     MSG msg;
4357
4358     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4359     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4360
4361     PostMessageA(hwnd, WM_USER, 0, 0);
4362
4363     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4364     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4365
4366     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4367     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4368
4369     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4370     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4371
4372     PostMessageA(hwnd, WM_USER, 0, 0);
4373
4374     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4375     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4376
4377     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4378     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4379
4380     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4381     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4382     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4383
4384     PostMessageA(hwnd, WM_USER, 0, 0);
4385
4386     /* new incoming message causes it to become signaled again */
4387     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4388     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4389
4390     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4391     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4392     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4393     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4394 }
4395
4396 /* test if we receive the right sequence of messages */
4397 static void test_messages(void)
4398 {
4399     HWND hwnd, hparent, hchild;
4400     HWND hchild2, hbutton;
4401     HMENU hmenu;
4402     MSG msg;
4403     LRESULT res;
4404
4405     flush_sequence();
4406
4407     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4408                            100, 100, 200, 200, 0, 0, 0, NULL);
4409     ok (hwnd != 0, "Failed to create overlapped window\n");
4410     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4411
4412     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4413     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4414     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4415
4416     /* test WM_SETREDRAW on a not visible top level window */
4417     test_WM_SETREDRAW(hwnd);
4418
4419     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4420     flush_events();
4421     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4422     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4423
4424     ok(GetActiveWindow() == hwnd, "window should be active\n");
4425     ok(GetFocus() == hwnd, "window should have input focus\n");
4426     ShowWindow(hwnd, SW_HIDE);
4427     flush_events();
4428     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4429
4430     ShowWindow(hwnd, SW_SHOW);
4431     flush_events();
4432     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4433
4434     ShowWindow(hwnd, SW_HIDE);
4435     flush_events();
4436     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4437
4438     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4439     flush_events();
4440     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4441
4442     ShowWindow(hwnd, SW_RESTORE);
4443     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4444     flush_events();
4445     flush_sequence();
4446
4447     ShowWindow(hwnd, SW_MINIMIZE);
4448     flush_events();
4449     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4450     flush_sequence();
4451
4452     ShowWindow(hwnd, SW_RESTORE);
4453     flush_events();
4454     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4455     flush_sequence();
4456
4457     ShowWindow(hwnd, SW_SHOW);
4458     flush_events();
4459     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4460
4461     ok(GetActiveWindow() == hwnd, "window should be active\n");
4462     ok(GetFocus() == hwnd, "window should have input focus\n");
4463     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4464     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4465     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4466     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4467
4468     /* test WM_SETREDRAW on a visible top level window */
4469     ShowWindow(hwnd, SW_SHOW);
4470     flush_events();
4471     test_WM_SETREDRAW(hwnd);
4472
4473     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4474     test_scroll_messages(hwnd);
4475
4476     /* test resizing and moving */
4477     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4478     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4479     flush_events();
4480     flush_sequence();
4481     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4482     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4483     flush_events();
4484     flush_sequence();
4485     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4486     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4487     flush_events();
4488     flush_sequence();
4489
4490     /* popups don't get WM_GETMINMAXINFO */
4491     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4492     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4493     flush_sequence();
4494     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4495     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4496
4497     DestroyWindow(hwnd);
4498     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4499
4500     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4501                               100, 100, 200, 200, 0, 0, 0, NULL);
4502     ok (hparent != 0, "Failed to create parent window\n");
4503     flush_sequence();
4504
4505     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4506                              0, 0, 10, 10, hparent, 0, 0, NULL);
4507     ok (hchild != 0, "Failed to create child window\n");
4508     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4509     DestroyWindow(hchild);
4510     flush_sequence();
4511
4512     /* visible child window with a caption */
4513     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4514                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4515                              0, 0, 10, 10, hparent, 0, 0, NULL);
4516     ok (hchild != 0, "Failed to create child window\n");
4517     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4518
4519     trace("testing scroll APIs on a visible child window %p\n", hchild);
4520     test_scroll_messages(hchild);
4521
4522     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4523     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4524
4525     DestroyWindow(hchild);
4526     flush_sequence();
4527
4528     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4529                              0, 0, 10, 10, hparent, 0, 0, NULL);
4530     ok (hchild != 0, "Failed to create child window\n");
4531     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4532     
4533     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4534                                100, 100, 50, 50, hparent, 0, 0, NULL);
4535     ok (hchild2 != 0, "Failed to create child2 window\n");
4536     flush_sequence();
4537
4538     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4539                               0, 100, 50, 50, hchild, 0, 0, NULL);
4540     ok (hbutton != 0, "Failed to create button window\n");
4541
4542     /* test WM_SETREDRAW on a not visible child window */
4543     test_WM_SETREDRAW(hchild);
4544
4545     ShowWindow(hchild, SW_SHOW);
4546     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4547
4548     /* check parent messages too */
4549     log_all_parent_messages++;
4550     ShowWindow(hchild, SW_HIDE);
4551     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4552     log_all_parent_messages--;
4553
4554     ShowWindow(hchild, SW_SHOW);
4555     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4556
4557     ShowWindow(hchild, SW_HIDE);
4558     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4559
4560     ShowWindow(hchild, SW_SHOW);
4561     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4562
4563     /* test WM_SETREDRAW on a visible child window */
4564     test_WM_SETREDRAW(hchild);
4565
4566     log_all_parent_messages++;
4567     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4568     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4569     log_all_parent_messages--;
4570
4571     ShowWindow(hchild, SW_HIDE);
4572     flush_sequence();
4573     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4574     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4575
4576     ShowWindow(hchild, SW_HIDE);
4577     flush_sequence();
4578     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4579     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4580
4581     /* DestroyWindow sequence below expects that a child has focus */
4582     SetFocus(hchild);
4583     flush_sequence();
4584
4585     DestroyWindow(hchild);
4586     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4587     DestroyWindow(hchild2);
4588     DestroyWindow(hbutton);
4589
4590     flush_sequence();
4591     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4592                              0, 0, 100, 100, hparent, 0, 0, NULL);
4593     ok (hchild != 0, "Failed to create child popup window\n");
4594     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4595     DestroyWindow(hchild);
4596
4597     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4598     flush_sequence();
4599     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4600                              0, 0, 100, 100, hparent, 0, 0, NULL);
4601     ok (hchild != 0, "Failed to create popup window\n");
4602     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4603     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4604     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4605     flush_sequence();
4606     ShowWindow(hchild, SW_SHOW);
4607     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4608     flush_sequence();
4609     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4610     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4611     flush_sequence();
4612     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4613     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4614     DestroyWindow(hchild);
4615
4616     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4617      * changes nothing in message sequences.
4618      */
4619     flush_sequence();
4620     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4621                              0, 0, 100, 100, hparent, 0, 0, NULL);
4622     ok (hchild != 0, "Failed to create popup window\n");
4623     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4624     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4625     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4626     flush_sequence();
4627     ShowWindow(hchild, SW_SHOW);
4628     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4629     flush_sequence();
4630     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4631     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4632     DestroyWindow(hchild);
4633
4634     flush_sequence();
4635     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4636                            0, 0, 100, 100, hparent, 0, 0, NULL);
4637     ok(hwnd != 0, "Failed to create custom dialog window\n");
4638     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4639
4640     /*
4641     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4642     test_scroll_messages(hwnd);
4643     */
4644
4645     flush_sequence();
4646
4647     test_def_id = 1;
4648     SendMessage(hwnd, WM_NULL, 0, 0);
4649
4650     flush_sequence();
4651     after_end_dialog = 1;
4652     EndDialog( hwnd, 0 );
4653     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4654
4655     DestroyWindow(hwnd);
4656     after_end_dialog = 0;
4657     test_def_id = 0;
4658
4659     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4660                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4661     ok(hwnd != 0, "Failed to create custom dialog window\n");
4662     flush_sequence();
4663     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4664     ShowWindow(hwnd, SW_SHOW);
4665     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4666     DestroyWindow(hwnd);
4667
4668     flush_sequence();
4669     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4670     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4671
4672     DestroyWindow(hparent);
4673     flush_sequence();
4674
4675     /* Message sequence for SetMenu */
4676     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4677     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4678
4679     hmenu = CreateMenu();
4680     ok (hmenu != 0, "Failed to create menu\n");
4681     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4682     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4683                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4684     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4685     ok (SetMenu(hwnd, 0), "SetMenu\n");
4686     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4687     ok (SetMenu(hwnd, 0), "SetMenu\n");
4688     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4689     ShowWindow(hwnd, SW_SHOW);
4690     UpdateWindow( hwnd );
4691     flush_events();
4692     flush_sequence();
4693     ok (SetMenu(hwnd, 0), "SetMenu\n");
4694     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4695     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4696     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4697
4698     UpdateWindow( hwnd );
4699     flush_events();
4700     flush_sequence();
4701     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4702     flush_events();
4703     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4704
4705     DestroyWindow(hwnd);
4706     flush_sequence();
4707
4708     /* Message sequence for EnableWindow */
4709     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4710                               100, 100, 200, 200, 0, 0, 0, NULL);
4711     ok (hparent != 0, "Failed to create parent window\n");
4712     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4713                              0, 0, 10, 10, hparent, 0, 0, NULL);
4714     ok (hchild != 0, "Failed to create child window\n");
4715
4716     SetFocus(hchild);
4717     flush_events();
4718     flush_sequence();
4719
4720     EnableWindow(hparent, FALSE);
4721     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4722
4723     EnableWindow(hparent, TRUE);
4724     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4725
4726     flush_events();
4727     flush_sequence();
4728
4729     test_MsgWaitForMultipleObjects(hparent);
4730
4731     /* the following test causes an exception in user.exe under win9x */
4732     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4733     {
4734         DestroyWindow(hparent);
4735         flush_sequence();
4736         return;
4737     }
4738     PostMessageW( hparent, WM_USER+1, 0, 0 );
4739     /* PeekMessage(NULL) fails, but still removes the message */
4740     SetLastError(0xdeadbeef);
4741     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4742     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4743         GetLastError() == 0xdeadbeef, /* NT4 */
4744         "last error is %d\n", GetLastError() );
4745     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4746     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4747
4748     DestroyWindow(hchild);
4749     DestroyWindow(hparent);
4750     flush_sequence();
4751
4752     /* Message sequences for WM_SETICON */
4753     trace("testing WM_SETICON\n");
4754     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4755                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4756                            NULL, NULL, 0);
4757     ShowWindow(hwnd, SW_SHOW);
4758     UpdateWindow(hwnd);
4759     flush_events();
4760     flush_sequence();
4761     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4762     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4763
4764     ShowWindow(hwnd, SW_HIDE);
4765     flush_events();
4766     flush_sequence();
4767     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4768     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4769     DestroyWindow(hwnd);
4770     flush_sequence();
4771
4772     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4773                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4774                            NULL, NULL, 0);
4775     ShowWindow(hwnd, SW_SHOW);
4776     UpdateWindow(hwnd);
4777     flush_events();
4778     flush_sequence();
4779     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4780     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4781
4782     ShowWindow(hwnd, SW_HIDE);
4783     flush_events();
4784     flush_sequence();
4785     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4786     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4787
4788     flush_sequence();
4789     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4790     if (!res)
4791     {
4792         todo_wine win_skip( "Message 0x3b not supported\n" );
4793         goto done;
4794     }
4795     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4796     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4797     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4798     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4799     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4800     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4801     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4802     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4803
4804     flush_sequence();
4805     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4806     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4807     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4808     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4809     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4810     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4811
4812     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4813     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4814     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4815
4816     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4817     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4818     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4819
4820 done:
4821     DestroyWindow(hwnd);
4822     flush_sequence();
4823 }
4824
4825 static void test_setwindowpos(void)
4826 {
4827     HWND hwnd;
4828     RECT rc;
4829     LRESULT res;
4830     const INT winX = 100;
4831     const INT winY = 100;
4832     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4833
4834     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4835                            0, 0, winX, winY, 0,
4836                            NULL, NULL, 0);
4837
4838     GetWindowRect(hwnd, &rc);
4839     expect(sysX, rc.right);
4840     expect(winY, rc.bottom);
4841
4842     flush_events();
4843     flush_sequence();
4844     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4845     ok_sequence(WmZOrder, "Z-Order", TRUE);
4846     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4847
4848     GetWindowRect(hwnd, &rc);
4849     expect(sysX, rc.right);
4850     expect(winY, rc.bottom);
4851     DestroyWindow(hwnd);
4852 }
4853
4854 static void invisible_parent_tests(void)
4855 {
4856     HWND hparent, hchild;
4857
4858     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4859                               100, 100, 200, 200, 0, 0, 0, NULL);
4860     ok (hparent != 0, "Failed to create parent window\n");
4861     flush_sequence();
4862
4863     /* test showing child with hidden parent */
4864
4865     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4866                              0, 0, 10, 10, hparent, 0, 0, NULL);
4867     ok (hchild != 0, "Failed to create child window\n");
4868     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4869
4870     ShowWindow( hchild, SW_MINIMIZE );
4871     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4872     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4873     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4874
4875     /* repeat */
4876     flush_events();
4877     flush_sequence();
4878     ShowWindow( hchild, SW_MINIMIZE );
4879     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4880
4881     DestroyWindow(hchild);
4882     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4883                              0, 0, 10, 10, hparent, 0, 0, NULL);
4884     flush_sequence();
4885
4886     ShowWindow( hchild, SW_MAXIMIZE );
4887     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4888     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4889     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4890
4891     /* repeat */
4892     flush_events();
4893     flush_sequence();
4894     ShowWindow( hchild, SW_MAXIMIZE );
4895     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4896
4897     DestroyWindow(hchild);
4898     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4899                              0, 0, 10, 10, hparent, 0, 0, NULL);
4900     flush_sequence();
4901
4902     ShowWindow( hchild, SW_RESTORE );
4903     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4904     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4905     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4906
4907     DestroyWindow(hchild);
4908     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4909                              0, 0, 10, 10, hparent, 0, 0, NULL);
4910     flush_sequence();
4911
4912     ShowWindow( hchild, SW_SHOWMINIMIZED );
4913     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4914     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4915     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4916
4917     /* repeat */
4918     flush_events();
4919     flush_sequence();
4920     ShowWindow( hchild, SW_SHOWMINIMIZED );
4921     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4922
4923     DestroyWindow(hchild);
4924     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4925                              0, 0, 10, 10, hparent, 0, 0, NULL);
4926     flush_sequence();
4927
4928     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4929     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4930     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4931     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4932     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4933
4934     DestroyWindow(hchild);
4935     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4936                              0, 0, 10, 10, hparent, 0, 0, NULL);
4937     flush_sequence();
4938
4939     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4940     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4941     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4942     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4943
4944     /* repeat */
4945     flush_events();
4946     flush_sequence();
4947     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4948     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4949
4950     DestroyWindow(hchild);
4951     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4952                              0, 0, 10, 10, hparent, 0, 0, NULL);
4953     flush_sequence();
4954
4955     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4956     ShowWindow( hchild, SW_FORCEMINIMIZE );
4957     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4958 todo_wine {
4959     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4960 }
4961     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4962
4963     DestroyWindow(hchild);
4964     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4965                              0, 0, 10, 10, hparent, 0, 0, NULL);
4966     flush_sequence();
4967
4968     ShowWindow( hchild, SW_SHOWNA );
4969     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4970     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4971     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4972
4973     /* repeat */
4974     flush_events();
4975     flush_sequence();
4976     ShowWindow( hchild, SW_SHOWNA );
4977     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4978
4979     DestroyWindow(hchild);
4980     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4981                              0, 0, 10, 10, hparent, 0, 0, NULL);
4982     flush_sequence();
4983
4984     ShowWindow( hchild, SW_SHOW );
4985     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4986     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4987     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4988
4989     /* repeat */
4990     flush_events();
4991     flush_sequence();
4992     ShowWindow( hchild, SW_SHOW );
4993     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4994
4995     ShowWindow( hchild, SW_HIDE );
4996     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4997     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4998     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4999
5000     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5001     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5002     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5003     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5004
5005     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5006     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5007     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5008     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5009
5010     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5011     flush_sequence();
5012     DestroyWindow(hchild);
5013     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5014
5015     DestroyWindow(hparent);
5016     flush_sequence();
5017 }
5018
5019 /****************** button message test *************************/
5020 static const struct message WmSetFocusButtonSeq[] =
5021 {
5022     { HCBT_SETFOCUS, hook },
5023     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5024     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5025     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5026     { WM_SETFOCUS, sent|wparam, 0 },
5027     { WM_CTLCOLORBTN, sent|defwinproc },
5028     { 0 }
5029 };
5030 static const struct message WmKillFocusButtonSeq[] =
5031 {
5032     { HCBT_SETFOCUS, hook },
5033     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5034     { WM_KILLFOCUS, sent|wparam, 0 },
5035     { WM_CTLCOLORBTN, sent|defwinproc },
5036     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5037     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5038     { 0 }
5039 };
5040 static const struct message WmSetFocusStaticSeq[] =
5041 {
5042     { HCBT_SETFOCUS, hook },
5043     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5044     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5045     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5046     { WM_SETFOCUS, sent|wparam, 0 },
5047     { WM_CTLCOLORSTATIC, sent|defwinproc },
5048     { 0 }
5049 };
5050 static const struct message WmKillFocusStaticSeq[] =
5051 {
5052     { HCBT_SETFOCUS, hook },
5053     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5054     { WM_KILLFOCUS, sent|wparam, 0 },
5055     { WM_CTLCOLORSTATIC, sent|defwinproc },
5056     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5057     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5058     { 0 }
5059 };
5060 static const struct message WmLButtonDownSeq[] =
5061 {
5062     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5063     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5064     { HCBT_SETFOCUS, hook },
5065     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5066     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5067     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5068     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5069     { WM_CTLCOLORBTN, sent|defwinproc },
5070     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5071     { WM_CTLCOLORBTN, sent|defwinproc },
5072     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5073     { 0 }
5074 };
5075 static const struct message WmLButtonUpSeq[] =
5076 {
5077     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5078     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5079     { WM_CTLCOLORBTN, sent|defwinproc },
5080     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5081     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5082     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5083     { 0 }
5084 };
5085 static const struct message WmSetFontButtonSeq[] =
5086 {
5087     { WM_SETFONT, sent },
5088     { WM_PAINT, sent },
5089     { WM_ERASEBKGND, sent|defwinproc|optional },
5090     { WM_CTLCOLORBTN, sent|defwinproc },
5091     { 0 }
5092 };
5093
5094 static WNDPROC old_button_proc;
5095
5096 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5097 {
5098     static long defwndproc_counter = 0;
5099     LRESULT ret;
5100     struct recvd_message msg;
5101
5102     switch (message)
5103     {
5104     case WM_GETICON:
5105     case WM_GETOBJECT:
5106         return 0;  /* ignore them */
5107     case WM_SYNCPAINT:
5108         break;
5109     case BM_SETSTATE:
5110         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5111         /* fall through */
5112     default:
5113         msg.hwnd = hwnd;
5114         msg.message = message;
5115         msg.flags = sent|wparam|lparam;
5116         if (defwndproc_counter) msg.flags |= defwinproc;
5117         msg.wParam = wParam;
5118         msg.lParam = lParam;
5119         msg.descr = "button";
5120         add_message(&msg);
5121     }
5122
5123     defwndproc_counter++;
5124     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5125     defwndproc_counter--;
5126
5127     return ret;
5128 }
5129
5130 static void subclass_button(void)
5131 {
5132     WNDCLASSA cls;
5133
5134     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5135
5136     old_button_proc = cls.lpfnWndProc;
5137
5138     cls.hInstance = GetModuleHandle(0);
5139     cls.lpfnWndProc = button_hook_proc;
5140     cls.lpszClassName = "my_button_class";
5141     UnregisterClass(cls.lpszClassName, cls.hInstance);
5142     if (!RegisterClassA(&cls)) assert(0);
5143 }
5144
5145 static void test_button_messages(void)
5146 {
5147     static const struct
5148     {
5149         DWORD style;
5150         DWORD dlg_code;
5151         const struct message *setfocus;
5152         const struct message *killfocus;
5153     } button[] = {
5154         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5155           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5156         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5157           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5158         { BS_CHECKBOX, DLGC_BUTTON,
5159           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5160         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5161           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5162         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5163           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5164         { BS_3STATE, DLGC_BUTTON,
5165           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5166         { BS_AUTO3STATE, DLGC_BUTTON,
5167           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5168         { BS_GROUPBOX, DLGC_STATIC,
5169           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5170         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5171           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5172         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5173           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5174         { BS_OWNERDRAW, DLGC_BUTTON,
5175           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5176     };
5177     unsigned int i;
5178     HWND hwnd;
5179     DWORD dlg_code;
5180     HFONT zfont;
5181
5182     subclass_button();
5183
5184     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5185     {
5186         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5187                                0, 0, 50, 14, 0, 0, 0, NULL);
5188         ok(hwnd != 0, "Failed to create button window\n");
5189
5190         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5191         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5192
5193         ShowWindow(hwnd, SW_SHOW);
5194         UpdateWindow(hwnd);
5195         SetFocus(0);
5196         flush_sequence();
5197
5198         trace("button style %08x\n", button[i].style);
5199         SetFocus(hwnd);
5200         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5201
5202         SetFocus(0);
5203         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5204
5205         DestroyWindow(hwnd);
5206     }
5207
5208     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5209                            0, 0, 50, 14, 0, 0, 0, NULL);
5210     ok(hwnd != 0, "Failed to create button window\n");
5211
5212     SetForegroundWindow(hwnd);
5213     SetFocus(0);
5214     flush_events();
5215     flush_sequence();
5216
5217     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5218     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5219
5220     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5221     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5222
5223     flush_sequence();
5224     zfont = GetStockObject(SYSTEM_FONT);
5225     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5226     UpdateWindow(hwnd);
5227     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5228
5229     DestroyWindow(hwnd);
5230 }
5231
5232 /****************** static message test *************************/
5233 static const struct message WmSetFontStaticSeq[] =
5234 {
5235     { WM_SETFONT, sent },
5236     { WM_PAINT, sent|defwinproc|optional },
5237     { WM_ERASEBKGND, sent|defwinproc|optional },
5238     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5239     { 0 }
5240 };
5241
5242 static WNDPROC old_static_proc;
5243
5244 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5245 {
5246     static long defwndproc_counter = 0;
5247     LRESULT ret;
5248     struct recvd_message msg;
5249
5250     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5251
5252     msg.hwnd = hwnd;
5253     msg.message = message;
5254     msg.flags = sent|wparam|lparam;
5255     if (defwndproc_counter) msg.flags |= defwinproc;
5256     msg.wParam = wParam;
5257     msg.lParam = lParam;
5258     msg.descr = "static";
5259     add_message(&msg);
5260
5261     defwndproc_counter++;
5262     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5263     defwndproc_counter--;
5264
5265     return ret;
5266 }
5267
5268 static void subclass_static(void)
5269 {
5270     WNDCLASSA cls;
5271
5272     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5273
5274     old_static_proc = cls.lpfnWndProc;
5275
5276     cls.hInstance = GetModuleHandle(0);
5277     cls.lpfnWndProc = static_hook_proc;
5278     cls.lpszClassName = "my_static_class";
5279     UnregisterClass(cls.lpszClassName, cls.hInstance);
5280     if (!RegisterClassA(&cls)) assert(0);
5281 }
5282
5283 static void test_static_messages(void)
5284 {
5285     /* FIXME: make as comprehensive as the button message test */
5286     static const struct
5287     {
5288         DWORD style;
5289         DWORD dlg_code;
5290         const struct message *setfont;
5291     } static_ctrl[] = {
5292         { SS_LEFT, DLGC_STATIC,
5293           WmSetFontStaticSeq }
5294     };
5295     unsigned int i;
5296     HWND hwnd;
5297     DWORD dlg_code;
5298
5299     subclass_static();
5300
5301     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5302     {
5303         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5304                                0, 0, 50, 14, 0, 0, 0, NULL);
5305         ok(hwnd != 0, "Failed to create static window\n");
5306
5307         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5308         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5309
5310         ShowWindow(hwnd, SW_SHOW);
5311         UpdateWindow(hwnd);
5312         SetFocus(0);
5313         flush_sequence();
5314
5315         trace("static style %08x\n", static_ctrl[i].style);
5316         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5317         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5318
5319         DestroyWindow(hwnd);
5320     }
5321 }
5322
5323 /****************** ComboBox message test *************************/
5324 #define ID_COMBOBOX 0x000f
5325
5326 static const struct message WmKeyDownComboSeq[] =
5327 {
5328     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5329     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5330     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5331     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5332     { WM_CTLCOLOREDIT, sent|parent },
5333     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5334     { 0 }
5335 };
5336
5337 static WNDPROC old_combobox_proc;
5338
5339 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5340 {
5341     static long defwndproc_counter = 0;
5342     LRESULT ret;
5343     struct recvd_message msg;
5344
5345     /* do not log painting messages */
5346     if (message != WM_PAINT &&
5347         message != WM_NCPAINT &&
5348         message != WM_SYNCPAINT &&
5349         message != WM_ERASEBKGND &&
5350         message != WM_NCHITTEST &&
5351         message != WM_GETTEXT &&
5352         message != WM_GETICON &&
5353         message != WM_GETOBJECT &&
5354         message != WM_DEVICECHANGE)
5355     {
5356         msg.hwnd = hwnd;
5357         msg.message = message;
5358         msg.flags = sent|wparam|lparam;
5359         if (defwndproc_counter) msg.flags |= defwinproc;
5360         msg.wParam = wParam;
5361         msg.lParam = lParam;
5362         msg.descr = "combo";
5363         add_message(&msg);
5364     }
5365
5366     defwndproc_counter++;
5367     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5368     defwndproc_counter--;
5369
5370     return ret;
5371 }
5372
5373 static void subclass_combobox(void)
5374 {
5375     WNDCLASSA cls;
5376
5377     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5378
5379     old_combobox_proc = cls.lpfnWndProc;
5380
5381     cls.hInstance = GetModuleHandle(0);
5382     cls.lpfnWndProc = combobox_hook_proc;
5383     cls.lpszClassName = "my_combobox_class";
5384     UnregisterClass(cls.lpszClassName, cls.hInstance);
5385     if (!RegisterClassA(&cls)) assert(0);
5386 }
5387
5388 static void test_combobox_messages(void)
5389 {
5390     HWND parent, combo;
5391     LRESULT ret;
5392
5393     subclass_combobox();
5394
5395     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5396                              100, 100, 200, 200, 0, 0, 0, NULL);
5397     ok(parent != 0, "Failed to create parent window\n");
5398     flush_sequence();
5399
5400     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5401                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5402     ok(combo != 0, "Failed to create combobox window\n");
5403
5404     UpdateWindow(combo);
5405
5406     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5407     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5408
5409     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5410     ok(ret == 0, "expected 0, got %ld\n", ret);
5411     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5412     ok(ret == 1, "expected 1, got %ld\n", ret);
5413     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5414     ok(ret == 2, "expected 2, got %ld\n", ret);
5415
5416     SendMessage(combo, CB_SETCURSEL, 0, 0);
5417     SetFocus(combo);
5418     flush_sequence();
5419
5420     log_all_parent_messages++;
5421     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5422     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5423     log_all_parent_messages--;
5424     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5425
5426     DestroyWindow(combo);
5427     DestroyWindow(parent);
5428 }
5429
5430 /****************** WM_IME_KEYDOWN message test *******************/
5431
5432 static const struct message WmImeKeydownMsgSeq_0[] =
5433 {
5434     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5435     { WM_CHAR, wparam, 'A' },
5436     { 0 }
5437 };
5438
5439 static const struct message WmImeKeydownMsgSeq_1[] =
5440 {
5441     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5442     { WM_CHAR,    optional|wparam, VK_RETURN },
5443     { 0 }
5444 };
5445
5446 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5447 {
5448     struct recvd_message msg;
5449
5450     msg.hwnd = hwnd;
5451     msg.message = message;
5452     msg.flags = wparam|lparam;
5453     msg.wParam = wParam;
5454     msg.lParam = lParam;
5455     msg.descr = "wmime_keydown";
5456     add_message(&msg);
5457
5458     return DefWindowProcA(hwnd, message, wParam, lParam);
5459 }
5460
5461 static void register_wmime_keydown_class(void)
5462 {
5463     WNDCLASSA cls;
5464
5465     ZeroMemory(&cls, sizeof(WNDCLASSA));
5466     cls.lpfnWndProc = wmime_keydown_procA;
5467     cls.hInstance = GetModuleHandleA(0);
5468     cls.lpszClassName = "wmime_keydown_class";
5469     if (!RegisterClassA(&cls)) assert(0);
5470 }
5471
5472 static void test_wmime_keydown_message(void)
5473 {
5474     HWND hwnd;
5475     MSG msg;
5476
5477     trace("Message sequences by WM_IME_KEYDOWN\n");
5478
5479     register_wmime_keydown_class();
5480     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5481                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5482                            NULL, NULL, 0);
5483     flush_events();
5484     flush_sequence();
5485
5486     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5487     SendMessage(hwnd, WM_CHAR, 'A', 1);
5488     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5489
5490     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5491     {
5492         TranslateMessage(&msg);
5493         DispatchMessage(&msg);
5494     }
5495     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5496
5497     DestroyWindow(hwnd);
5498 }
5499
5500 /************* painting message test ********************/
5501
5502 void dump_region(HRGN hrgn)
5503 {
5504     DWORD i, size;
5505     RGNDATA *data = NULL;
5506     RECT *rect;
5507
5508     if (!hrgn)
5509     {
5510         printf( "null region\n" );
5511         return;
5512     }
5513     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5514     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5515     GetRegionData( hrgn, size, data );
5516     printf("%d rects:", data->rdh.nCount );
5517     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5518         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5519     printf("\n");
5520     HeapFree( GetProcessHeap(), 0, data );
5521 }
5522
5523 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5524 {
5525     INT ret;
5526     RECT r1, r2;
5527     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5528     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5529
5530     ret = GetUpdateRgn( hwnd, update, FALSE );
5531     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5532     if (ret == NULLREGION)
5533     {
5534         ok( !hrgn, "Update region shouldn't be empty\n" );
5535     }
5536     else
5537     {
5538         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5539         {
5540             ok( 0, "Regions are different\n" );
5541             if (winetest_debug > 0)
5542             {
5543                 printf( "Update region: " );
5544                 dump_region( update );
5545                 printf( "Wanted region: " );
5546                 dump_region( hrgn );
5547             }
5548         }
5549     }
5550     GetRgnBox( update, &r1 );
5551     GetUpdateRect( hwnd, &r2, FALSE );
5552     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5553         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5554         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5555
5556     DeleteObject( tmp );
5557     DeleteObject( update );
5558 }
5559
5560 static const struct message WmInvalidateRgn[] = {
5561     { WM_NCPAINT, sent },
5562     { WM_GETTEXT, sent|defwinproc|optional },
5563     { 0 }
5564 };
5565
5566 static const struct message WmGetUpdateRect[] = {
5567     { WM_NCPAINT, sent },
5568     { WM_GETTEXT, sent|defwinproc|optional },
5569     { WM_PAINT, sent },
5570     { 0 }
5571 };
5572
5573 static const struct message WmInvalidateFull[] = {
5574     { WM_NCPAINT, sent|wparam, 1 },
5575     { WM_GETTEXT, sent|defwinproc|optional },
5576     { 0 }
5577 };
5578
5579 static const struct message WmInvalidateErase[] = {
5580     { WM_NCPAINT, sent|wparam, 1 },
5581     { WM_GETTEXT, sent|defwinproc|optional },
5582     { WM_ERASEBKGND, sent },
5583     { 0 }
5584 };
5585
5586 static const struct message WmInvalidatePaint[] = {
5587     { WM_PAINT, sent },
5588     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5589     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5590     { 0 }
5591 };
5592
5593 static const struct message WmInvalidateErasePaint[] = {
5594     { WM_PAINT, sent },
5595     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5596     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5597     { WM_ERASEBKGND, sent|beginpaint },
5598     { 0 }
5599 };
5600
5601 static const struct message WmInvalidateErasePaint2[] = {
5602     { WM_PAINT, sent },
5603     { WM_NCPAINT, sent|beginpaint },
5604     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5605     { WM_ERASEBKGND, sent|beginpaint|optional },
5606     { 0 }
5607 };
5608
5609 static const struct message WmErase[] = {
5610     { WM_ERASEBKGND, sent },
5611     { 0 }
5612 };
5613
5614 static const struct message WmPaint[] = {
5615     { WM_PAINT, sent },
5616     { 0 }
5617 };
5618
5619 static const struct message WmParentOnlyPaint[] = {
5620     { WM_PAINT, sent|parent },
5621     { 0 }
5622 };
5623
5624 static const struct message WmInvalidateParent[] = {
5625     { WM_NCPAINT, sent|parent },
5626     { WM_GETTEXT, sent|defwinproc|parent|optional },
5627     { WM_ERASEBKGND, sent|parent },
5628     { 0 }
5629 };
5630
5631 static const struct message WmInvalidateParentChild[] = {
5632     { WM_NCPAINT, sent|parent },
5633     { WM_GETTEXT, sent|defwinproc|parent|optional },
5634     { WM_ERASEBKGND, sent|parent },
5635     { WM_NCPAINT, sent },
5636     { WM_GETTEXT, sent|defwinproc|optional },
5637     { WM_ERASEBKGND, sent },
5638     { 0 }
5639 };
5640
5641 static const struct message WmInvalidateParentChild2[] = {
5642     { WM_ERASEBKGND, sent|parent },
5643     { WM_NCPAINT, sent },
5644     { WM_GETTEXT, sent|defwinproc|optional },
5645     { WM_ERASEBKGND, sent },
5646     { 0 }
5647 };
5648
5649 static const struct message WmParentPaint[] = {
5650     { WM_PAINT, sent|parent },
5651     { WM_PAINT, sent },
5652     { 0 }
5653 };
5654
5655 static const struct message WmParentPaintNc[] = {
5656     { WM_PAINT, sent|parent },
5657     { WM_PAINT, sent },
5658     { WM_NCPAINT, sent|beginpaint },
5659     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5660     { WM_ERASEBKGND, sent|beginpaint|optional },
5661     { 0 }
5662 };
5663
5664 static const struct message WmChildPaintNc[] = {
5665     { WM_PAINT, sent },
5666     { WM_NCPAINT, sent|beginpaint },
5667     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5668     { WM_ERASEBKGND, sent|beginpaint },
5669     { 0 }
5670 };
5671
5672 static const struct message WmParentErasePaint[] = {
5673     { WM_PAINT, sent|parent },
5674     { WM_NCPAINT, sent|parent|beginpaint },
5675     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5676     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5677     { WM_PAINT, sent },
5678     { WM_NCPAINT, sent|beginpaint },
5679     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5680     { WM_ERASEBKGND, sent|beginpaint|optional },
5681     { 0 }
5682 };
5683
5684 static const struct message WmParentOnlyNcPaint[] = {
5685     { WM_PAINT, sent|parent },
5686     { WM_NCPAINT, sent|parent|beginpaint },
5687     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5688     { 0 }
5689 };
5690
5691 static const struct message WmSetParentStyle[] = {
5692     { WM_STYLECHANGING, sent|parent },
5693     { WM_STYLECHANGED, sent|parent },
5694     { 0 }
5695 };
5696
5697 static void test_paint_messages(void)
5698 {
5699     BOOL ret;
5700     RECT rect;
5701     POINT pt;
5702     MSG msg;
5703     HWND hparent, hchild;
5704     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5705     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5706     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5707                                 100, 100, 200, 200, 0, 0, 0, NULL);
5708     ok (hwnd != 0, "Failed to create overlapped window\n");
5709
5710     ShowWindow( hwnd, SW_SHOW );
5711     UpdateWindow( hwnd );
5712     flush_events();
5713     flush_sequence();
5714
5715     check_update_rgn( hwnd, 0 );
5716     SetRectRgn( hrgn, 10, 10, 20, 20 );
5717     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5718     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5719     check_update_rgn( hwnd, hrgn );
5720     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5721     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5722     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5723     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5724     check_update_rgn( hwnd, hrgn );
5725     /* validate everything */
5726     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5727     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5728     check_update_rgn( hwnd, 0 );
5729
5730     /* test empty region */
5731     SetRectRgn( hrgn, 10, 10, 10, 15 );
5732     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5733     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5734     check_update_rgn( hwnd, 0 );
5735     /* test empty rect */
5736     SetRect( &rect, 10, 10, 10, 15 );
5737     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5738     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5739     check_update_rgn( hwnd, 0 );
5740
5741     /* flush pending messages */
5742     flush_events();
5743     flush_sequence();
5744
5745     GetClientRect( hwnd, &rect );
5746     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5747     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5748      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5749      */
5750     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5751     SetRectEmpty( &rect );
5752     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5753     check_update_rgn( hwnd, hrgn );
5754     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5755     flush_events();
5756     ok_sequence( WmPaint, "Paint", FALSE );
5757     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5758     check_update_rgn( hwnd, 0 );
5759
5760     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5761      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5762      */
5763     trace("testing ValidateRect(0, NULL)\n");
5764     SetRectEmpty( &rect );
5765     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5766     {
5767         check_update_rgn( hwnd, hrgn );
5768         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5769         flush_events();
5770         ok_sequence( WmPaint, "Paint", FALSE );
5771         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5772         check_update_rgn( hwnd, 0 );
5773     }
5774
5775     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5776     SetLastError(0xdeadbeef);
5777     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5778     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5779        "wrong error code %d\n", GetLastError());
5780     check_update_rgn( hwnd, 0 );
5781     flush_events();
5782     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5783
5784     trace("testing ValidateRgn(0, NULL)\n");
5785     SetLastError(0xdeadbeef);
5786     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5787     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5788        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5789        "wrong error code %d\n", GetLastError());
5790     check_update_rgn( hwnd, 0 );
5791     flush_events();
5792     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5793
5794     /* now with frame */
5795     SetRectRgn( hrgn, -5, -5, 20, 20 );
5796
5797     /* flush pending messages */
5798     flush_events();
5799     flush_sequence();
5800     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5801     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5802
5803     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5804     check_update_rgn( hwnd, hrgn );
5805
5806     flush_sequence();
5807     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5808     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5809
5810     flush_sequence();
5811     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5812     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5813
5814     GetClientRect( hwnd, &rect );
5815     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5816     check_update_rgn( hwnd, hrgn );
5817
5818     flush_sequence();
5819     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5820     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5821
5822     flush_sequence();
5823     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5824     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5825     check_update_rgn( hwnd, 0 );
5826
5827     flush_sequence();
5828     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5829     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5830     check_update_rgn( hwnd, 0 );
5831
5832     flush_sequence();
5833     SetRectRgn( hrgn, 0, 0, 100, 100 );
5834     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5835     SetRectRgn( hrgn, 0, 0, 50, 100 );
5836     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5837     SetRectRgn( hrgn, 50, 0, 100, 100 );
5838     check_update_rgn( hwnd, hrgn );
5839     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5840     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5841     check_update_rgn( hwnd, 0 );
5842
5843     flush_sequence();
5844     SetRectRgn( hrgn, 0, 0, 100, 100 );
5845     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5846     SetRectRgn( hrgn, 0, 0, 100, 50 );
5847     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5848     ok_sequence( WmErase, "Erase", FALSE );
5849     SetRectRgn( hrgn, 0, 50, 100, 100 );
5850     check_update_rgn( hwnd, hrgn );
5851
5852     flush_sequence();
5853     SetRectRgn( hrgn, 0, 0, 100, 100 );
5854     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5855     SetRectRgn( hrgn, 0, 0, 50, 50 );
5856     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5857     ok_sequence( WmPaint, "Paint", FALSE );
5858
5859     flush_sequence();
5860     SetRectRgn( hrgn, -4, -4, -2, -2 );
5861     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5862     SetRectRgn( hrgn, -200, -200, -198, -198 );
5863     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5864     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5865
5866     flush_sequence();
5867     SetRectRgn( hrgn, -4, -4, -2, -2 );
5868     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5869     SetRectRgn( hrgn, -4, -4, -3, -3 );
5870     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5871     SetRectRgn( hrgn, 0, 0, 1, 1 );
5872     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5873     ok_sequence( WmPaint, "Paint", FALSE );
5874
5875     flush_sequence();
5876     SetRectRgn( hrgn, -4, -4, -1, -1 );
5877     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5878     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5879     /* make sure no WM_PAINT was generated */
5880     flush_events();
5881     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5882
5883     flush_sequence();
5884     SetRectRgn( hrgn, -4, -4, -1, -1 );
5885     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5886     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5887     {
5888         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5889         {
5890             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5891             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5892             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5893             ret = GetUpdateRect( hwnd, &rect, FALSE );
5894             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5895             /* this will send WM_NCPAINT and validate the non client area */
5896             ret = GetUpdateRect( hwnd, &rect, TRUE );
5897             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5898         }
5899         DispatchMessage( &msg );
5900     }
5901     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5902
5903     DestroyWindow( hwnd );
5904
5905     /* now test with a child window */
5906
5907     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5908                               100, 100, 200, 200, 0, 0, 0, NULL);
5909     ok (hparent != 0, "Failed to create parent window\n");
5910
5911     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5912                            10, 10, 100, 100, hparent, 0, 0, NULL);
5913     ok (hchild != 0, "Failed to create child window\n");
5914
5915     ShowWindow( hparent, SW_SHOW );
5916     UpdateWindow( hparent );
5917     UpdateWindow( hchild );
5918     flush_events();
5919     flush_sequence();
5920     log_all_parent_messages++;
5921
5922     SetRect( &rect, 0, 0, 50, 50 );
5923     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5924     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5925     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5926
5927     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5928     pt.x = pt.y = 0;
5929     MapWindowPoints( hchild, hparent, &pt, 1 );
5930     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5931     check_update_rgn( hchild, hrgn );
5932     SetRectRgn( hrgn, 0, 0, 50, 50 );
5933     check_update_rgn( hparent, hrgn );
5934     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5935     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5936     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5937     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5938
5939     flush_events();
5940     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5941
5942     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5943     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5944     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5945     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5946     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5947
5948     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5949     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5950     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5951
5952     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5953     flush_sequence();
5954     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5955     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5956     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5957
5958     /* flush all paint messages */
5959     flush_events();
5960     flush_sequence();
5961
5962     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5963     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5964     SetRectRgn( hrgn, 0, 0, 50, 50 );
5965     check_update_rgn( hparent, hrgn );
5966     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5967     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5968     SetRectRgn( hrgn, 0, 0, 50, 50 );
5969     check_update_rgn( hparent, hrgn );
5970
5971     /* flush all paint messages */
5972     flush_events();
5973     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5974     flush_sequence();
5975
5976     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5977     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5978     SetRectRgn( hrgn, 0, 0, 50, 50 );
5979     check_update_rgn( hparent, hrgn );
5980     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5981     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5982     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5983     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5984     check_update_rgn( hparent, hrgn );
5985     /* flush all paint messages */
5986     flush_events();
5987     flush_sequence();
5988
5989     /* same as above but parent gets completely validated */
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     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5995     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5996     check_update_rgn( hparent, 0 );  /* no update region */
5997     flush_events();
5998     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5999
6000     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6001     flush_sequence();
6002     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6003     SetRectRgn( hrgn, 20, 20, 30, 30 );
6004     check_update_rgn( hparent, hrgn );
6005     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6006     SetRectRgn( hrgn, 20, 20, 30, 30 );
6007     check_update_rgn( hparent, hrgn );
6008
6009     /* same as above but normal WM_PAINT doesn't validate parent */
6010     flush_sequence();
6011     SetRect( &rect, 20, 20, 30, 30 );
6012     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6013     SetRectRgn( hrgn, 20, 20, 30, 30 );
6014     check_update_rgn( hparent, hrgn );
6015     /* no WM_PAINT in child while parent still pending */
6016     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6017     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6018     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6019     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6020
6021     flush_sequence();
6022     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6023     /* no WM_PAINT in child while parent still pending */
6024     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6025     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6026     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6027     /* now that parent is valid child should get WM_PAINT */
6028     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6029     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6030     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6031     ok_sequence( WmEmptySeq, "No other message", FALSE );
6032
6033     /* same thing with WS_CLIPCHILDREN in parent */
6034     flush_sequence();
6035     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6036     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6037     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6038     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6039     ok_sequence( WmEmptySeq, "No message", FALSE );
6040     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6041     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6042
6043     flush_sequence();
6044     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6045     SetRectRgn( hrgn, 20, 20, 30, 30 );
6046     check_update_rgn( hparent, hrgn );
6047     /* no WM_PAINT in child while parent still pending */
6048     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6049     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6050     /* WM_PAINT in parent first */
6051     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6052     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6053
6054     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6055     flush_sequence();
6056     SetRect( &rect, 0, 0, 30, 30 );
6057     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6058     SetRectRgn( hrgn, 0, 0, 30, 30 );
6059     check_update_rgn( hparent, hrgn );
6060     flush_events();
6061     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6062
6063     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6064     flush_sequence();
6065     SetRect( &rect, -10, 0, 30, 30 );
6066     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6067     SetRect( &rect, 0, 0, 20, 20 );
6068     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6069     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6070     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6071
6072     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6073     flush_sequence();
6074     SetRect( &rect, -10, 0, 30, 30 );
6075     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6076     SetRect( &rect, 0, 0, 100, 100 );
6077     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6078     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6079     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6080     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6081     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6082
6083     /* test RDW_INTERNALPAINT behavior */
6084
6085     flush_sequence();
6086     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6087     flush_events();
6088     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6089
6090     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6091     flush_events();
6092     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6093
6094     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6095     flush_events();
6096     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6097
6098     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6099     UpdateWindow( hparent );
6100     flush_events();
6101     flush_sequence();
6102     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6103     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6104     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6105                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6106     flush_events();
6107     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6108
6109     UpdateWindow( hparent );
6110     flush_events();
6111     flush_sequence();
6112     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6113     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6114     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6115                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6116     flush_events();
6117     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6118
6119     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6120     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6121     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6122     flush_events();
6123     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6124
6125     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6126     UpdateWindow( hparent );
6127     flush_events();
6128     flush_sequence();
6129     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6130     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6131     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6132                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6133     flush_events();
6134     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6135
6136     UpdateWindow( hparent );
6137     flush_events();
6138     flush_sequence();
6139     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6140     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6141     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6142                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6143     flush_events();
6144     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6145
6146     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6147     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6148
6149     UpdateWindow( hparent );
6150     flush_events();
6151     flush_sequence();
6152     trace("testing SetWindowPos(-10000, -10000) on child\n");
6153     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6154     check_update_rgn( hchild, 0 );
6155     flush_events();
6156
6157 #if 0 /* this one doesn't pass under Wine yet */
6158     UpdateWindow( hparent );
6159     flush_events();
6160     flush_sequence();
6161     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6162     ShowWindow( hchild, SW_MINIMIZE );
6163     check_update_rgn( hchild, 0 );
6164     flush_events();
6165 #endif
6166
6167     UpdateWindow( hparent );
6168     flush_events();
6169     flush_sequence();
6170     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6171     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6172     check_update_rgn( hparent, 0 );
6173     flush_events();
6174
6175     log_all_parent_messages--;
6176     DestroyWindow( hparent );
6177     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6178
6179     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6180
6181     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6182                               100, 100, 200, 200, 0, 0, 0, NULL);
6183     ok (hparent != 0, "Failed to create parent window\n");
6184
6185     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6186                            10, 10, 100, 100, hparent, 0, 0, NULL);
6187     ok (hchild != 0, "Failed to create child window\n");
6188
6189     ShowWindow( hparent, SW_SHOW );
6190     UpdateWindow( hparent );
6191     UpdateWindow( hchild );
6192     flush_events();
6193     flush_sequence();
6194
6195     /* moving child outside of parent boundaries changes update region */
6196     SetRect( &rect, 0, 0, 40, 40 );
6197     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6198     SetRectRgn( hrgn, 0, 0, 40, 40 );
6199     check_update_rgn( hchild, hrgn );
6200     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6201     SetRectRgn( hrgn, 10, 0, 40, 40 );
6202     check_update_rgn( hchild, hrgn );
6203     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6204     SetRectRgn( hrgn, 10, 10, 40, 40 );
6205     check_update_rgn( hchild, hrgn );
6206
6207     /* moving parent off-screen does too */
6208     SetRect( &rect, 0, 0, 100, 100 );
6209     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6210     SetRectRgn( hrgn, 0, 0, 100, 100 );
6211     check_update_rgn( hparent, hrgn );
6212     SetRectRgn( hrgn, 10, 10, 40, 40 );
6213     check_update_rgn( hchild, hrgn );
6214     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6215     SetRectRgn( hrgn, 20, 20, 100, 100 );
6216     check_update_rgn( hparent, hrgn );
6217     SetRectRgn( hrgn, 30, 30, 40, 40 );
6218     check_update_rgn( hchild, hrgn );
6219
6220     /* invalidated region is cropped by the parent rects */
6221     SetRect( &rect, 0, 0, 50, 50 );
6222     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6223     SetRectRgn( hrgn, 30, 30, 50, 50 );
6224     check_update_rgn( hchild, hrgn );
6225
6226     DestroyWindow( hparent );
6227     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6228     flush_sequence();
6229
6230     DeleteObject( hrgn );
6231     DeleteObject( hrgn2 );
6232 }
6233
6234 struct wnd_event
6235 {
6236     HWND hwnd;
6237     HANDLE event;
6238 };
6239
6240 static DWORD WINAPI thread_proc(void *param)
6241 {
6242     MSG msg;
6243     struct wnd_event *wnd_event = param;
6244
6245     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6246                                       100, 100, 200, 200, 0, 0, 0, NULL);
6247     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6248
6249     SetEvent(wnd_event->event);
6250
6251     while (GetMessage(&msg, 0, 0, 0))
6252     {
6253         TranslateMessage(&msg);
6254         DispatchMessage(&msg);
6255     }
6256
6257     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6258
6259     return 0;
6260 }
6261
6262 static void test_interthread_messages(void)
6263 {
6264     HANDLE hThread;
6265     DWORD tid;
6266     WNDPROC proc;
6267     MSG msg;
6268     char buf[256];
6269     int len, expected_len;
6270     struct wnd_event wnd_event;
6271     BOOL ret;
6272
6273     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6274     if (!wnd_event.event)
6275     {
6276         trace("skipping interthread message test under win9x\n");
6277         return;
6278     }
6279
6280     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6281     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6282
6283     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6284
6285     CloseHandle(wnd_event.event);
6286
6287     SetLastError(0xdeadbeef);
6288     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6289     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6290        "wrong error code %d\n", GetLastError());
6291
6292     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6293     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6294
6295     expected_len = lstrlenA("window caption text");
6296     memset(buf, 0, sizeof(buf));
6297     SetLastError(0xdeadbeef);
6298     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6299     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6300     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6301
6302     msg.hwnd = wnd_event.hwnd;
6303     msg.message = WM_GETTEXT;
6304     msg.wParam = sizeof(buf);
6305     msg.lParam = (LPARAM)buf;
6306     memset(buf, 0, sizeof(buf));
6307     SetLastError(0xdeadbeef);
6308     len = DispatchMessageA(&msg);
6309     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6310        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6311
6312     /* the following test causes an exception in user.exe under win9x */
6313     msg.hwnd = wnd_event.hwnd;
6314     msg.message = WM_TIMER;
6315     msg.wParam = 0;
6316     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6317     SetLastError(0xdeadbeef);
6318     len = DispatchMessageA(&msg);
6319     ok(!len && GetLastError() == 0xdeadbeef,
6320        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6321
6322     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6323     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6324
6325     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6326     CloseHandle(hThread);
6327
6328     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6329 }
6330
6331
6332 static const struct message WmVkN[] = {
6333     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6334     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6335     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6336     { WM_CHAR, wparam|lparam, 'n', 1 },
6337     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6338     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6339     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6340     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6341     { 0 }
6342 };
6343 static const struct message WmShiftVkN[] = {
6344     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6345     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6346     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6347     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6348     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6349     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6350     { WM_CHAR, wparam|lparam, 'N', 1 },
6351     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6352     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6353     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6354     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6355     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6356     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6357     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6358     { 0 }
6359 };
6360 static const struct message WmCtrlVkN[] = {
6361     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6362     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6363     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6364     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6365     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6366     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6367     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6368     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6369     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6370     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6371     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6372     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6373     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6374     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6375     { 0 }
6376 };
6377 static const struct message WmCtrlVkN_2[] = {
6378     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6379     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6380     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6381     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6382     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6383     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6384     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6385     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6386     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6387     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6388     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6389     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6390     { 0 }
6391 };
6392 static const struct message WmAltVkN[] = {
6393     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6394     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6395     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6396     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6397     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6398     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6399     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6400     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6401     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6402     { HCBT_SYSCOMMAND, hook },
6403     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6404     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6405     { 0x00AE, sent|defwinproc|optional }, /* XP */
6406     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6407     { WM_INITMENU, sent|defwinproc },
6408     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6409     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6410     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6411     { WM_CAPTURECHANGED, sent|defwinproc },
6412     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6413     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6414     { WM_EXITMENULOOP, sent|defwinproc },
6415     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6416     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6417     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6418     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6419     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6420     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6421     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6422     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6423     { 0 }
6424 };
6425 static const struct message WmAltVkN_2[] = {
6426     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6427     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6428     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6429     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6430     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6431     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6432     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6433     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6434     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6435     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6436     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6437     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6438     { 0 }
6439 };
6440 static const struct message WmCtrlAltVkN[] = {
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_MENU, 0x20000001 }, /* XP */
6445     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6446     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6447     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6448     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6449     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6450     { WM_CHAR, optional },
6451     { WM_CHAR, sent|optional },
6452     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6453     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6454     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6455     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6456     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6457     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6458     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6459     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6460     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6461     { 0 }
6462 };
6463 static const struct message WmCtrlShiftVkN[] = {
6464     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6465     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6466     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6467     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6468     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6469     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6470     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6471     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6472     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6473     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6474     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6475     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6476     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6477     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6478     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6479     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6480     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6481     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6482     { 0 }
6483 };
6484 static const struct message WmCtrlAltShiftVkN[] = {
6485     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6486     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6487     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6488     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6489     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6490     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6491     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6492     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6493     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6494     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6495     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6496     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6497     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6498     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6499     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6500     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6501     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6502     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6503     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6504     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6505     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6506     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6507     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6508     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6509     { 0 }
6510 };
6511 static const struct message WmAltPressRelease[] = {
6512     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6513     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6514     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6515     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6516     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6517     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6518     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6519     { HCBT_SYSCOMMAND, hook },
6520     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6521     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6522     { WM_INITMENU, sent|defwinproc },
6523     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6524     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6525     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6526
6527     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6528
6529     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6530     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6531     { WM_CAPTURECHANGED, sent|defwinproc },
6532     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6533     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6534     { WM_EXITMENULOOP, sent|defwinproc },
6535     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6536     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6537     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6538     { 0 }
6539 };
6540 static const struct message WmAltMouseButton[] = {
6541     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6542     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6543     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6544     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6545     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6546     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6547     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6548     { WM_LBUTTONUP, wparam, 0, 0 },
6549     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6550     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6551     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6552     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6553     { 0 }
6554 };
6555 static const struct message WmF1Seq[] = {
6556     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6557     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6558     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6559     { WM_KEYF1, wparam|lparam, 0, 0 },
6560     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6561     { WM_HELP, sent|defwinproc },
6562     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6563     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6564     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6565     { 0 }
6566 };
6567 static const struct message WmVkAppsSeq[] = {
6568     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6569     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6570     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6571     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6572     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6573     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6574     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6575     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6576     { 0 }
6577 };
6578
6579 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6580 {
6581     MSG msg;
6582
6583     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6584     {
6585         struct recvd_message log_msg;
6586
6587         /* ignore some unwanted messages */
6588         if (msg.message == WM_MOUSEMOVE ||
6589             msg.message == WM_GETICON ||
6590             msg.message == WM_GETOBJECT ||
6591             msg.message == WM_TIMER ||
6592             msg.message == WM_DEVICECHANGE)
6593             continue;
6594
6595         log_msg.hwnd = msg.hwnd;
6596         log_msg.message = msg.message;
6597         log_msg.flags = wparam|lparam;
6598         log_msg.wParam = msg.wParam;
6599         log_msg.lParam = msg.lParam;
6600         log_msg.descr = "accel";
6601         add_message(&log_msg);
6602
6603         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6604         {
6605             TranslateMessage(&msg);
6606             DispatchMessage(&msg);
6607         }
6608     }
6609 }
6610
6611 static void test_accelerators(void)
6612 {
6613     RECT rc;
6614     SHORT state;
6615     HACCEL hAccel;
6616     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6617                                 100, 100, 200, 200, 0, 0, 0, NULL);
6618     BOOL ret;
6619
6620     assert(hwnd != 0);
6621     UpdateWindow(hwnd);
6622     flush_events();
6623     flush_sequence();
6624
6625     SetFocus(hwnd);
6626     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6627
6628     state = GetKeyState(VK_SHIFT);
6629     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6630     state = GetKeyState(VK_CAPITAL);
6631     ok(state == 0, "wrong CapsLock state %04x\n", state);
6632
6633     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6634     assert(hAccel != 0);
6635
6636     flush_events();
6637     pump_msg_loop(hwnd, 0);
6638     flush_sequence();
6639
6640     trace("testing VK_N press/release\n");
6641     flush_sequence();
6642     keybd_event('N', 0, 0, 0);
6643     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6644     pump_msg_loop(hwnd, hAccel);
6645     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6646
6647     trace("testing Shift+VK_N press/release\n");
6648     flush_sequence();
6649     keybd_event(VK_SHIFT, 0, 0, 0);
6650     keybd_event('N', 0, 0, 0);
6651     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6652     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6653     pump_msg_loop(hwnd, hAccel);
6654     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6655
6656     trace("testing Ctrl+VK_N press/release\n");
6657     flush_sequence();
6658     keybd_event(VK_CONTROL, 0, 0, 0);
6659     keybd_event('N', 0, 0, 0);
6660     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6661     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6662     pump_msg_loop(hwnd, hAccel);
6663     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6664
6665     trace("testing Alt+VK_N press/release\n");
6666     flush_sequence();
6667     keybd_event(VK_MENU, 0, 0, 0);
6668     keybd_event('N', 0, 0, 0);
6669     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6670     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6671     pump_msg_loop(hwnd, hAccel);
6672     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6673
6674     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6675     flush_sequence();
6676     keybd_event(VK_CONTROL, 0, 0, 0);
6677     keybd_event(VK_MENU, 0, 0, 0);
6678     keybd_event('N', 0, 0, 0);
6679     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6680     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6681     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6682     pump_msg_loop(hwnd, hAccel);
6683     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6684
6685     ret = DestroyAcceleratorTable(hAccel);
6686     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6687
6688     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6689     assert(hAccel != 0);
6690
6691     trace("testing VK_N press/release\n");
6692     flush_sequence();
6693     keybd_event('N', 0, 0, 0);
6694     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6695     pump_msg_loop(hwnd, hAccel);
6696     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6697
6698     trace("testing Shift+VK_N press/release\n");
6699     flush_sequence();
6700     keybd_event(VK_SHIFT, 0, 0, 0);
6701     keybd_event('N', 0, 0, 0);
6702     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6703     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6704     pump_msg_loop(hwnd, hAccel);
6705     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6706
6707     trace("testing Ctrl+VK_N press/release 2\n");
6708     flush_sequence();
6709     keybd_event(VK_CONTROL, 0, 0, 0);
6710     keybd_event('N', 0, 0, 0);
6711     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6712     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6713     pump_msg_loop(hwnd, hAccel);
6714     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6715
6716     trace("testing Alt+VK_N press/release 2\n");
6717     flush_sequence();
6718     keybd_event(VK_MENU, 0, 0, 0);
6719     keybd_event('N', 0, 0, 0);
6720     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6721     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6722     pump_msg_loop(hwnd, hAccel);
6723     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6724
6725     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6726     flush_sequence();
6727     keybd_event(VK_CONTROL, 0, 0, 0);
6728     keybd_event(VK_MENU, 0, 0, 0);
6729     keybd_event('N', 0, 0, 0);
6730     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6731     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6732     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6733     pump_msg_loop(hwnd, hAccel);
6734     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6735
6736     trace("testing Ctrl+Shift+VK_N press/release\n");
6737     flush_sequence();
6738     keybd_event(VK_CONTROL, 0, 0, 0);
6739     keybd_event(VK_SHIFT, 0, 0, 0);
6740     keybd_event('N', 0, 0, 0);
6741     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6742     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6743     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6744     pump_msg_loop(hwnd, hAccel);
6745     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6746
6747     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6748     flush_sequence();
6749     keybd_event(VK_CONTROL, 0, 0, 0);
6750     keybd_event(VK_MENU, 0, 0, 0);
6751     keybd_event(VK_SHIFT, 0, 0, 0);
6752     keybd_event('N', 0, 0, 0);
6753     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6754     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6755     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6756     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6757     pump_msg_loop(hwnd, hAccel);
6758     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6759
6760     ret = DestroyAcceleratorTable(hAccel);
6761     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6762
6763     trace("testing Alt press/release\n");
6764     flush_sequence();
6765     keybd_event(VK_MENU, 0, 0, 0);
6766     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6767     keybd_event(VK_MENU, 0, 0, 0);
6768     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6769     pump_msg_loop(hwnd, 0);
6770     /* this test doesn't pass in Wine for managed windows */
6771     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6772
6773     trace("testing Alt+MouseButton press/release\n");
6774     /* first, move mouse pointer inside of the window client area */
6775     GetClientRect(hwnd, &rc);
6776     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6777     rc.left += (rc.right - rc.left)/2;
6778     rc.top += (rc.bottom - rc.top)/2;
6779     SetCursorPos(rc.left, rc.top);
6780
6781     flush_events();
6782     flush_sequence();
6783     keybd_event(VK_MENU, 0, 0, 0);
6784     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6785     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6786     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6787     pump_msg_loop(hwnd, 0);
6788     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6789
6790     trace("testing VK_F1 press/release\n");
6791     keybd_event(VK_F1, 0, 0, 0);
6792     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6793     pump_msg_loop(hwnd, 0);
6794     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6795
6796     trace("testing VK_APPS press/release\n");
6797     keybd_event(VK_APPS, 0, 0, 0);
6798     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6799     pump_msg_loop(hwnd, 0);
6800     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6801
6802     DestroyWindow(hwnd);
6803 }
6804
6805 /************* window procedures ********************/
6806
6807 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6808                              WPARAM wParam, LPARAM lParam)
6809 {
6810     static long defwndproc_counter = 0;
6811     static long beginpaint_counter = 0;
6812     LRESULT ret;
6813     struct recvd_message msg;
6814
6815     /* ignore registered messages */
6816     if (message >= 0xc000) return 0;
6817
6818     switch (message)
6819     {
6820         case WM_ENABLE:
6821         {
6822             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6823             ok((BOOL)wParam == !(style & WS_DISABLED),
6824                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6825             break;
6826         }
6827
6828         case WM_CAPTURECHANGED:
6829             if (test_DestroyWindow_flag)
6830             {
6831                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6832                 if (style & WS_CHILD)
6833                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6834                 else if (style & WS_POPUP)
6835                     lParam = WND_POPUP_ID;
6836                 else
6837                     lParam = WND_PARENT_ID;
6838             }
6839             break;
6840
6841         case WM_NCDESTROY:
6842         {
6843             HWND capture;
6844
6845             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6846             capture = GetCapture();
6847             if (capture)
6848             {
6849                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6850                 trace("current capture %p, releasing...\n", capture);
6851                 ReleaseCapture();
6852             }
6853         }
6854         /* fall through */
6855         case WM_DESTROY:
6856             if (pGetAncestor)
6857                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6858             if (test_DestroyWindow_flag)
6859             {
6860                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6861                 if (style & WS_CHILD)
6862                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6863                 else if (style & WS_POPUP)
6864                     lParam = WND_POPUP_ID;
6865                 else
6866                     lParam = WND_PARENT_ID;
6867             }
6868             break;
6869
6870         /* test_accelerators() depends on this */
6871         case WM_NCHITTEST:
6872             return HTCLIENT;
6873
6874         /* ignore */
6875         case WM_MOUSEMOVE:
6876         case WM_MOUSEACTIVATE:
6877         case WM_NCMOUSEMOVE:
6878         case WM_SETCURSOR:
6879         case WM_GETICON:
6880         case WM_GETOBJECT:
6881         case WM_DEVICECHANGE:
6882         case WM_IME_SELECT:
6883             return 0;
6884     }
6885
6886     msg.hwnd = hwnd;
6887     msg.message = message;
6888     msg.flags = sent|wparam|lparam;
6889     if (defwndproc_counter) msg.flags |= defwinproc;
6890     if (beginpaint_counter) msg.flags |= beginpaint;
6891     msg.wParam = wParam;
6892     msg.lParam = lParam;
6893     msg.descr = "MsgCheckProc";
6894     add_message(&msg);
6895
6896     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6897     {
6898         HWND parent = GetParent(hwnd);
6899         RECT rc;
6900         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6901
6902         GetClientRect(parent, &rc);
6903         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6904         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6905               minmax->ptReserved.x, minmax->ptReserved.y,
6906               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6907               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6908               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6909               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6910
6911         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6912            minmax->ptMaxSize.x, rc.right);
6913         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6914            minmax->ptMaxSize.y, rc.bottom);
6915     }
6916
6917     if (message == WM_PAINT)
6918     {
6919         PAINTSTRUCT ps;
6920         beginpaint_counter++;
6921         BeginPaint( hwnd, &ps );
6922         beginpaint_counter--;
6923         EndPaint( hwnd, &ps );
6924         return 0;
6925     }
6926
6927     defwndproc_counter++;
6928     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6929                   : DefWindowProcA(hwnd, message, wParam, lParam);
6930     defwndproc_counter--;
6931
6932     return ret;
6933 }
6934
6935 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6936 {
6937     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6938 }
6939
6940 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6941 {
6942     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6943 }
6944
6945 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6946 {
6947     static long defwndproc_counter = 0;
6948     LRESULT ret;
6949     struct recvd_message msg;
6950
6951     switch (message)
6952     {
6953     case WM_GETICON:
6954     case WM_GETOBJECT:
6955         return 0;  /* ignore them */
6956     case WM_QUERYENDSESSION:
6957     case WM_ENDSESSION:
6958         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
6959         break;
6960     }
6961
6962     msg.hwnd = hwnd;
6963     msg.message = message;
6964     msg.flags = sent|wparam|lparam;
6965     if (defwndproc_counter) msg.flags |= defwinproc;
6966     msg.wParam = wParam;
6967     msg.lParam = lParam;
6968     msg.descr = "popup";
6969     add_message(&msg);
6970
6971     if (message == WM_CREATE)
6972     {
6973         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6974         SetWindowLongA(hwnd, GWL_STYLE, style);
6975     }
6976
6977     defwndproc_counter++;
6978     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6979     defwndproc_counter--;
6980
6981     return ret;
6982 }
6983
6984 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6985 {
6986     static long defwndproc_counter = 0;
6987     static long beginpaint_counter = 0;
6988     LRESULT ret;
6989     struct recvd_message msg;
6990
6991     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
6992
6993     /* ignore registered messages */
6994     if (message >= 0xc000) return 0;
6995
6996     if (log_all_parent_messages ||
6997         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6998         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6999         message == WM_ENABLE || message == WM_ENTERIDLE ||
7000         message == WM_DRAWITEM ||
7001         message == WM_IME_SETCONTEXT)
7002     {
7003         switch (message)
7004         {
7005             /* ignore */
7006             case WM_NCHITTEST:
7007                 return HTCLIENT;
7008             case WM_SETCURSOR:
7009             case WM_MOUSEMOVE:
7010             case WM_NCMOUSEMOVE:
7011                 return 0;
7012
7013             case WM_ERASEBKGND:
7014             {
7015                 RECT rc;
7016                 INT ret = GetClipBox((HDC)wParam, &rc);
7017
7018                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7019                        ret, rc.left, rc.top, rc.right, rc.bottom);
7020                 break;
7021             }
7022         }
7023
7024         msg.hwnd = hwnd;
7025         msg.message = message;
7026         msg.flags = sent|parent|wparam|lparam;
7027         if (defwndproc_counter) msg.flags |= defwinproc;
7028         if (beginpaint_counter) msg.flags |= beginpaint;
7029         msg.wParam = wParam;
7030         msg.lParam = lParam;
7031         msg.descr = "parent";
7032         add_message(&msg);
7033     }
7034
7035     if (message == WM_PAINT)
7036     {
7037         PAINTSTRUCT ps;
7038         beginpaint_counter++;
7039         BeginPaint( hwnd, &ps );
7040         beginpaint_counter--;
7041         EndPaint( hwnd, &ps );
7042         return 0;
7043     }
7044
7045     defwndproc_counter++;
7046     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7047     defwndproc_counter--;
7048
7049     return ret;
7050 }
7051
7052 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7053 {
7054     static long defwndproc_counter = 0;
7055     LRESULT ret;
7056     struct recvd_message msg;
7057
7058     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7059
7060     if (test_def_id)
7061     {
7062         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7063         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7064         if (after_end_dialog)
7065             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7066         else
7067             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7068     }
7069
7070     msg.hwnd = hwnd;
7071     msg.message = message;
7072     msg.flags = sent|wparam|lparam;
7073     if (defwndproc_counter) msg.flags |= defwinproc;
7074     msg.wParam = wParam;
7075     msg.lParam = lParam;
7076     msg.descr = "dialog";
7077     add_message(&msg);
7078
7079     defwndproc_counter++;
7080     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7081     defwndproc_counter--;
7082
7083     return ret;
7084 }
7085
7086 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7087 {
7088     static long defwndproc_counter = 0;
7089     LRESULT ret;
7090     struct recvd_message msg;
7091
7092     /* log only specific messages we are interested in */
7093     switch (message)
7094     {
7095 #if 0 /* probably log these as well */
7096     case WM_ACTIVATE:
7097     case WM_SETFOCUS:
7098     case WM_KILLFOCUS:
7099 #endif
7100     case WM_SHOWWINDOW:
7101     case WM_SIZE:
7102     case WM_MOVE:
7103     case WM_GETMINMAXINFO:
7104     case WM_WINDOWPOSCHANGING:
7105     case WM_WINDOWPOSCHANGED:
7106         break;
7107
7108     default: /* ignore */
7109         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7110         return DefWindowProcA(hwnd, message, wParam, lParam);
7111     }
7112
7113     msg.hwnd = hwnd;
7114     msg.message = message;
7115     msg.flags = sent|wparam|lparam;
7116     if (defwndproc_counter) msg.flags |= defwinproc;
7117     msg.wParam = wParam;
7118     msg.lParam = lParam;
7119     msg.descr = "show";
7120     add_message(&msg);
7121
7122     defwndproc_counter++;
7123     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7124     defwndproc_counter--;
7125
7126     return ret;
7127 }
7128
7129 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7130 {
7131     switch (msg)
7132     {
7133         case WM_CREATE: return 0;
7134         case WM_PAINT:
7135         {
7136             MSG msg2;
7137             static int i = 0;
7138
7139             if (i < 256)
7140             {
7141                 i++;
7142                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7143                 {
7144                     TranslateMessage(&msg2);
7145                     DispatchMessage(&msg2);
7146                 }
7147                 i--;
7148             }
7149             else ok(broken(1), "infinite loop\n");
7150             if ( i == 0)
7151                 paint_loop_done = 1;
7152             return DefWindowProcA(hWnd,msg,wParam,lParam);
7153         }
7154     }
7155     return DefWindowProcA(hWnd,msg,wParam,lParam);
7156 }
7157
7158 static BOOL RegisterWindowClasses(void)
7159 {
7160     WNDCLASSA cls;
7161     WNDCLASSW clsW;
7162
7163     cls.style = 0;
7164     cls.lpfnWndProc = MsgCheckProcA;
7165     cls.cbClsExtra = 0;
7166     cls.cbWndExtra = 0;
7167     cls.hInstance = GetModuleHandleA(0);
7168     cls.hIcon = 0;
7169     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7170     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7171     cls.lpszMenuName = NULL;
7172     cls.lpszClassName = "TestWindowClass";
7173     if(!RegisterClassA(&cls)) return FALSE;
7174
7175     cls.lpfnWndProc = ShowWindowProcA;
7176     cls.lpszClassName = "ShowWindowClass";
7177     if(!RegisterClassA(&cls)) return FALSE;
7178
7179     cls.lpfnWndProc = PopupMsgCheckProcA;
7180     cls.lpszClassName = "TestPopupClass";
7181     if(!RegisterClassA(&cls)) return FALSE;
7182
7183     cls.lpfnWndProc = ParentMsgCheckProcA;
7184     cls.lpszClassName = "TestParentClass";
7185     if(!RegisterClassA(&cls)) return FALSE;
7186
7187     cls.lpfnWndProc = DefWindowProcA;
7188     cls.lpszClassName = "SimpleWindowClass";
7189     if(!RegisterClassA(&cls)) return FALSE;
7190
7191     cls.lpfnWndProc = PaintLoopProcA;
7192     cls.lpszClassName = "PaintLoopWindowClass";
7193     if(!RegisterClassA(&cls)) return FALSE;
7194
7195     cls.style = CS_NOCLOSE;
7196     cls.lpszClassName = "NoCloseWindowClass";
7197     if(!RegisterClassA(&cls)) return FALSE;
7198
7199     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7200     cls.style = 0;
7201     cls.hInstance = GetModuleHandleA(0);
7202     cls.hbrBackground = 0;
7203     cls.lpfnWndProc = TestDlgProcA;
7204     cls.lpszClassName = "TestDialogClass";
7205     if(!RegisterClassA(&cls)) return FALSE;
7206
7207     clsW.style = 0;
7208     clsW.lpfnWndProc = MsgCheckProcW;
7209     clsW.cbClsExtra = 0;
7210     clsW.cbWndExtra = 0;
7211     clsW.hInstance = GetModuleHandleW(0);
7212     clsW.hIcon = 0;
7213     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7214     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7215     clsW.lpszMenuName = NULL;
7216     clsW.lpszClassName = testWindowClassW;
7217     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7218
7219     return TRUE;
7220 }
7221
7222 static BOOL is_our_logged_class(HWND hwnd)
7223 {
7224     char buf[256];
7225
7226     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7227     {
7228         if (!lstrcmpiA(buf, "TestWindowClass") ||
7229             !lstrcmpiA(buf, "ShowWindowClass") ||
7230             !lstrcmpiA(buf, "TestParentClass") ||
7231             !lstrcmpiA(buf, "TestPopupClass") ||
7232             !lstrcmpiA(buf, "SimpleWindowClass") ||
7233             !lstrcmpiA(buf, "TestDialogClass") ||
7234             !lstrcmpiA(buf, "MDI_frame_class") ||
7235             !lstrcmpiA(buf, "MDI_client_class") ||
7236             !lstrcmpiA(buf, "MDI_child_class") ||
7237             !lstrcmpiA(buf, "my_button_class") ||
7238             !lstrcmpiA(buf, "my_edit_class") ||
7239             !lstrcmpiA(buf, "static") ||
7240             !lstrcmpiA(buf, "ListBox") ||
7241             !lstrcmpiA(buf, "ComboBox") ||
7242             !lstrcmpiA(buf, "MyDialogClass") ||
7243             !lstrcmpiA(buf, "#32770") ||
7244             !lstrcmpiA(buf, "#32768"))
7245         return TRUE;
7246     }
7247     return FALSE;
7248 }
7249
7250 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7251
7252     HWND hwnd;
7253
7254     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7255
7256     if (nCode == HCBT_CLICKSKIPPED)
7257     {
7258         /* ignore this event, XP sends it a lot when switching focus between windows */
7259         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7260     }
7261
7262     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7263     {
7264         struct recvd_message msg;
7265
7266         msg.hwnd = 0;
7267         msg.message = nCode;
7268         msg.flags = hook|wparam|lparam;
7269         msg.wParam = wParam;
7270         msg.lParam = lParam;
7271         msg.descr = "CBT";
7272         add_message(&msg);
7273
7274         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7275     }
7276
7277     if (nCode == HCBT_DESTROYWND)
7278     {
7279         if (test_DestroyWindow_flag)
7280         {
7281             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7282             if (style & WS_CHILD)
7283                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7284             else if (style & WS_POPUP)
7285                 lParam = WND_POPUP_ID;
7286             else
7287                 lParam = WND_PARENT_ID;
7288         }
7289     }
7290
7291     /* Log also SetFocus(0) calls */
7292     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7293
7294     if (is_our_logged_class(hwnd))
7295     {
7296         struct recvd_message msg;
7297
7298         msg.hwnd = hwnd;
7299         msg.message = nCode;
7300         msg.flags = hook|wparam|lparam;
7301         msg.wParam = wParam;
7302         msg.lParam = lParam;
7303         msg.descr = "CBT";
7304         add_message(&msg);
7305     }
7306     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7307 }
7308
7309 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7310                                     DWORD event,
7311                                     HWND hwnd,
7312                                     LONG object_id,
7313                                     LONG child_id,
7314                                     DWORD thread_id,
7315                                     DWORD event_time)
7316 {
7317     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7318
7319     /* ignore mouse cursor events */
7320     if (object_id == OBJID_CURSOR) return;
7321
7322     if (!hwnd || is_our_logged_class(hwnd))
7323     {
7324         struct recvd_message msg;
7325
7326         msg.hwnd = hwnd;
7327         msg.message = event;
7328         msg.flags = winevent_hook|wparam|lparam;
7329         msg.wParam = object_id;
7330         msg.lParam = child_id;
7331         msg.descr = "WEH";
7332         add_message(&msg);
7333     }
7334 }
7335
7336 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7337 static const WCHAR wszAnsi[] = {'U',0};
7338
7339 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7340 {
7341     switch (uMsg)
7342     {
7343     case CB_FINDSTRINGEXACT:
7344         trace("String: %p\n", (LPCWSTR)lParam);
7345         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7346             return 1;
7347         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7348             return 0;
7349         return -1;
7350     }
7351     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7352 }
7353
7354 static const struct message WmGetTextLengthAfromW[] = {
7355     { WM_GETTEXTLENGTH, sent },
7356     { WM_GETTEXT, sent|optional },
7357     { 0 }
7358 };
7359
7360 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7361
7362 /* dummy window proc for WM_GETTEXTLENGTH test */
7363 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7364 {
7365     switch(msg)
7366     {
7367     case WM_GETTEXTLENGTH:
7368         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7369     case WM_GETTEXT:
7370         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7371         return lstrlenW( (LPWSTR)lp );
7372     default:
7373         return DefWindowProcW( hwnd, msg, wp, lp );
7374     }
7375 }
7376
7377 static void test_message_conversion(void)
7378 {
7379     static const WCHAR wszMsgConversionClass[] =
7380         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7381     WNDCLASSW cls;
7382     LRESULT lRes;
7383     HWND hwnd;
7384     WNDPROC wndproc, newproc;
7385     BOOL ret;
7386
7387     cls.style = 0;
7388     cls.lpfnWndProc = MsgConversionProcW;
7389     cls.cbClsExtra = 0;
7390     cls.cbWndExtra = 0;
7391     cls.hInstance = GetModuleHandleW(NULL);
7392     cls.hIcon = NULL;
7393     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7394     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7395     cls.lpszMenuName = NULL;
7396     cls.lpszClassName = wszMsgConversionClass;
7397     /* this call will fail on Win9x, but that doesn't matter as this test is
7398      * meaningless on those platforms */
7399     if(!RegisterClassW(&cls)) return;
7400
7401     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7402                            100, 100, 200, 200, 0, 0, 0, NULL);
7403     ok(hwnd != NULL, "Window creation failed\n");
7404
7405     /* {W, A} -> A */
7406
7407     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7408     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7409     ok(lRes == 0, "String should have been converted\n");
7410     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7411     ok(lRes == 1, "String shouldn't have been converted\n");
7412
7413     /* {W, A} -> W */
7414
7415     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7416     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7417     ok(lRes == 1, "String shouldn't have been converted\n");
7418     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7419     ok(lRes == 1, "String shouldn't have been converted\n");
7420
7421     /* Synchronous messages */
7422
7423     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7424     ok(lRes == 0, "String should have been converted\n");
7425     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7426     ok(lRes == 1, "String shouldn't have been converted\n");
7427
7428     /* Asynchronous messages */
7429
7430     SetLastError(0);
7431     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7432     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7433         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7434     SetLastError(0);
7435     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7436     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7437         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7438     SetLastError(0);
7439     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7440     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7441         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7442     SetLastError(0);
7443     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7444     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7445         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7446     SetLastError(0);
7447     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7448     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7449         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7450     SetLastError(0);
7451     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7452     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7453         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7454     SetLastError(0);
7455     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7456     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7457         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7458     SetLastError(0);
7459     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7460     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7461         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7462
7463     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7464
7465     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7466                           WS_OVERLAPPEDWINDOW,
7467                           100, 100, 200, 200, 0, 0, 0, NULL);
7468     assert(hwnd);
7469     flush_sequence();
7470     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7471     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7472     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7473         "got bad length %ld\n", lRes );
7474
7475     flush_sequence();
7476     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7477                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7478     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7479     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7480         "got bad length %ld\n", lRes );
7481
7482     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7483     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7484     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7485     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7486                                      NULL, 0, NULL, NULL ) ||
7487         broken(lRes == lstrlenW(dummy_window_text) + 37),
7488         "got bad length %ld\n", lRes );
7489
7490     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7491     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7492     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7493                                      NULL, 0, NULL, NULL ) ||
7494         broken(lRes == lstrlenW(dummy_window_text) + 37),
7495         "got bad length %ld\n", lRes );
7496
7497     ret = DestroyWindow(hwnd);
7498     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7499 }
7500
7501 struct timer_info
7502 {
7503     HWND hWnd;
7504     HANDLE handles[2];
7505     DWORD id;
7506 };
7507
7508 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7509 {
7510 }
7511
7512 #define TIMER_ID  0x19
7513
7514 static DWORD WINAPI timer_thread_proc(LPVOID x)
7515 {
7516     struct timer_info *info = x;
7517     DWORD r;
7518
7519     r = KillTimer(info->hWnd, 0x19);
7520     ok(r,"KillTimer failed in thread\n");
7521     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7522     ok(r,"SetTimer failed in thread\n");
7523     ok(r==TIMER_ID,"SetTimer id different\n");
7524     r = SetEvent(info->handles[0]);
7525     ok(r,"SetEvent failed in thread\n");
7526     return 0;
7527 }
7528
7529 static void test_timers(void)
7530 {
7531     struct timer_info info;
7532     DWORD id;
7533
7534     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7535        WS_OVERLAPPEDWINDOW ,
7536        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7537        NULL, NULL, 0);
7538
7539     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7540     ok(info.id, "SetTimer failed\n");
7541     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7542     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7543     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7544
7545     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7546
7547     WaitForSingleObject(info.handles[1], INFINITE);
7548
7549     CloseHandle(info.handles[0]);
7550     CloseHandle(info.handles[1]);
7551
7552     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7553
7554     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7555 }
7556
7557 static int count = 0;
7558 static VOID CALLBACK callback_count(
7559     HWND hwnd,
7560     UINT uMsg,
7561     UINT_PTR idEvent,
7562     DWORD dwTime
7563 )
7564 {
7565     count++;
7566 }
7567
7568 static void test_timers_no_wnd(void)
7569 {
7570     UINT_PTR id, id2;
7571     MSG msg;
7572
7573     count = 0;
7574     id = SetTimer(NULL, 0, 100, callback_count);
7575     ok(id != 0, "did not get id from SetTimer.\n");
7576     id2 = SetTimer(NULL, id, 200, callback_count);
7577     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7578     Sleep(150);
7579     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7580     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7581     Sleep(150);
7582     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7583     ok(count == 1, "did not get one count as expected (%i).\n", count);
7584     KillTimer(NULL, id);
7585     Sleep(250);
7586     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7587     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7588 }
7589
7590 /* Various win events with arbitrary parameters */
7591 static const struct message WmWinEventsSeq[] = {
7592     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7593     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7594     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7595     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7596     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7597     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7598     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7599     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7600     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7601     /* our win event hook ignores OBJID_CURSOR events */
7602     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7603     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7604     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7605     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7606     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7607     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7608     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7609     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7610     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7611     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7612     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7613     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7614     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7615     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7616     { 0 }
7617 };
7618 static const struct message WmWinEventCaretSeq[] = {
7619     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7620     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7621     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7622     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7623     { 0 }
7624 };
7625 static const struct message WmWinEventCaretSeq_2[] = {
7626     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7627     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7628     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7629     { 0 }
7630 };
7631 static const struct message WmWinEventAlertSeq[] = {
7632     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7633     { 0 }
7634 };
7635 static const struct message WmWinEventAlertSeq_2[] = {
7636     /* create window in the thread proc */
7637     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7638     /* our test event */
7639     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7640     { 0 }
7641 };
7642 static const struct message WmGlobalHookSeq_1[] = {
7643     /* create window in the thread proc */
7644     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7645     /* our test events */
7646     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7647     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7648     { 0 }
7649 };
7650 static const struct message WmGlobalHookSeq_2[] = {
7651     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7652     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7653     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7654     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7655     { 0 }
7656 };
7657
7658 static const struct message WmMouseLLHookSeq[] = {
7659     { WM_MOUSEMOVE, hook },
7660     { WM_LBUTTONUP, hook },
7661     { WM_MOUSEMOVE, hook },
7662     { 0 }
7663 };
7664
7665 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7666                                          DWORD event,
7667                                          HWND hwnd,
7668                                          LONG object_id,
7669                                          LONG child_id,
7670                                          DWORD thread_id,
7671                                          DWORD event_time)
7672 {
7673     char buf[256];
7674
7675     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7676     {
7677         if (!lstrcmpiA(buf, "TestWindowClass") ||
7678             !lstrcmpiA(buf, "static"))
7679         {
7680             struct recvd_message msg;
7681
7682             msg.hwnd = hwnd;
7683             msg.message = event;
7684             msg.flags = winevent_hook|wparam|lparam;
7685             msg.wParam = object_id;
7686             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7687             msg.descr = "WEH_2";
7688             add_message(&msg);
7689         }
7690     }
7691 }
7692
7693 static HHOOK hCBT_global_hook;
7694 static DWORD cbt_global_hook_thread_id;
7695
7696 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7697
7698     HWND hwnd;
7699     char buf[256];
7700
7701     if (nCode == HCBT_SYSCOMMAND)
7702     {
7703         struct recvd_message msg;
7704
7705         msg.hwnd = 0;
7706         msg.message = nCode;
7707         msg.flags = hook|wparam|lparam;
7708         msg.wParam = wParam;
7709         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7710         msg.descr = "CBT_2";
7711         add_message(&msg);
7712
7713         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7714     }
7715     /* WH_MOUSE_LL hook */
7716     if (nCode == HC_ACTION)
7717     {
7718         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7719
7720         /* we can't test for real mouse events */
7721         if (mhll->flags & LLMHF_INJECTED)
7722         {
7723             struct recvd_message msg;
7724
7725             memset (&msg, 0, sizeof (msg));
7726             msg.message = wParam;
7727             msg.flags = hook;
7728             msg.descr = "CBT_2";
7729             add_message(&msg);
7730         }
7731         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7732     }
7733
7734     /* Log also SetFocus(0) calls */
7735     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7736
7737     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7738     {
7739         if (!lstrcmpiA(buf, "TestWindowClass") ||
7740             !lstrcmpiA(buf, "static"))
7741         {
7742             struct recvd_message msg;
7743
7744             msg.hwnd = hwnd;
7745             msg.message = nCode;
7746             msg.flags = hook|wparam|lparam;
7747             msg.wParam = wParam;
7748             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7749             msg.descr = "CBT_2";
7750             add_message(&msg);
7751         }
7752     }
7753     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7754 }
7755
7756 static DWORD WINAPI win_event_global_thread_proc(void *param)
7757 {
7758     HWND hwnd;
7759     MSG msg;
7760     HANDLE hevent = *(HANDLE *)param;
7761
7762     assert(pNotifyWinEvent);
7763
7764     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7765     assert(hwnd);
7766     trace("created thread window %p\n", hwnd);
7767
7768     *(HWND *)param = hwnd;
7769
7770     flush_sequence();
7771     /* this event should be received only by our new hook proc,
7772      * an old one does not expect an event from another thread.
7773      */
7774     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7775     SetEvent(hevent);
7776
7777     while (GetMessage(&msg, 0, 0, 0))
7778     {
7779         TranslateMessage(&msg);
7780         DispatchMessage(&msg);
7781     }
7782     return 0;
7783 }
7784
7785 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7786 {
7787     HWND hwnd;
7788     MSG msg;
7789     HANDLE hevent = *(HANDLE *)param;
7790
7791     flush_sequence();
7792     /* these events should be received only by our new hook proc,
7793      * an old one does not expect an event from another thread.
7794      */
7795
7796     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7797     assert(hwnd);
7798     trace("created thread window %p\n", hwnd);
7799
7800     *(HWND *)param = hwnd;
7801
7802     /* Windows doesn't like when a thread plays games with the focus,
7803        that leads to all kinds of misbehaviours and failures to activate
7804        a window. So, better keep next lines commented out.
7805     SetFocus(0);
7806     SetFocus(hwnd);*/
7807
7808     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7809     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7810
7811     SetEvent(hevent);
7812
7813     while (GetMessage(&msg, 0, 0, 0))
7814     {
7815         TranslateMessage(&msg);
7816         DispatchMessage(&msg);
7817     }
7818     return 0;
7819 }
7820
7821 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7822 {
7823     HWND hwnd;
7824     MSG msg;
7825     HANDLE hevent = *(HANDLE *)param;
7826
7827     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7828     assert(hwnd);
7829     trace("created thread window %p\n", hwnd);
7830
7831     *(HWND *)param = hwnd;
7832
7833     flush_sequence();
7834
7835     /* Windows doesn't like when a thread plays games with the focus,
7836      * that leads to all kinds of misbehaviours and failures to activate
7837      * a window. So, better don't generate a mouse click message below.
7838      */
7839     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7840     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7841     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7842
7843     SetEvent(hevent);
7844     while (GetMessage(&msg, 0, 0, 0))
7845     {
7846         TranslateMessage(&msg);
7847         DispatchMessage(&msg);
7848     }
7849     return 0;
7850 }
7851
7852 static void test_winevents(void)
7853 {
7854     BOOL ret;
7855     MSG msg;
7856     HWND hwnd, hwnd2;
7857     UINT i;
7858     HANDLE hthread, hevent;
7859     DWORD tid;
7860     HWINEVENTHOOK hhook;
7861     const struct message *events = WmWinEventsSeq;
7862
7863     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7864                            WS_OVERLAPPEDWINDOW,
7865                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7866                            NULL, NULL, 0);
7867     assert(hwnd);
7868
7869     /****** start of global hook test *************/
7870     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7871     if (!hCBT_global_hook)
7872     {
7873         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7874         skip( "cannot set global hook\n" );
7875         return;
7876     }
7877
7878     hevent = CreateEventA(NULL, 0, 0, NULL);
7879     assert(hevent);
7880     hwnd2 = hevent;
7881
7882     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7883     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7884
7885     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7886
7887     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7888
7889     flush_sequence();
7890     /* this one should be received only by old hook proc */
7891     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7892     /* this one should be received only by old hook proc */
7893     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7894
7895     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7896
7897     ret = UnhookWindowsHookEx(hCBT_global_hook);
7898     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7899
7900     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7901     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7902     CloseHandle(hthread);
7903     CloseHandle(hevent);
7904     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7905     /****** end of global hook test *************/
7906
7907     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7908     {
7909         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7910         return;
7911     }
7912
7913     flush_sequence();
7914
7915     if (0)
7916     {
7917     /* this test doesn't pass under Win9x */
7918     /* win2k ignores events with hwnd == 0 */
7919     SetLastError(0xdeadbeef);
7920     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7921     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7922        GetLastError() == 0xdeadbeef, /* Win9x */
7923        "unexpected error %d\n", GetLastError());
7924     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7925     }
7926
7927     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7928         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7929
7930     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7931
7932     /****** start of event filtering test *************/
7933     hhook = pSetWinEventHook(
7934         EVENT_OBJECT_SHOW, /* 0x8002 */
7935         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7936         GetModuleHandleA(0), win_event_global_hook_proc,
7937         GetCurrentProcessId(), 0,
7938         WINEVENT_INCONTEXT);
7939     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7940
7941     hevent = CreateEventA(NULL, 0, 0, NULL);
7942     assert(hevent);
7943     hwnd2 = hevent;
7944
7945     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7946     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7947
7948     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7949
7950     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7951
7952     flush_sequence();
7953     /* this one should be received only by old hook proc */
7954     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7955     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7956     /* this one should be received only by old hook proc */
7957     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7958
7959     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7960
7961     ret = pUnhookWinEvent(hhook);
7962     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7963
7964     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7965     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7966     CloseHandle(hthread);
7967     CloseHandle(hevent);
7968     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7969     /****** end of event filtering test *************/
7970
7971     /****** start of out of context event test *************/
7972     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
7973         win_event_global_hook_proc, GetCurrentProcessId(), 0,
7974         WINEVENT_OUTOFCONTEXT);
7975     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7976
7977     hevent = CreateEventA(NULL, 0, 0, NULL);
7978     assert(hevent);
7979     hwnd2 = hevent;
7980
7981     flush_sequence();
7982
7983     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7984     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7985
7986     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7987
7988     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7989     /* process pending winevent messages */
7990     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7991     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7992
7993     flush_sequence();
7994     /* this one should be received only by old hook proc */
7995     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7996     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7997     /* this one should be received only by old hook proc */
7998     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7999
8000     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8001     /* process pending winevent messages */
8002     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8003     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8004
8005     ret = pUnhookWinEvent(hhook);
8006     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8007
8008     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8009     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8010     CloseHandle(hthread);
8011     CloseHandle(hevent);
8012     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8013     /****** end of out of context event test *************/
8014
8015     /****** start of MOUSE_LL hook test *************/
8016     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8017     /* WH_MOUSE_LL is not supported on Win9x platforms */
8018     if (!hCBT_global_hook)
8019     {
8020         trace("Skipping WH_MOUSE_LL test on this platform\n");
8021         goto skip_mouse_ll_hook_test;
8022     }
8023
8024     hevent = CreateEventA(NULL, 0, 0, NULL);
8025     assert(hevent);
8026     hwnd2 = hevent;
8027
8028     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8029     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8030
8031     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8032         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8033
8034     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8035     flush_sequence();
8036
8037     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8038     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8039     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8040
8041     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8042
8043     ret = UnhookWindowsHookEx(hCBT_global_hook);
8044     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8045
8046     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8047     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8048     CloseHandle(hthread);
8049     CloseHandle(hevent);
8050     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8051     /****** end of MOUSE_LL hook test *************/
8052 skip_mouse_ll_hook_test:
8053
8054     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8055 }
8056
8057 static void test_set_hook(void)
8058 {
8059     BOOL ret;
8060     HHOOK hhook;
8061     HWINEVENTHOOK hwinevent_hook;
8062
8063     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8064     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8065     UnhookWindowsHookEx(hhook);
8066
8067     if (0)
8068     {
8069     /* this test doesn't pass under Win9x: BUG! */
8070     SetLastError(0xdeadbeef);
8071     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8072     ok(!hhook, "global hook requires hModule != 0\n");
8073     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8074     }
8075
8076     SetLastError(0xdeadbeef);
8077     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8078     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8079     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8080        GetLastError() == 0xdeadbeef, /* Win9x */
8081        "unexpected error %d\n", GetLastError());
8082
8083     SetLastError(0xdeadbeef);
8084     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8085     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8086        GetLastError() == 0xdeadbeef, /* Win9x */
8087        "unexpected error %d\n", GetLastError());
8088
8089     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8090
8091     /* even process local incontext hooks require hmodule */
8092     SetLastError(0xdeadbeef);
8093     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8094         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8095     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8096     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8097        GetLastError() == 0xdeadbeef, /* Win9x */
8098        "unexpected error %d\n", GetLastError());
8099
8100     /* even thread local incontext hooks require hmodule */
8101     SetLastError(0xdeadbeef);
8102     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8103         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8104     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8105     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8106        GetLastError() == 0xdeadbeef, /* Win9x */
8107        "unexpected error %d\n", GetLastError());
8108
8109     if (0)
8110     {
8111     /* these 3 tests don't pass under Win9x */
8112     SetLastError(0xdeadbeef);
8113     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8114         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8115     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8116     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8117
8118     SetLastError(0xdeadbeef);
8119     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8120         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8121     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8122     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8123
8124     SetLastError(0xdeadbeef);
8125     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8126         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8127     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8128     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8129     }
8130
8131     SetLastError(0xdeadbeef);
8132     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8133         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8134     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8135     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8136     ret = pUnhookWinEvent(hwinevent_hook);
8137     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8138
8139 todo_wine {
8140     /* This call succeeds under win2k SP4, but fails under Wine.
8141        Does win2k test/use passed process id? */
8142     SetLastError(0xdeadbeef);
8143     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8144         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8145     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8146     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8147     ret = pUnhookWinEvent(hwinevent_hook);
8148     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8149 }
8150
8151     SetLastError(0xdeadbeef);
8152     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8153     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8154         GetLastError() == 0xdeadbeef, /* Win9x */
8155         "unexpected error %d\n", GetLastError());
8156 }
8157
8158 static const struct message ScrollWindowPaint1[] = {
8159     { WM_PAINT, sent },
8160     { WM_ERASEBKGND, sent|beginpaint },
8161     { 0 }
8162 };
8163
8164 static const struct message ScrollWindowPaint2[] = {
8165     { WM_PAINT, sent },
8166     { 0 }
8167 };
8168
8169 static void test_scrollwindowex(void)
8170 {
8171     HWND hwnd, hchild;
8172     RECT rect={0,0,130,130};
8173
8174     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8175             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8176             100, 100, 200, 200, 0, 0, 0, NULL);
8177     ok (hwnd != 0, "Failed to create overlapped window\n");
8178     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8179             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8180             10, 10, 150, 150, hwnd, 0, 0, NULL);
8181     ok (hchild != 0, "Failed to create child\n");
8182     UpdateWindow(hwnd);
8183     flush_events();
8184     flush_sequence();
8185
8186     /* scroll without the child window */
8187     trace("start scroll\n");
8188     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8189             SW_ERASE|SW_INVALIDATE);
8190     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8191     trace("end scroll\n");
8192     flush_sequence();
8193     flush_events();
8194     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8195     flush_events();
8196     flush_sequence();
8197
8198     /* Now without the SW_ERASE flag */
8199     trace("start scroll\n");
8200     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8201     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8202     trace("end scroll\n");
8203     flush_sequence();
8204     flush_events();
8205     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8206     flush_events();
8207     flush_sequence();
8208
8209     /* now scroll the child window as well */
8210     trace("start scroll\n");
8211     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8212             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8213     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8214     /* windows sometimes a WM_MOVE */
8215     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8216     trace("end scroll\n");
8217     flush_sequence();
8218     flush_events();
8219     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8220     flush_events();
8221     flush_sequence();
8222
8223     /* now scroll with ScrollWindow() */
8224     trace("start scroll with ScrollWindow\n");
8225     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8226     trace("end scroll\n");
8227     flush_sequence();
8228     flush_events();
8229     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8230
8231     ok(DestroyWindow(hchild), "failed to destroy window\n");
8232     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8233     flush_sequence();
8234 }
8235
8236 static const struct message destroy_window_with_children[] = {
8237     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8238     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8239     { 0x0090, sent|optional },
8240     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8241     { 0x0090, sent|optional },
8242     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8243     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8244     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8245     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8246     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8247     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8248     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8249     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8250     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8251     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8252     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8253     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8254     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8255     { 0 }
8256 };
8257
8258 static void test_DestroyWindow(void)
8259 {
8260     BOOL ret;
8261     HWND parent, child1, child2, child3, child4, test;
8262     UINT_PTR child_id = WND_CHILD_ID + 1;
8263
8264     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8265                              100, 100, 200, 200, 0, 0, 0, NULL);
8266     assert(parent != 0);
8267     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8268                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8269     assert(child1 != 0);
8270     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8271                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8272     assert(child2 != 0);
8273     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8274                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8275     assert(child3 != 0);
8276     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8277                              0, 0, 50, 50, parent, 0, 0, NULL);
8278     assert(child4 != 0);
8279
8280     /* test owner/parent of child2 */
8281     test = GetParent(child2);
8282     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8283     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8284     if(pGetAncestor) {
8285         test = pGetAncestor(child2, GA_PARENT);
8286         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8287     }
8288     test = GetWindow(child2, GW_OWNER);
8289     ok(!test, "wrong owner %p\n", test);
8290
8291     test = SetParent(child2, parent);
8292     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8293
8294     /* test owner/parent of the parent */
8295     test = GetParent(parent);
8296     ok(!test, "wrong parent %p\n", test);
8297     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8298     if(pGetAncestor) {
8299         test = pGetAncestor(parent, GA_PARENT);
8300         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8301     }
8302     test = GetWindow(parent, GW_OWNER);
8303     ok(!test, "wrong owner %p\n", test);
8304
8305     /* test owner/parent of child1 */
8306     test = GetParent(child1);
8307     ok(test == parent, "wrong parent %p\n", test);
8308     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8309     if(pGetAncestor) {
8310         test = pGetAncestor(child1, GA_PARENT);
8311         ok(test == parent, "wrong parent %p\n", test);
8312     }
8313     test = GetWindow(child1, GW_OWNER);
8314     ok(!test, "wrong owner %p\n", test);
8315
8316     /* test owner/parent of child2 */
8317     test = GetParent(child2);
8318     ok(test == parent, "wrong parent %p\n", test);
8319     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8320     if(pGetAncestor) {
8321         test = pGetAncestor(child2, GA_PARENT);
8322         ok(test == parent, "wrong parent %p\n", test);
8323     }
8324     test = GetWindow(child2, GW_OWNER);
8325     ok(!test, "wrong owner %p\n", test);
8326
8327     /* test owner/parent of child3 */
8328     test = GetParent(child3);
8329     ok(test == child1, "wrong parent %p\n", test);
8330     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8331     if(pGetAncestor) {
8332         test = pGetAncestor(child3, GA_PARENT);
8333         ok(test == child1, "wrong parent %p\n", test);
8334     }
8335     test = GetWindow(child3, GW_OWNER);
8336     ok(!test, "wrong owner %p\n", test);
8337
8338     /* test owner/parent of child4 */
8339     test = GetParent(child4);
8340     ok(test == parent, "wrong parent %p\n", test);
8341     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8342     if(pGetAncestor) {
8343         test = pGetAncestor(child4, GA_PARENT);
8344         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8345     }
8346     test = GetWindow(child4, GW_OWNER);
8347     ok(test == parent, "wrong owner %p\n", test);
8348
8349     flush_sequence();
8350
8351     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8352            parent, child1, child2, child3, child4);
8353
8354     SetCapture(child4);
8355     test = GetCapture();
8356     ok(test == child4, "wrong capture window %p\n", test);
8357
8358     test_DestroyWindow_flag = TRUE;
8359     ret = DestroyWindow(parent);
8360     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8361     test_DestroyWindow_flag = FALSE;
8362     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8363
8364     ok(!IsWindow(parent), "parent still exists\n");
8365     ok(!IsWindow(child1), "child1 still exists\n");
8366     ok(!IsWindow(child2), "child2 still exists\n");
8367     ok(!IsWindow(child3), "child3 still exists\n");
8368     ok(!IsWindow(child4), "child4 still exists\n");
8369
8370     test = GetCapture();
8371     ok(!test, "wrong capture window %p\n", test);
8372 }
8373
8374
8375 static const struct message WmDispatchPaint[] = {
8376     { WM_NCPAINT, sent },
8377     { WM_GETTEXT, sent|defwinproc|optional },
8378     { WM_GETTEXT, sent|defwinproc|optional },
8379     { WM_ERASEBKGND, sent },
8380     { 0 }
8381 };
8382
8383 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8384 {
8385     if (message == WM_PAINT) return 0;
8386     return MsgCheckProcA( hwnd, message, wParam, lParam );
8387 }
8388
8389 static void test_DispatchMessage(void)
8390 {
8391     RECT rect;
8392     MSG msg;
8393     int count;
8394     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8395                                100, 100, 200, 200, 0, 0, 0, NULL);
8396     ShowWindow( hwnd, SW_SHOW );
8397     UpdateWindow( hwnd );
8398     flush_events();
8399     flush_sequence();
8400     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8401
8402     SetRect( &rect, -5, -5, 5, 5 );
8403     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8404     count = 0;
8405     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8406     {
8407         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8408         else
8409         {
8410             flush_sequence();
8411             DispatchMessage( &msg );
8412             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8413             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8414             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8415             if (++count > 10) break;
8416         }
8417     }
8418     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8419
8420     trace("now without DispatchMessage\n");
8421     flush_sequence();
8422     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8423     count = 0;
8424     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8425     {
8426         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8427         else
8428         {
8429             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8430             flush_sequence();
8431             /* this will send WM_NCCPAINT just like DispatchMessage does */
8432             GetUpdateRgn( hwnd, hrgn, TRUE );
8433             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8434             DeleteObject( hrgn );
8435             GetClientRect( hwnd, &rect );
8436             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8437             ok( !count, "Got multiple WM_PAINTs\n" );
8438             if (++count > 10) break;
8439         }
8440     }
8441     DestroyWindow(hwnd);
8442 }
8443
8444
8445 static const struct message WmUser[] = {
8446     { WM_USER, sent },
8447     { 0 }
8448 };
8449
8450 struct sendmsg_info
8451 {
8452     HWND  hwnd;
8453     DWORD timeout;
8454     DWORD ret;
8455 };
8456
8457 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8458 {
8459     struct sendmsg_info *info = arg;
8460     SetLastError( 0xdeadbeef );
8461     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8462     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8463                         broken(GetLastError() == 0),  /* win9x */
8464                         "unexpected error %d\n", GetLastError());
8465     return 0;
8466 }
8467
8468 static void wait_for_thread( HANDLE thread )
8469 {
8470     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8471     {
8472         MSG msg;
8473         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8474     }
8475 }
8476
8477 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8478 {
8479     if (message == WM_USER) Sleep(200);
8480     return MsgCheckProcA( hwnd, message, wParam, lParam );
8481 }
8482
8483 static void test_SendMessageTimeout(void)
8484 {
8485     HANDLE thread;
8486     struct sendmsg_info info;
8487     DWORD tid;
8488     BOOL is_win9x;
8489
8490     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8491                                100, 100, 200, 200, 0, 0, 0, NULL);
8492     flush_events();
8493     flush_sequence();
8494
8495     info.timeout = 1000;
8496     info.ret = 0xdeadbeef;
8497     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8498     wait_for_thread( thread );
8499     CloseHandle( thread );
8500     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8501     ok_sequence( WmUser, "WmUser", FALSE );
8502
8503     info.timeout = 1;
8504     info.ret = 0xdeadbeef;
8505     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8506     Sleep(100);  /* SendMessageTimeout should time out here */
8507     wait_for_thread( thread );
8508     CloseHandle( thread );
8509     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8510     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8511
8512     /* 0 means infinite timeout (but not on win9x) */
8513     info.timeout = 0;
8514     info.ret = 0xdeadbeef;
8515     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8516     Sleep(100);
8517     wait_for_thread( thread );
8518     CloseHandle( thread );
8519     is_win9x = !info.ret;
8520     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8521     else ok_sequence( WmUser, "WmUser", FALSE );
8522
8523     /* timeout is treated as signed despite the prototype (but not on win9x) */
8524     info.timeout = 0x7fffffff;
8525     info.ret = 0xdeadbeef;
8526     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8527     Sleep(100);
8528     wait_for_thread( thread );
8529     CloseHandle( thread );
8530     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8531     ok_sequence( WmUser, "WmUser", FALSE );
8532
8533     info.timeout = 0x80000000;
8534     info.ret = 0xdeadbeef;
8535     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8536     Sleep(100);
8537     wait_for_thread( thread );
8538     CloseHandle( thread );
8539     if (is_win9x)
8540     {
8541         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8542         ok_sequence( WmUser, "WmUser", FALSE );
8543     }
8544     else
8545     {
8546         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8547         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8548     }
8549
8550     /* now check for timeout during message processing */
8551     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8552     info.timeout = 100;
8553     info.ret = 0xdeadbeef;
8554     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8555     wait_for_thread( thread );
8556     CloseHandle( thread );
8557     /* we should time out but still get the message */
8558     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8559     ok_sequence( WmUser, "WmUser", FALSE );
8560
8561     DestroyWindow( info.hwnd );
8562 }
8563
8564
8565 /****************** edit message test *************************/
8566 #define ID_EDIT 0x1234
8567 static const struct message sl_edit_setfocus[] =
8568 {
8569     { HCBT_SETFOCUS, hook },
8570     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8571     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8572     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8573     { WM_SETFOCUS, sent|wparam, 0 },
8574     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8575     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8576     { WM_CTLCOLOREDIT, sent|parent },
8577     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8578     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8579     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8580     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8581     { 0 }
8582 };
8583 static const struct message ml_edit_setfocus[] =
8584 {
8585     { HCBT_SETFOCUS, hook },
8586     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8587     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8588     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8589     { WM_SETFOCUS, sent|wparam, 0 },
8590     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8591     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8592     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8593     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8594     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8595     { 0 }
8596 };
8597 static const struct message sl_edit_killfocus[] =
8598 {
8599     { HCBT_SETFOCUS, hook },
8600     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8601     { WM_KILLFOCUS, sent|wparam, 0 },
8602     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8603     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8604     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8605     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8606     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8607     { 0 }
8608 };
8609 static const struct message sl_edit_lbutton_dblclk[] =
8610 {
8611     { WM_LBUTTONDBLCLK, sent },
8612     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8613     { 0 }
8614 };
8615 static const struct message sl_edit_lbutton_down[] =
8616 {
8617     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8618     { HCBT_SETFOCUS, hook },
8619     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8620     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8621     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8622     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8623     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8624     { WM_CTLCOLOREDIT, sent|parent },
8625     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8626     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8627     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8628     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8629     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8630     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8631     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8632     { WM_CTLCOLOREDIT, sent|parent|optional },
8633     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8635     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8636     { 0 }
8637 };
8638 static const struct message ml_edit_lbutton_down[] =
8639 {
8640     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8641     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8642     { HCBT_SETFOCUS, hook },
8643     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8644     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8645     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8646     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8647     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8648     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8649     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8650     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8651     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8652     { 0 }
8653 };
8654 static const struct message sl_edit_lbutton_up[] =
8655 {
8656     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8657     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8658     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8659     { WM_CAPTURECHANGED, sent|defwinproc },
8660     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8661     { 0 }
8662 };
8663 static const struct message ml_edit_lbutton_up[] =
8664 {
8665     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8666     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8667     { WM_CAPTURECHANGED, sent|defwinproc },
8668     { 0 }
8669 };
8670
8671 static WNDPROC old_edit_proc;
8672
8673 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8674 {
8675     static long defwndproc_counter = 0;
8676     LRESULT ret;
8677     struct recvd_message msg;
8678
8679     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8680
8681     msg.hwnd = hwnd;
8682     msg.message = message;
8683     msg.flags = sent|wparam|lparam;
8684     if (defwndproc_counter) msg.flags |= defwinproc;
8685     msg.wParam = wParam;
8686     msg.lParam = lParam;
8687     msg.descr = "edit";
8688     add_message(&msg);
8689
8690     defwndproc_counter++;
8691     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8692     defwndproc_counter--;
8693
8694     return ret;
8695 }
8696
8697 static void subclass_edit(void)
8698 {
8699     WNDCLASSA cls;
8700
8701     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8702
8703     old_edit_proc = cls.lpfnWndProc;
8704
8705     cls.hInstance = GetModuleHandle(0);
8706     cls.lpfnWndProc = edit_hook_proc;
8707     cls.lpszClassName = "my_edit_class";
8708     UnregisterClass(cls.lpszClassName, cls.hInstance);
8709     if (!RegisterClassA(&cls)) assert(0);
8710 }
8711
8712 static void test_edit_messages(void)
8713 {
8714     HWND hwnd, parent;
8715     DWORD dlg_code;
8716
8717     subclass_edit();
8718     log_all_parent_messages++;
8719
8720     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8721                              100, 100, 200, 200, 0, 0, 0, NULL);
8722     ok (parent != 0, "Failed to create parent window\n");
8723
8724     /* test single line edit */
8725     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8726                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8727     ok(hwnd != 0, "Failed to create edit window\n");
8728
8729     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8730     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8731
8732     ShowWindow(hwnd, SW_SHOW);
8733     UpdateWindow(hwnd);
8734     SetFocus(0);
8735     flush_sequence();
8736
8737     SetFocus(hwnd);
8738     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8739
8740     SetFocus(0);
8741     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8742
8743     SetFocus(0);
8744     ReleaseCapture();
8745     flush_sequence();
8746
8747     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8748     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8749
8750     SetFocus(0);
8751     ReleaseCapture();
8752     flush_sequence();
8753
8754     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8755     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8756
8757     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8758     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8759
8760     DestroyWindow(hwnd);
8761
8762     /* test multiline edit */
8763     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8764                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8765     ok(hwnd != 0, "Failed to create edit window\n");
8766
8767     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8768     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8769        "wrong dlg_code %08x\n", dlg_code);
8770
8771     ShowWindow(hwnd, SW_SHOW);
8772     UpdateWindow(hwnd);
8773     SetFocus(0);
8774     flush_sequence();
8775
8776     SetFocus(hwnd);
8777     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8778
8779     SetFocus(0);
8780     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8781
8782     SetFocus(0);
8783     ReleaseCapture();
8784     flush_sequence();
8785
8786     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8787     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8788
8789     SetFocus(0);
8790     ReleaseCapture();
8791     flush_sequence();
8792
8793     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8794     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8795
8796     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8797     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8798
8799     DestroyWindow(hwnd);
8800     DestroyWindow(parent);
8801
8802     log_all_parent_messages--;
8803 }
8804
8805 /**************************** End of Edit test ******************************/
8806
8807 static const struct message WmKeyDownSkippedSeq[] =
8808 {
8809     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8810     { 0 }
8811 };
8812 static const struct message WmKeyDownWasDownSkippedSeq[] =
8813 {
8814     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8815     { 0 }
8816 };
8817 static const struct message WmKeyUpSkippedSeq[] =
8818 {
8819     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8820     { 0 }
8821 };
8822 static const struct message WmUserKeyUpSkippedSeq[] =
8823 {
8824     { WM_USER, sent },
8825     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8826     { 0 }
8827 };
8828
8829 #define EV_STOP 0
8830 #define EV_SENDMSG 1
8831 #define EV_ACK 2
8832
8833 struct peekmsg_info
8834 {
8835     HWND  hwnd;
8836     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8837 };
8838
8839 static DWORD CALLBACK send_msg_thread_2(void *param)
8840 {
8841     DWORD ret;
8842     struct peekmsg_info *info = param;
8843
8844     trace("thread: looping\n");
8845     SetEvent(info->hevent[EV_ACK]);
8846
8847     while (1)
8848     {
8849         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8850
8851         switch (ret)
8852         {
8853         case WAIT_OBJECT_0 + EV_STOP:
8854             trace("thread: exiting\n");
8855             return 0;
8856
8857         case WAIT_OBJECT_0 + EV_SENDMSG:
8858             trace("thread: sending message\n");
8859             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8860                 "SendNotifyMessageA failed error %u\n", GetLastError());
8861             SetEvent(info->hevent[EV_ACK]);
8862             break;
8863
8864         default:
8865             trace("unexpected return: %04x\n", ret);
8866             assert(0);
8867             break;
8868         }
8869     }
8870     return 0;
8871 }
8872
8873 static void test_PeekMessage(void)
8874 {
8875     MSG msg;
8876     HANDLE hthread;
8877     DWORD tid, qstatus;
8878     UINT qs_all_input = QS_ALLINPUT;
8879     UINT qs_input = QS_INPUT;
8880     BOOL ret;
8881     struct peekmsg_info info;
8882
8883     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8884                               100, 100, 200, 200, 0, 0, 0, NULL);
8885     assert(info.hwnd);
8886     ShowWindow(info.hwnd, SW_SHOW);
8887     UpdateWindow(info.hwnd);
8888     SetFocus(info.hwnd);
8889
8890     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8891     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8892     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8893
8894     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8895     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8896
8897     flush_events();
8898     flush_sequence();
8899
8900     SetLastError(0xdeadbeef);
8901     qstatus = GetQueueStatus(qs_all_input);
8902     if (GetLastError() == ERROR_INVALID_FLAGS)
8903     {
8904         trace("QS_RAWINPUT not supported on this platform\n");
8905         qs_all_input &= ~QS_RAWINPUT;
8906         qs_input &= ~QS_RAWINPUT;
8907     }
8908     if (qstatus & QS_POSTMESSAGE)
8909     {
8910         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8911         qstatus = GetQueueStatus(qs_all_input);
8912     }
8913     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8914
8915     trace("signalling to send message\n");
8916     SetEvent(info.hevent[EV_SENDMSG]);
8917     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8918
8919     /* pass invalid QS_xxxx flags */
8920     SetLastError(0xdeadbeef);
8921     qstatus = GetQueueStatus(0xffffffff);
8922     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8923     if (!qstatus)
8924     {
8925         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8926         qstatus = GetQueueStatus(qs_all_input);
8927     }
8928     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8929        "wrong qstatus %08x\n", qstatus);
8930
8931     msg.message = 0;
8932     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8933     ok(!ret,
8934        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8935         msg.message);
8936     ok_sequence(WmUser, "WmUser", FALSE);
8937
8938     qstatus = GetQueueStatus(qs_all_input);
8939     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8940
8941     keybd_event('N', 0, 0, 0);
8942     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8943     qstatus = GetQueueStatus(qs_all_input);
8944     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8945        "wrong qstatus %08x\n", qstatus);
8946
8947     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8948     qstatus = GetQueueStatus(qs_all_input);
8949     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8950        "wrong qstatus %08x\n", qstatus);
8951
8952     InvalidateRect(info.hwnd, NULL, FALSE);
8953     qstatus = GetQueueStatus(qs_all_input);
8954     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8955        "wrong qstatus %08x\n", qstatus);
8956
8957     trace("signalling to send message\n");
8958     SetEvent(info.hevent[EV_SENDMSG]);
8959     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8960
8961     qstatus = GetQueueStatus(qs_all_input);
8962     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8963        "wrong qstatus %08x\n", qstatus);
8964
8965     msg.message = 0;
8966     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8967     if (ret && msg.message == WM_CHAR)
8968     {
8969         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8970         goto done;
8971     }
8972     ok(!ret,
8973        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8974         msg.message);
8975     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
8976     {
8977         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8978         goto done;
8979     }
8980     ok_sequence(WmUser, "WmUser", FALSE);
8981
8982     qstatus = GetQueueStatus(qs_all_input);
8983     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8984        "wrong qstatus %08x\n", qstatus);
8985
8986     trace("signalling to send message\n");
8987     SetEvent(info.hevent[EV_SENDMSG]);
8988     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8989
8990     qstatus = GetQueueStatus(qs_all_input);
8991     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8992        "wrong qstatus %08x\n", qstatus);
8993
8994     msg.message = 0;
8995     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
8996     ok(!ret,
8997        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8998         msg.message);
8999     ok_sequence(WmUser, "WmUser", FALSE);
9000
9001     qstatus = GetQueueStatus(qs_all_input);
9002     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9003        "wrong qstatus %08x\n", qstatus);
9004
9005     msg.message = 0;
9006     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9007     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9008        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9009        ret, msg.message, msg.wParam);
9010     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9011
9012     qstatus = GetQueueStatus(qs_all_input);
9013     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9014        "wrong qstatus %08x\n", qstatus);
9015
9016     msg.message = 0;
9017     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9018     ok(!ret,
9019        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9020         msg.message);
9021     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9022
9023     qstatus = GetQueueStatus(qs_all_input);
9024     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9025        "wrong qstatus %08x\n", qstatus);
9026
9027     msg.message = 0;
9028     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9029     ok(ret && msg.message == WM_PAINT,
9030        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9031     DispatchMessageA(&msg);
9032     ok_sequence(WmPaint, "WmPaint", FALSE);
9033
9034     qstatus = GetQueueStatus(qs_all_input);
9035     ok(qstatus == MAKELONG(0, QS_KEY),
9036        "wrong qstatus %08x\n", qstatus);
9037
9038     msg.message = 0;
9039     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9040     ok(!ret,
9041        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9042         msg.message);
9043     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9044
9045     qstatus = GetQueueStatus(qs_all_input);
9046     ok(qstatus == MAKELONG(0, QS_KEY),
9047        "wrong qstatus %08x\n", qstatus);
9048
9049     trace("signalling to send message\n");
9050     SetEvent(info.hevent[EV_SENDMSG]);
9051     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9052
9053     qstatus = GetQueueStatus(qs_all_input);
9054     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|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_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9061        "wrong qstatus %08x\n", qstatus);
9062
9063     msg.message = 0;
9064     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9065     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9066        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9067        ret, msg.message, msg.wParam);
9068     ok_sequence(WmUser, "WmUser", FALSE);
9069
9070     qstatus = GetQueueStatus(qs_all_input);
9071     ok(qstatus == MAKELONG(0, QS_KEY),
9072        "wrong qstatus %08x\n", qstatus);
9073
9074     msg.message = 0;
9075     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9076     ok(!ret,
9077        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9078         msg.message);
9079     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9080
9081     qstatus = GetQueueStatus(qs_all_input);
9082     ok(qstatus == MAKELONG(0, QS_KEY),
9083        "wrong qstatus %08x\n", qstatus);
9084
9085     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9086
9087     qstatus = GetQueueStatus(qs_all_input);
9088     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9089        "wrong qstatus %08x\n", qstatus);
9090
9091     trace("signalling to send message\n");
9092     SetEvent(info.hevent[EV_SENDMSG]);
9093     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9094
9095     qstatus = GetQueueStatus(qs_all_input);
9096     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9097        "wrong qstatus %08x\n", qstatus);
9098
9099     msg.message = 0;
9100     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9101     ok(!ret,
9102        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9103         msg.message);
9104     ok_sequence(WmUser, "WmUser", FALSE);
9105
9106     qstatus = GetQueueStatus(qs_all_input);
9107     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9108        "wrong qstatus %08x\n", qstatus);
9109
9110     msg.message = 0;
9111     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9112         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9113     else /* workaround for a missing QS_RAWINPUT support */
9114         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9115     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9116        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9117        ret, msg.message, msg.wParam);
9118     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9119
9120     qstatus = GetQueueStatus(qs_all_input);
9121     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9122        "wrong qstatus %08x\n", qstatus);
9123
9124     msg.message = 0;
9125     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9126         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9127     else /* workaround for a missing QS_RAWINPUT support */
9128         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9129     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9130        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9131        ret, msg.message, msg.wParam);
9132     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9133
9134     qstatus = GetQueueStatus(qs_all_input);
9135     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9136        "wrong qstatus %08x\n", qstatus);
9137
9138     msg.message = 0;
9139     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9140     ok(!ret,
9141        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9142         msg.message);
9143     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9144
9145     qstatus = GetQueueStatus(qs_all_input);
9146     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9147        "wrong qstatus %08x\n", qstatus);
9148
9149     msg.message = 0;
9150     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9151     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9152        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9153        ret, msg.message, msg.wParam);
9154     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9155
9156     qstatus = GetQueueStatus(qs_all_input);
9157     ok(qstatus == 0,
9158        "wrong qstatus %08x\n", qstatus);
9159
9160     msg.message = 0;
9161     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9162     ok(!ret,
9163        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9164         msg.message);
9165     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9166
9167     qstatus = GetQueueStatus(qs_all_input);
9168     ok(qstatus == 0,
9169        "wrong qstatus %08x\n", qstatus);
9170
9171     /* test whether presence of the quit flag in the queue affects
9172      * the queue state
9173      */
9174     PostQuitMessage(0x1234abcd);
9175
9176     qstatus = GetQueueStatus(qs_all_input);
9177     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9178        "wrong qstatus %08x\n", qstatus);
9179
9180     PostMessageA(info.hwnd, WM_USER, 0, 0);
9181
9182     qstatus = GetQueueStatus(qs_all_input);
9183     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9184        "wrong qstatus %08x\n", qstatus);
9185
9186     msg.message = 0;
9187     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9188     ok(ret && msg.message == WM_USER,
9189        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9190     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9191
9192     qstatus = GetQueueStatus(qs_all_input);
9193     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9194        "wrong qstatus %08x\n", qstatus);
9195
9196     msg.message = 0;
9197     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9198     ok(ret && msg.message == WM_QUIT,
9199        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9200     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9201     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9202     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9203
9204     qstatus = GetQueueStatus(qs_all_input);
9205 todo_wine {
9206     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9207        "wrong qstatus %08x\n", qstatus);
9208 }
9209
9210     msg.message = 0;
9211     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9212     ok(!ret,
9213        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9214         msg.message);
9215     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9216
9217     qstatus = GetQueueStatus(qs_all_input);
9218     ok(qstatus == 0,
9219        "wrong qstatus %08x\n", qstatus);
9220
9221     /* some GetMessage tests */
9222
9223     keybd_event('N', 0, 0, 0);
9224     qstatus = GetQueueStatus(qs_all_input);
9225     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9226
9227     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9228     qstatus = GetQueueStatus(qs_all_input);
9229     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9230
9231     if (qstatus)
9232     {
9233         ret = GetMessageA( &msg, 0, 0, 0 );
9234         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9235            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9236            ret, msg.message, msg.wParam);
9237         qstatus = GetQueueStatus(qs_all_input);
9238         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9239     }
9240
9241     if (qstatus)
9242     {
9243         ret = GetMessageA( &msg, 0, 0, 0 );
9244         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9245            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9246            ret, msg.message, msg.wParam);
9247         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9248         qstatus = GetQueueStatus(qs_all_input);
9249         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9250     }
9251
9252     keybd_event('N', 0, 0, 0);
9253     qstatus = GetQueueStatus(qs_all_input);
9254     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9255
9256     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9257     qstatus = GetQueueStatus(qs_all_input);
9258     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9259
9260     if (qstatus & (QS_KEY << 16))
9261     {
9262         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9263         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9264            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9265            ret, msg.message, msg.wParam);
9266         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9267         qstatus = GetQueueStatus(qs_all_input);
9268         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9269     }
9270
9271     if (qstatus)
9272     {
9273         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9274         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9275            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9276            ret, msg.message, msg.wParam);
9277         qstatus = GetQueueStatus(qs_all_input);
9278         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9279     }
9280
9281     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9282     qstatus = GetQueueStatus(qs_all_input);
9283     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9284
9285     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9286     qstatus = GetQueueStatus(qs_all_input);
9287     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9288
9289     trace("signalling to send message\n");
9290     SetEvent(info.hevent[EV_SENDMSG]);
9291     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9292     qstatus = GetQueueStatus(qs_all_input);
9293     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9294        "wrong qstatus %08x\n", qstatus);
9295
9296     if (qstatus & (QS_KEY << 16))
9297     {
9298         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9299         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9300            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9301            ret, msg.message, msg.wParam);
9302         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9303         qstatus = GetQueueStatus(qs_all_input);
9304         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9305     }
9306
9307     if (qstatus)
9308     {
9309         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9310         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9311            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9312            ret, msg.message, msg.wParam);
9313         qstatus = GetQueueStatus(qs_all_input);
9314         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9315     }
9316 done:
9317     trace("signalling to exit\n");
9318     SetEvent(info.hevent[EV_STOP]);
9319
9320     WaitForSingleObject(hthread, INFINITE);
9321
9322     CloseHandle(hthread);
9323     CloseHandle(info.hevent[0]);
9324     CloseHandle(info.hevent[1]);
9325     CloseHandle(info.hevent[2]);
9326
9327     DestroyWindow(info.hwnd);
9328 }
9329
9330 static void wait_move_event(HWND hwnd, int x, int y)
9331 {
9332     MSG msg;
9333     DWORD time;
9334     BOOL  ret;
9335     int go = 0;
9336
9337     time = GetTickCount();
9338     while (GetTickCount() - time < 200 && !go) {
9339         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9340         go  = ret && msg.pt.x > x && msg.pt.y > y;
9341         if (ret && !go) PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9342     }
9343 }
9344
9345 #define STEP 20
9346 static void test_PeekMessage2(void)
9347 {
9348     HWND hwnd;
9349     BOOL ret;
9350     MSG msg;
9351     UINT message;
9352     DWORD time1, time2, time3;
9353     int x1, y1, x2, y2, x3, y3;
9354     POINT pos;
9355
9356     time1 = time2 = time3 = 0;
9357     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9358
9359     /* Initialise window and make sure it is ready for events */
9360     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9361                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9362     assert(hwnd);
9363     trace("Window for test_PeekMessage2 %p\n", hwnd);
9364     ShowWindow(hwnd, SW_SHOW);
9365     UpdateWindow(hwnd);
9366     SetFocus(hwnd);
9367     GetCursorPos(&pos);
9368     SetCursorPos(100, 100);
9369     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9370     flush_events();
9371
9372     /* Do initial mousemove, wait until we can see it
9373        and then do our test peek with PM_NOREMOVE. */
9374     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9375     wait_move_event(hwnd, 80, 80);
9376
9377     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9378     ok(ret, "no message available\n");
9379     if (ret) {
9380         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9381         message = msg.message;
9382         time1 = msg.time;
9383         x1 = msg.pt.x;
9384         y1 = msg.pt.y;
9385         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9386         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9387     }
9388
9389     /* Allow time to advance a bit, and then simulate the user moving their
9390      * mouse around. After that we peek again with PM_NOREMOVE.
9391      * Although the previous mousemove message was never removed, the
9392      * mousemove we now peek should reflect the recent mouse movements
9393      * because the input queue will merge the move events. */
9394     Sleep(2);
9395     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9396     wait_move_event(hwnd, x1, y1);
9397
9398     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9399     ok(ret, "no message available\n");
9400     if (ret) {
9401         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9402         message = msg.message;
9403         time2 = msg.time;
9404         x2 = msg.pt.x;
9405         y2 = msg.pt.y;
9406         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9407         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9408         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9409         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9410     }
9411
9412     /* Have another go, to drive the point home */
9413     Sleep(2);
9414     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9415     wait_move_event(hwnd, x2, y2);
9416
9417     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9418     ok(ret, "no message available\n");
9419     if (ret) {
9420         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9421         message = msg.message;
9422         time3 = msg.time;
9423         x3 = msg.pt.x;
9424         y3 = msg.pt.y;
9425         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9426         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9427         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9428     }
9429
9430     DestroyWindow(hwnd);
9431     SetCursorPos(pos.x, pos.y);
9432     flush_events();
9433 }
9434
9435 static void test_quit_message(void)
9436 {
9437     MSG msg;
9438     BOOL ret;
9439
9440     /* test using PostQuitMessage */
9441     flush_events();
9442     PostQuitMessage(0xbeef);
9443
9444     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9445     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9446     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9447     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9448
9449     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9450     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9451
9452     ret = GetMessage(&msg, NULL, 0, 0);
9453     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9454     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9455
9456     /* note: WM_QUIT message received after WM_USER message */
9457     ret = GetMessage(&msg, NULL, 0, 0);
9458     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9459     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9460     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9461
9462     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9463     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9464
9465     /* now test with PostThreadMessage - different behaviour! */
9466     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9467
9468     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9469     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9470     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9471     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9472
9473     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9474     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9475
9476     /* note: we receive the WM_QUIT message first this time */
9477     ret = GetMessage(&msg, NULL, 0, 0);
9478     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9479     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9480     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9481
9482     ret = GetMessage(&msg, NULL, 0, 0);
9483     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9484     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9485 }
9486
9487 static const struct message WmMouseHoverSeq[] = {
9488     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9489     { WM_MOUSEACTIVATE, sent|optional },
9490     { WM_TIMER, sent|optional }, /* XP sends it */
9491     { WM_SYSTIMER, sent },
9492     { WM_MOUSEHOVER, sent|wparam, 0 },
9493     { 0 }
9494 };
9495
9496 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9497 {
9498     MSG msg;
9499     DWORD start_ticks, end_ticks;
9500
9501     start_ticks = GetTickCount();
9502     /* add some deviation (50%) to cover not expected delays */
9503     start_ticks += timeout / 2;
9504
9505     do
9506     {
9507         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9508         {
9509             /* Timer proc messages are not dispatched to the window proc,
9510              * and therefore not logged.
9511              */
9512             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9513             {
9514                 struct recvd_message s_msg;
9515
9516                 s_msg.hwnd = msg.hwnd;
9517                 s_msg.message = msg.message;
9518                 s_msg.flags = sent|wparam|lparam;
9519                 s_msg.wParam = msg.wParam;
9520                 s_msg.lParam = msg.lParam;
9521                 s_msg.descr = "msg_loop";
9522                 add_message(&s_msg);
9523             }
9524             DispatchMessage(&msg);
9525         }
9526
9527         end_ticks = GetTickCount();
9528
9529         /* inject WM_MOUSEMOVE to see how it changes tracking */
9530         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9531         {
9532             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9533             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9534
9535             inject_mouse_move = FALSE;
9536         }
9537     } while (start_ticks + timeout >= end_ticks);
9538 }
9539
9540 static void test_TrackMouseEvent(void)
9541 {
9542     TRACKMOUSEEVENT tme;
9543     BOOL ret;
9544     HWND hwnd, hchild;
9545     RECT rc_parent, rc_child;
9546     UINT default_hover_time, hover_width = 0, hover_height = 0;
9547
9548 #define track_hover(track_hwnd, track_hover_time) \
9549     tme.cbSize = sizeof(tme); \
9550     tme.dwFlags = TME_HOVER; \
9551     tme.hwndTrack = track_hwnd; \
9552     tme.dwHoverTime = track_hover_time; \
9553     SetLastError(0xdeadbeef); \
9554     ret = pTrackMouseEvent(&tme); \
9555     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9556
9557 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9558     tme.cbSize = sizeof(tme); \
9559     tme.dwFlags = TME_QUERY; \
9560     tme.hwndTrack = (HWND)0xdeadbeef; \
9561     tme.dwHoverTime = 0xdeadbeef; \
9562     SetLastError(0xdeadbeef); \
9563     ret = pTrackMouseEvent(&tme); \
9564     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9565     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9566     ok(tme.dwFlags == (expected_track_flags), \
9567        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9568     ok(tme.hwndTrack == (expected_track_hwnd), \
9569        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9570     ok(tme.dwHoverTime == (expected_hover_time), \
9571        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9572
9573 #define track_hover_cancel(track_hwnd) \
9574     tme.cbSize = sizeof(tme); \
9575     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9576     tme.hwndTrack = track_hwnd; \
9577     tme.dwHoverTime = 0xdeadbeef; \
9578     SetLastError(0xdeadbeef); \
9579     ret = pTrackMouseEvent(&tme); \
9580     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9581
9582     default_hover_time = 0xdeadbeef;
9583     SetLastError(0xdeadbeef);
9584     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9585     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9586        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9587     if (!ret) default_hover_time = 400;
9588     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9589
9590     SetLastError(0xdeadbeef);
9591     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9592     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9593        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9594     if (!ret) hover_width = 4;
9595     SetLastError(0xdeadbeef);
9596     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9597     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9598        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9599     if (!ret) hover_height = 4;
9600     trace("hover rect is %u x %d\n", hover_width, hover_height);
9601
9602     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9603                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9604                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9605                           NULL, NULL, 0);
9606     assert(hwnd);
9607
9608     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9609                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9610                           50, 50, 200, 200, hwnd,
9611                           NULL, NULL, 0);
9612     assert(hchild);
9613
9614     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9615     flush_events();
9616     flush_sequence();
9617
9618     tme.cbSize = 0;
9619     tme.dwFlags = TME_QUERY;
9620     tme.hwndTrack = (HWND)0xdeadbeef;
9621     tme.dwHoverTime = 0xdeadbeef;
9622     SetLastError(0xdeadbeef);
9623     ret = pTrackMouseEvent(&tme);
9624     ok(!ret, "TrackMouseEvent should fail\n");
9625     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9626        "not expected error %u\n", GetLastError());
9627
9628     tme.cbSize = sizeof(tme);
9629     tme.dwFlags = TME_HOVER;
9630     tme.hwndTrack = (HWND)0xdeadbeef;
9631     tme.dwHoverTime = 0xdeadbeef;
9632     SetLastError(0xdeadbeef);
9633     ret = pTrackMouseEvent(&tme);
9634     ok(!ret, "TrackMouseEvent should fail\n");
9635     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9636        "not expected error %u\n", GetLastError());
9637
9638     tme.cbSize = sizeof(tme);
9639     tme.dwFlags = TME_HOVER | TME_CANCEL;
9640     tme.hwndTrack = (HWND)0xdeadbeef;
9641     tme.dwHoverTime = 0xdeadbeef;
9642     SetLastError(0xdeadbeef);
9643     ret = pTrackMouseEvent(&tme);
9644     ok(!ret, "TrackMouseEvent should fail\n");
9645     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9646        "not expected error %u\n", GetLastError());
9647
9648     GetWindowRect(hwnd, &rc_parent);
9649     GetWindowRect(hchild, &rc_child);
9650     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9651
9652     /* Process messages so that the system updates its internal current
9653      * window and hittest, otherwise TrackMouseEvent calls don't have any
9654      * effect.
9655      */
9656     flush_events();
9657     flush_sequence();
9658
9659     track_query(0, NULL, 0);
9660     track_hover(hchild, 0);
9661     track_query(0, NULL, 0);
9662
9663     flush_events();
9664     flush_sequence();
9665
9666     track_hover(hwnd, 0);
9667     tme.cbSize = sizeof(tme);
9668     tme.dwFlags = TME_QUERY;
9669     tme.hwndTrack = (HWND)0xdeadbeef;
9670     tme.dwHoverTime = 0xdeadbeef;
9671     SetLastError(0xdeadbeef);
9672     ret = pTrackMouseEvent(&tme);
9673     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9674     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9675     if (!tme.dwFlags)
9676     {
9677         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9678         DestroyWindow( hwnd );
9679         return;
9680     }
9681     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9682     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9683     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9684        tme.dwHoverTime, default_hover_time);
9685
9686     pump_msg_loop_timeout(default_hover_time, FALSE);
9687     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9688
9689     track_query(0, NULL, 0);
9690
9691     track_hover(hwnd, HOVER_DEFAULT);
9692     track_query(TME_HOVER, hwnd, default_hover_time);
9693
9694     Sleep(default_hover_time / 2);
9695     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9696     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9697
9698     track_query(TME_HOVER, hwnd, default_hover_time);
9699
9700     pump_msg_loop_timeout(default_hover_time, FALSE);
9701     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9702
9703     track_query(0, NULL, 0);
9704
9705     track_hover(hwnd, HOVER_DEFAULT);
9706     track_query(TME_HOVER, hwnd, default_hover_time);
9707
9708     pump_msg_loop_timeout(default_hover_time, TRUE);
9709     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9710
9711     track_query(0, NULL, 0);
9712
9713     track_hover(hwnd, HOVER_DEFAULT);
9714     track_query(TME_HOVER, hwnd, default_hover_time);
9715     track_hover_cancel(hwnd);
9716
9717     DestroyWindow(hwnd);
9718
9719 #undef track_hover
9720 #undef track_query
9721 #undef track_hover_cancel
9722 }
9723
9724
9725 static const struct message WmSetWindowRgn[] = {
9726     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9727     { WM_NCCALCSIZE, sent|wparam, 1 },
9728     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9729     { WM_GETTEXT, sent|defwinproc|optional },
9730     { WM_ERASEBKGND, sent|optional },
9731     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9732     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9733     { 0 }
9734 };
9735
9736 static const struct message WmSetWindowRgn_no_redraw[] = {
9737     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9738     { WM_NCCALCSIZE, sent|wparam, 1 },
9739     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9740     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9741     { 0 }
9742 };
9743
9744 static const struct message WmSetWindowRgn_clear[] = {
9745     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9746     { WM_NCCALCSIZE, sent|wparam, 1 },
9747     { WM_NCPAINT, sent|optional },
9748     { WM_GETTEXT, sent|defwinproc|optional },
9749     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9750     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9751     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9752     { WM_NCPAINT, sent|optional },
9753     { WM_GETTEXT, sent|defwinproc|optional },
9754     { WM_ERASEBKGND, sent|optional },
9755     { WM_WINDOWPOSCHANGING, sent|optional },
9756     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9757     { WM_NCPAINT, sent|optional },
9758     { WM_GETTEXT, sent|defwinproc|optional },
9759     { WM_ERASEBKGND, sent|optional },
9760     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9761     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9762     { WM_NCPAINT, sent|optional },
9763     { WM_GETTEXT, sent|defwinproc|optional },
9764     { WM_ERASEBKGND, sent|optional },
9765     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9766     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9767     { 0 }
9768 };
9769
9770 static void test_SetWindowRgn(void)
9771 {
9772     HRGN hrgn;
9773     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9774                                 100, 100, 200, 200, 0, 0, 0, NULL);
9775     ok( hwnd != 0, "Failed to create overlapped window\n" );
9776
9777     ShowWindow( hwnd, SW_SHOW );
9778     UpdateWindow( hwnd );
9779     flush_events();
9780     flush_sequence();
9781
9782     trace("testing SetWindowRgn\n");
9783     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9784     SetWindowRgn( hwnd, hrgn, TRUE );
9785     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9786
9787     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9788     SetWindowRgn( hwnd, hrgn, FALSE );
9789     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9790
9791     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9792     SetWindowRgn( hwnd, hrgn, TRUE );
9793     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9794
9795     SetWindowRgn( hwnd, 0, TRUE );
9796     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9797
9798     DestroyWindow( hwnd );
9799 }
9800
9801 /*************************** ShowWindow() test ******************************/
9802 static const struct message WmShowNormal[] = {
9803     { WM_SHOWWINDOW, sent|wparam, 1 },
9804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9805     { HCBT_ACTIVATE, hook },
9806     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9807     { HCBT_SETFOCUS, hook },
9808     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9809     { 0 }
9810 };
9811 static const struct message WmShow[] = {
9812     { WM_SHOWWINDOW, sent|wparam, 1 },
9813     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9814     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9815     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9816     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9817     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9818     { 0 }
9819 };
9820 static const struct message WmShowNoActivate_1[] = {
9821     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9822     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9823     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9824     { WM_MOVE, sent|defwinproc|optional },
9825     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9826     { 0 }
9827 };
9828 static const struct message WmShowNoActivate_2[] = {
9829     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9830     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9831     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9832     { WM_MOVE, sent|defwinproc },
9833     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9834     { HCBT_SETFOCUS, hook|optional },
9835     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9836     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9837     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9838     { 0 }
9839 };
9840 static const struct message WmShowNA_1[] = {
9841     { WM_SHOWWINDOW, sent|wparam, 1 },
9842     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9843     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9844     { 0 }
9845 };
9846 static const struct message WmShowNA_2[] = {
9847     { WM_SHOWWINDOW, sent|wparam, 1 },
9848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9849     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9850     { 0 }
9851 };
9852 static const struct message WmRestore_1[] = {
9853     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9854     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9855     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9856     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9857     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9858     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9859     { WM_MOVE, sent|defwinproc },
9860     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9861     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9862     { 0 }
9863 };
9864 static const struct message WmRestore_2[] = {
9865     { WM_SHOWWINDOW, sent|wparam, 1 },
9866     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9867     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9868     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9869     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9870     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9871     { 0 }
9872 };
9873 static const struct message WmRestore_3[] = {
9874     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9875     { WM_GETMINMAXINFO, sent },
9876     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9877     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9878     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9879     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9880     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9881     { WM_MOVE, sent|defwinproc },
9882     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9883     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9884     { 0 }
9885 };
9886 static const struct message WmRestore_4[] = {
9887     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9888     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9889     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9890     { WM_MOVE, sent|defwinproc|optional },
9891     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9892     { 0 }
9893 };
9894 static const struct message WmRestore_5[] = {
9895     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9896     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9897     { HCBT_ACTIVATE, hook|optional },
9898     { HCBT_SETFOCUS, hook|optional },
9899     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9900     { WM_MOVE, sent|defwinproc|optional },
9901     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9902     { 0 }
9903 };
9904 static const struct message WmHide_1[] = {
9905     { WM_SHOWWINDOW, sent|wparam, 0 },
9906     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9907     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9908     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9909     { 0 }
9910 };
9911 static const struct message WmHide_2[] = {
9912     { WM_SHOWWINDOW, sent|wparam, 0 },
9913     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9914     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9915     { 0 }
9916 };
9917 static const struct message WmHide_3[] = {
9918     { WM_SHOWWINDOW, sent|wparam, 0 },
9919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9920     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9921     { HCBT_SETFOCUS, hook|optional },
9922     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9923     { 0 }
9924 };
9925 static const struct message WmShowMinimized_1[] = {
9926     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9927     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9928     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9929     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9930     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9931     { WM_MOVE, sent|defwinproc },
9932     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9933     { 0 }
9934 };
9935 static const struct message WmMinimize_1[] = {
9936     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9937     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9938     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9940     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9941     { WM_MOVE, sent|defwinproc },
9942     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9943     { 0 }
9944 };
9945 static const struct message WmMinimize_2[] = {
9946     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9947     { HCBT_SETFOCUS, hook|optional },
9948     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9949     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9950     { WM_MOVE, sent|defwinproc },
9951     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9952     { 0 }
9953 };
9954 static const struct message WmMinimize_3[] = {
9955     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9957     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9958     { WM_MOVE, sent|defwinproc },
9959     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9960     { 0 }
9961 };
9962 static const struct message WmShowMinNoActivate[] = {
9963     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9964     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9965     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9966     { 0 }
9967 };
9968 static const struct message WmMinMax_1[] = {
9969     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9970     { 0 }
9971 };
9972 static const struct message WmMinMax_2[] = {
9973     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9974     { WM_GETMINMAXINFO, sent|optional },
9975     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
9976     { HCBT_ACTIVATE, hook|optional },
9977     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
9978     { HCBT_SETFOCUS, hook|optional },
9979     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9980     { WM_MOVE, sent|defwinproc|optional },
9981     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
9982     { HCBT_SETFOCUS, hook|optional },
9983     { 0 }
9984 };
9985 static const struct message WmMinMax_3[] = {
9986     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9987     { 0 }
9988 };
9989 static const struct message WmMinMax_4[] = {
9990     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9991     { 0 }
9992 };
9993 static const struct message WmShowMaximized_1[] = {
9994     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9995     { WM_GETMINMAXINFO, sent },
9996     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9997     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9998     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9999     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10000     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10001     { WM_MOVE, sent|defwinproc },
10002     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10003     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10004     { 0 }
10005 };
10006 static const struct message WmShowMaximized_2[] = {
10007     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10008     { WM_GETMINMAXINFO, sent },
10009     { WM_WINDOWPOSCHANGING, sent|optional },
10010     { HCBT_ACTIVATE, hook|optional },
10011     { WM_WINDOWPOSCHANGED, sent|optional },
10012     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10013     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10014     { WM_WINDOWPOSCHANGING, sent },
10015     { HCBT_SETFOCUS, hook|optional },
10016     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10017     { WM_MOVE, sent|defwinproc },
10018     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10019     { HCBT_SETFOCUS, hook|optional },
10020     { 0 }
10021 };
10022 static const struct message WmShowMaximized_3[] = {
10023     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10024     { WM_GETMINMAXINFO, sent },
10025     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10026     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10027     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10028     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10029     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10030     { WM_MOVE, sent|defwinproc|optional },
10031     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10032     { 0 }
10033 };
10034
10035 static void test_ShowWindow(void)
10036 {
10037     /* ShowWindow commands in random order */
10038     static const struct
10039     {
10040         INT cmd; /* ShowWindow command */
10041         LPARAM ret; /* ShowWindow return value */
10042         DWORD style; /* window style after the command */
10043         const struct message *msg; /* message sequence the command produces */
10044         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10045     } sw[] =
10046     {
10047 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10048 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10049 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10050 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10051 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10052 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10053 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10054 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10055 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10056 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10057 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10058 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10059 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10060 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10061 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10062 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10063 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10064 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10065 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10066 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10067 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10068 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10069 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10070 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10071 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10072 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10073 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10074 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10075 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10076 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10077 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10078 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10079 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10080 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10081 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10082 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10083 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10084 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10085 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10086 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10087 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10088 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
10089 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10090 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10091 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10092 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10093 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10094 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10095 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10096 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10097 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10098 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10099 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10100 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10101 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10102 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10103 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10104     };
10105     HWND hwnd;
10106     DWORD style;
10107     LPARAM ret;
10108     INT i;
10109
10110 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10111     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10112                           120, 120, 90, 90,
10113                           0, 0, 0, NULL);
10114     assert(hwnd);
10115
10116     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10117     ok(style == 0, "expected style 0, got %08x\n", style);
10118
10119     flush_events();
10120     flush_sequence();
10121
10122     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10123     {
10124         static const char * const sw_cmd_name[13] =
10125         {
10126             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10127             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10128             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10129             "SW_NORMALNA" /* 0xCC */
10130         };
10131         char comment[64];
10132         INT idx; /* index into the above array of names */
10133
10134         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10135
10136         style = GetWindowLong(hwnd, GWL_STYLE);
10137         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10138         ret = ShowWindow(hwnd, sw[i].cmd);
10139         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10140         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10141         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10142
10143         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10144         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10145
10146         flush_events();
10147         flush_sequence();
10148     }
10149
10150     DestroyWindow(hwnd);
10151 }
10152
10153 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10154 {
10155     struct recvd_message msg;
10156
10157     switch (message)
10158     {
10159     case WM_GETICON:
10160     case WM_GETOBJECT:
10161         return 0;  /* ignore them */
10162     }
10163
10164     msg.hwnd = hwnd;
10165     msg.message = message;
10166     msg.flags = sent|wparam|lparam;
10167     msg.wParam = wParam;
10168     msg.lParam = lParam;
10169     msg.descr = "dialog";
10170     add_message(&msg);
10171
10172     /* calling DefDlgProc leads to a recursion under XP */
10173
10174     switch (message)
10175     {
10176     case WM_INITDIALOG:
10177     case WM_GETDLGCODE:
10178         return 0;
10179     }
10180     return 1;
10181 }
10182
10183 static const struct message WmDefDlgSetFocus_1[] = {
10184     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10185     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10186     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10187     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10188     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10189     { HCBT_SETFOCUS, hook },
10190     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10191     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10192     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10193     { WM_SETFOCUS, sent|wparam, 0 },
10194     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10195     { WM_CTLCOLOREDIT, sent },
10196     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10197     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10198     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10199     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10200     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10201     { 0 }
10202 };
10203 static const struct message WmDefDlgSetFocus_2[] = {
10204     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10205     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10206     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10207     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10208     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10209     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10210     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10211     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10212     { 0 }
10213 };
10214 /* Creation of a dialog */
10215 static const struct message WmCreateDialogParamSeq_1[] = {
10216     { HCBT_CREATEWND, hook },
10217     { WM_NCCREATE, sent },
10218     { WM_NCCALCSIZE, sent|wparam, 0 },
10219     { WM_CREATE, sent },
10220     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10221     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10222     { WM_MOVE, sent },
10223     { WM_SETFONT, sent },
10224     { WM_INITDIALOG, sent },
10225     { WM_CHANGEUISTATE, sent|optional },
10226     { 0 }
10227 };
10228 /* Creation of a dialog */
10229 static const struct message WmCreateDialogParamSeq_2[] = {
10230     { HCBT_CREATEWND, hook },
10231     { WM_NCCREATE, sent },
10232     { WM_NCCALCSIZE, sent|wparam, 0 },
10233     { WM_CREATE, sent },
10234     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10235     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10236     { WM_MOVE, sent },
10237     { WM_CHANGEUISTATE, sent|optional },
10238     { 0 }
10239 };
10240
10241 static void test_dialog_messages(void)
10242 {
10243     WNDCLASS cls;
10244     HWND hdlg, hedit1, hedit2, hfocus;
10245     LRESULT ret;
10246
10247 #define set_selection(hctl, start, end) \
10248     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10249     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10250
10251 #define check_selection(hctl, start, end) \
10252     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10253     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10254
10255     subclass_edit();
10256
10257     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10258                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10259                           0, 0, 100, 100, 0, 0, 0, NULL);
10260     ok(hdlg != 0, "Failed to create custom dialog window\n");
10261
10262     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10263                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10264                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10265     ok(hedit1 != 0, "Failed to create edit control\n");
10266     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10267                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10268                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10269     ok(hedit2 != 0, "Failed to create edit control\n");
10270
10271     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10272     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10273
10274     hfocus = GetFocus();
10275     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10276
10277     SetFocus(hedit2);
10278     hfocus = GetFocus();
10279     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10280
10281     check_selection(hedit1, 0, 0);
10282     check_selection(hedit2, 0, 0);
10283
10284     set_selection(hedit2, 0, -1);
10285     check_selection(hedit2, 0, 3);
10286
10287     SetFocus(0);
10288     hfocus = GetFocus();
10289     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10290
10291     flush_sequence();
10292     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10293     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10294     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10295
10296     hfocus = GetFocus();
10297     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10298
10299     check_selection(hedit1, 0, 5);
10300     check_selection(hedit2, 0, 3);
10301
10302     flush_sequence();
10303     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10304     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10305     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10306
10307     hfocus = GetFocus();
10308     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10309
10310     check_selection(hedit1, 0, 5);
10311     check_selection(hedit2, 0, 3);
10312
10313     EndDialog(hdlg, 0);
10314     DestroyWindow(hedit1);
10315     DestroyWindow(hedit2);
10316     DestroyWindow(hdlg);
10317     flush_sequence();
10318
10319 #undef set_selection
10320 #undef check_selection
10321
10322     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10323     cls.lpszClassName = "MyDialogClass";
10324     cls.hInstance = GetModuleHandle(0);
10325     /* need a cast since a dlgproc is used as a wndproc */
10326     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10327     if (!RegisterClass(&cls)) assert(0);
10328
10329     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10330     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10331     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10332     EndDialog(hdlg, 0);
10333     DestroyWindow(hdlg);
10334     flush_sequence();
10335
10336     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10337     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10338     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10339     EndDialog(hdlg, 0);
10340     DestroyWindow(hdlg);
10341     flush_sequence();
10342
10343     UnregisterClass(cls.lpszClassName, cls.hInstance);
10344 }
10345
10346 static void test_nullCallback(void)
10347 {
10348     HWND hwnd;
10349
10350     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10351                            100, 100, 200, 200, 0, 0, 0, NULL);
10352     ok (hwnd != 0, "Failed to create overlapped window\n");
10353
10354     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10355     flush_events();
10356     DestroyWindow(hwnd);
10357 }
10358
10359 /* SetActiveWindow( 0 ) hwnd visible */
10360 static const struct message SetActiveWindowSeq0[] =
10361 {
10362     { HCBT_ACTIVATE, hook },
10363     { WM_NCACTIVATE, sent|wparam, 0 },
10364     { WM_GETTEXT, sent|defwinproc|optional },
10365     { WM_ACTIVATE, sent|wparam, 0 },
10366     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10367     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10368     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10369     { WM_NCACTIVATE, sent|wparam, 1 },
10370     { WM_GETTEXT, sent|defwinproc|optional },
10371     { WM_ACTIVATE, sent|wparam, 1 },
10372     { HCBT_SETFOCUS, hook },
10373     { WM_KILLFOCUS, sent|defwinproc },
10374     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10375     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10376     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10377     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10378     { WM_SETFOCUS, sent|defwinproc },
10379     { WM_GETTEXT, sent|optional },
10380     { 0 }
10381 };
10382 /* SetActiveWindow( hwnd ) hwnd visible */
10383 static const struct message SetActiveWindowSeq1[] =
10384 {
10385     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10386     { 0 }
10387 };
10388 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10389 static const struct message SetActiveWindowSeq2[] =
10390 {
10391     { HCBT_ACTIVATE, hook },
10392     { WM_NCACTIVATE, sent|wparam, 0 },
10393     { WM_GETTEXT, sent|defwinproc|optional },
10394     { WM_ACTIVATE, sent|wparam, 0 },
10395     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10396     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10397     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10398     { WM_NCPAINT, sent|optional },
10399     { WM_GETTEXT, sent|defwinproc|optional },
10400     { WM_ERASEBKGND, sent|optional },
10401     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10402     { WM_NCACTIVATE, sent|wparam, 1 },
10403     { WM_GETTEXT, sent|defwinproc|optional },
10404     { WM_ACTIVATE, sent|wparam, 1 },
10405     { HCBT_SETFOCUS, hook },
10406     { WM_KILLFOCUS, sent|defwinproc },
10407     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10408     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10409     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10410     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10411     { WM_SETFOCUS, sent|defwinproc },
10412     { WM_GETTEXT, sent|optional },
10413     { 0 }
10414 };
10415
10416 /* SetActiveWindow( hwnd ) hwnd not visible */
10417 static const struct message SetActiveWindowSeq3[] =
10418 {
10419     { HCBT_ACTIVATE, hook },
10420     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10421     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10422     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10423     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10424     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10425     { WM_ACTIVATEAPP, sent|wparam, 1 },
10426     { WM_ACTIVATEAPP, sent|wparam, 1 },
10427     { WM_NCACTIVATE, sent|wparam, 1 },
10428     { WM_ACTIVATE, sent|wparam, 1 },
10429     { HCBT_SETFOCUS, hook },
10430     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10431     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10432     { WM_SETFOCUS, sent|defwinproc },
10433     { 0 }
10434 };
10435 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10436 static const struct message SetActiveWindowSeq4[] =
10437 {
10438     { HCBT_ACTIVATE, hook },
10439     { WM_NCACTIVATE, sent|wparam, 0 },
10440     { WM_GETTEXT, sent|defwinproc|optional },
10441     { WM_ACTIVATE, sent|wparam, 0 },
10442     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10443     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10444     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10445     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10446     { WM_NCACTIVATE, sent|wparam, 1 },
10447     { WM_GETTEXT, sent|defwinproc|optional },
10448     { WM_ACTIVATE, sent|wparam, 1 },
10449     { HCBT_SETFOCUS, hook },
10450     { WM_KILLFOCUS, sent|defwinproc },
10451     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10452     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10453     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10454     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10455     { WM_SETFOCUS, sent|defwinproc },
10456     { 0 }
10457 };
10458
10459
10460 static void test_SetActiveWindow(void)
10461 {
10462     HWND hwnd, popup, ret;
10463
10464     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10465                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10466                            100, 100, 200, 200, 0, 0, 0, NULL);
10467
10468     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10469                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10470                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10471
10472     ok(hwnd != 0, "Failed to create overlapped window\n");
10473     ok(popup != 0, "Failed to create popup window\n");
10474     SetForegroundWindow( popup );
10475     flush_sequence();
10476
10477     trace("SetActiveWindow(0)\n");
10478     ret = SetActiveWindow(0);
10479     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10480     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10481     flush_sequence();
10482
10483     trace("SetActiveWindow(hwnd), hwnd visible\n");
10484     ret = SetActiveWindow(hwnd);
10485     todo_wine
10486     {
10487         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10488     }
10489     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10490     flush_sequence();
10491
10492     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10493     ret = SetActiveWindow(popup);
10494     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10495     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10496     flush_sequence();
10497
10498     ShowWindow(hwnd, SW_HIDE);
10499     ShowWindow(popup, SW_HIDE);
10500     flush_sequence();
10501
10502     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10503     ret = SetActiveWindow(hwnd);
10504     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10505     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10506     flush_sequence();
10507
10508     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10509     ret = SetActiveWindow(popup);
10510     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10511     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10512     flush_sequence();
10513
10514     trace("done\n");
10515
10516     DestroyWindow(hwnd);
10517 }
10518
10519 static const struct message SetForegroundWindowSeq[] =
10520 {
10521     { WM_NCACTIVATE, sent|wparam, 0 },
10522     { WM_GETTEXT, sent|defwinproc|optional },
10523     { WM_ACTIVATE, sent|wparam, 0 },
10524     { WM_ACTIVATEAPP, sent|wparam, 0 },
10525     { WM_KILLFOCUS, sent },
10526     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10527     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10528     { 0 }
10529 };
10530
10531 static void test_SetForegroundWindow(void)
10532 {
10533     HWND hwnd;
10534
10535     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10536                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10537                            100, 100, 200, 200, 0, 0, 0, NULL);
10538     ok (hwnd != 0, "Failed to create overlapped window\n");
10539     flush_sequence();
10540
10541     trace("SetForegroundWindow( 0 )\n");
10542     SetForegroundWindow( 0 );
10543     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10544     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10545     SetForegroundWindow( GetDesktopWindow() );
10546     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10547                                         "foreground top level window", FALSE);
10548     trace("done\n");
10549
10550     DestroyWindow(hwnd);
10551 }
10552
10553 static void test_dbcs_wm_char(void)
10554 {
10555     BYTE dbch[2];
10556     WCHAR wch, bad_wch;
10557     HWND hwnd, hwnd2;
10558     MSG msg;
10559     DWORD time;
10560     POINT pt;
10561     DWORD_PTR res;
10562     CPINFOEXA cpinfo;
10563     UINT i, j, k;
10564     struct message wmCharSeq[2];
10565
10566     if (!pGetCPInfoExA)
10567     {
10568         skip("GetCPInfoExA is not available\n");
10569         return;
10570     }
10571
10572     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10573     if (cpinfo.MaxCharSize != 2)
10574     {
10575         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10576         return;
10577     }
10578
10579     dbch[0] = dbch[1] = 0;
10580     wch = 0;
10581     bad_wch = cpinfo.UnicodeDefaultChar;
10582     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10583         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10584             for (k = 128; k <= 255; k++)
10585             {
10586                 char str[2];
10587                 WCHAR wstr[2];
10588                 str[0] = j;
10589                 str[1] = k;
10590                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10591                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10592                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10593                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10594                 {
10595                     dbch[0] = j;
10596                     dbch[1] = k;
10597                     wch = wstr[0];
10598                     break;
10599                 }
10600             }
10601
10602     if (!wch)
10603     {
10604         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10605         return;
10606     }
10607     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10608            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10609
10610     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10611                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10612     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10613                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10614     ok (hwnd != 0, "Failed to create overlapped window\n");
10615     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10616     flush_sequence();
10617
10618     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10619     wmCharSeq[0].message = WM_CHAR;
10620     wmCharSeq[0].flags = sent|wparam;
10621     wmCharSeq[0].wParam = wch;
10622
10623     /* posted message */
10624     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10625     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10626     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10627     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10628     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10629     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10630     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10631
10632     /* posted thread message */
10633     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10634     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10635     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10636     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10637     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10638     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10639     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10640
10641     /* sent message */
10642     flush_sequence();
10643     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10644     ok_sequence( WmEmptySeq, "no messages", FALSE );
10645     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10646     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10647     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10648
10649     /* sent message with timeout */
10650     flush_sequence();
10651     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10652     ok_sequence( WmEmptySeq, "no messages", FALSE );
10653     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10654     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10655     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10656
10657     /* sent message with timeout and callback */
10658     flush_sequence();
10659     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10660     ok_sequence( WmEmptySeq, "no messages", FALSE );
10661     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10662     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10663     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10664
10665     /* sent message with callback */
10666     flush_sequence();
10667     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10668     ok_sequence( WmEmptySeq, "no messages", FALSE );
10669     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10670     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10671     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10672
10673     /* direct window proc call */
10674     flush_sequence();
10675     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10676     ok_sequence( WmEmptySeq, "no messages", FALSE );
10677     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10678     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10679
10680     /* dispatch message */
10681     msg.hwnd = hwnd;
10682     msg.message = WM_CHAR;
10683     msg.wParam = dbch[0];
10684     msg.lParam = 0;
10685     DispatchMessageA( &msg );
10686     ok_sequence( WmEmptySeq, "no messages", FALSE );
10687     msg.wParam = dbch[1];
10688     DispatchMessageA( &msg );
10689     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10690
10691     /* window handle is irrelevant */
10692     flush_sequence();
10693     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10694     ok_sequence( WmEmptySeq, "no messages", FALSE );
10695     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10696     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10697     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10698
10699     /* interleaved post and send */
10700     flush_sequence();
10701     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10702     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10703     ok_sequence( WmEmptySeq, "no messages", FALSE );
10704     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10705     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10706     ok_sequence( WmEmptySeq, "no messages", FALSE );
10707     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10708     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10709     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10710     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10711     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10712     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10713     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10714
10715     /* interleaved sent message and winproc */
10716     flush_sequence();
10717     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10718     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10719     ok_sequence( WmEmptySeq, "no messages", FALSE );
10720     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10721     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10722     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10723     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10724
10725     /* interleaved winproc and dispatch */
10726     msg.hwnd = hwnd;
10727     msg.message = WM_CHAR;
10728     msg.wParam = dbch[0];
10729     msg.lParam = 0;
10730     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10731     DispatchMessageA( &msg );
10732     ok_sequence( WmEmptySeq, "no messages", FALSE );
10733     msg.wParam = dbch[1];
10734     DispatchMessageA( &msg );
10735     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10736     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10737     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10738
10739     /* interleaved sends */
10740     flush_sequence();
10741     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10742     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10743     ok_sequence( WmEmptySeq, "no messages", FALSE );
10744     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10745     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10746     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10747     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10748
10749     /* dbcs WM_CHAR */
10750     flush_sequence();
10751     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10752     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10753     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10754
10755     /* other char messages are not magic */
10756     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10757     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10758     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10759     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10760     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10761     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10762     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10763     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10764     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10765     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10766
10767     /* test retrieving messages */
10768
10769     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10770     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "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, hwnd, 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[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10778     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10779
10780     /* message filters */
10781     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10782     ok( PeekMessageA( &msg, hwnd, 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[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10786     /* message id is filtered, hwnd is not */
10787     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10788     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10789     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10790     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10791     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10792     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10793
10794     /* mixing GetMessage and PostMessage */
10795     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10796     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10797     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10798     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10799     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10800     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10801     time = msg.time;
10802     pt = msg.pt;
10803     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10804     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10805     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10806     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10807     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10808     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10809     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10810     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 );
10811     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10812
10813     /* without PM_REMOVE */
10814     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10815     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10816     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10817     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10818     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10819     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10820     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10821     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10822     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10823     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10824     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10825     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10826     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10827     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10828     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10829     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10830     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10831     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10832
10833     DestroyWindow(hwnd);
10834 }
10835
10836 #define ID_LISTBOX 0x000f
10837
10838 static const struct message wm_lb_setcursel_0[] =
10839 {
10840     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10841     { WM_CTLCOLORLISTBOX, sent|parent },
10842     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10843     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10844     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10845     { 0 }
10846 };
10847 static const struct message wm_lb_setcursel_1[] =
10848 {
10849     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10850     { WM_CTLCOLORLISTBOX, sent|parent },
10851     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10852     { WM_CTLCOLORLISTBOX, sent|parent },
10853     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10854     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10855     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10856     { 0 }
10857 };
10858 static const struct message wm_lb_setcursel_2[] =
10859 {
10860     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10861     { WM_CTLCOLORLISTBOX, sent|parent },
10862     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10863     { WM_CTLCOLORLISTBOX, sent|parent },
10864     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10865     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10866     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10867     { 0 }
10868 };
10869 static const struct message wm_lb_click_0[] =
10870 {
10871     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10872     { HCBT_SETFOCUS, hook },
10873     { WM_KILLFOCUS, sent|parent },
10874     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10875     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10876     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10877     { WM_SETFOCUS, sent|defwinproc },
10878
10879     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10880     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10881     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10882     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10883     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10884
10885     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10886     { WM_CTLCOLORLISTBOX, sent|parent },
10887     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10888     { WM_CTLCOLORLISTBOX, sent|parent },
10889     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10890     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10891
10892     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10893     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10894
10895     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10896     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10897     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10898     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10899     { 0 }
10900 };
10901
10902 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10903
10904 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10905
10906 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10907 {
10908     static long defwndproc_counter = 0;
10909     LRESULT ret;
10910     struct recvd_message msg;
10911
10912     /* do not log painting messages */
10913     if (message != WM_PAINT &&
10914         message != WM_NCPAINT &&
10915         message != WM_SYNCPAINT &&
10916         message != WM_ERASEBKGND &&
10917         message != WM_NCHITTEST &&
10918         message != WM_GETTEXT &&
10919         message != WM_GETOBJECT &&
10920         message != WM_GETICON &&
10921         message != WM_DEVICECHANGE)
10922     {
10923         msg.hwnd = hwnd;
10924         msg.message = message;
10925         msg.flags = sent|wparam|lparam;
10926         if (defwndproc_counter) msg.flags |= defwinproc;
10927         msg.wParam = wp;
10928         msg.lParam = lp;
10929         msg.descr = "listbox";
10930         add_message(&msg);
10931     }
10932
10933     defwndproc_counter++;
10934     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10935     defwndproc_counter--;
10936
10937     return ret;
10938 }
10939
10940 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10941                                int caret_index, int top_index, int line)
10942 {
10943     LRESULT ret;
10944
10945     /* calling an orig proc helps to avoid unnecessary message logging */
10946     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10947     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10948     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10949     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10950     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10951     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10952     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10953     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10954 }
10955
10956 static void test_listbox_messages(void)
10957 {
10958     HWND parent, listbox;
10959     LRESULT ret;
10960
10961     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10962                              100, 100, 200, 200, 0, 0, 0, NULL);
10963     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10964                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10965                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10966     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10967
10968     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10969
10970     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10971     ok(ret == 0, "expected 0, got %ld\n", ret);
10972     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10973     ok(ret == 1, "expected 1, got %ld\n", ret);
10974     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10975     ok(ret == 2, "expected 2, got %ld\n", ret);
10976
10977     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10978
10979     flush_sequence();
10980
10981     log_all_parent_messages++;
10982
10983     trace("selecting item 0\n");
10984     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10985     ok(ret == 0, "expected 0, got %ld\n", ret);
10986     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10987     check_lb_state(listbox, 3, 0, 0, 0);
10988     flush_sequence();
10989
10990     trace("selecting item 1\n");
10991     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10992     ok(ret == 1, "expected 1, got %ld\n", ret);
10993     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10994     check_lb_state(listbox, 3, 1, 1, 0);
10995
10996     trace("selecting item 2\n");
10997     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10998     ok(ret == 2, "expected 2, got %ld\n", ret);
10999     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11000     check_lb_state(listbox, 3, 2, 2, 0);
11001
11002     trace("clicking on item 0\n");
11003     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11004     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11005     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11006     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11007     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11008     check_lb_state(listbox, 3, 0, 0, 0);
11009     flush_sequence();
11010
11011     log_all_parent_messages--;
11012
11013     DestroyWindow(listbox);
11014     DestroyWindow(parent);
11015 }
11016
11017 /*************************** Menu test ******************************/
11018 static const struct message wm_popup_menu_1[] =
11019 {
11020     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11021     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11022     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11023     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11024     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11025     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11026     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11027     { WM_INITMENU, sent|lparam, 0, 0 },
11028     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11029     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11030     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11031     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11032     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11033     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11034     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11035     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11036     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11037     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11038     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11039     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11040     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11041     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11042     { 0 }
11043 };
11044 static const struct message wm_popup_menu_2[] =
11045 {
11046     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11047     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11048     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11049     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11050     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11051     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11052     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11053     { WM_INITMENU, sent|lparam, 0, 0 },
11054     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11055     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11056     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11057     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11058     { HCBT_CREATEWND, hook },
11059     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11060                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11061     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11062     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11063     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11064     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11065     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11066     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11067     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11068     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11069     { HCBT_DESTROYWND, hook },
11070     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11071     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11072     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11073     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11074     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11075     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11076     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11077     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11078     { 0 }
11079 };
11080 static const struct message wm_popup_menu_3[] =
11081 {
11082     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11083     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11084     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11085     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11086     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11087     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11088     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11089     { WM_INITMENU, sent|lparam, 0, 0 },
11090     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11091     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11092     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11093     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11094     { HCBT_CREATEWND, hook },
11095     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11096                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11097     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11098     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11099     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11100     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11101     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11102     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11103     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11104     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11105     { HCBT_DESTROYWND, hook },
11106     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11107     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11108     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11109     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11110     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11111     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11112     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11113     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11114     { 0 }
11115 };
11116
11117 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11118 {
11119     if (message == WM_ENTERIDLE ||
11120         message == WM_INITMENU ||
11121         message == WM_INITMENUPOPUP ||
11122         message == WM_MENUSELECT ||
11123         message == WM_PARENTNOTIFY ||
11124         message == WM_ENTERMENULOOP ||
11125         message == WM_EXITMENULOOP ||
11126         message == WM_UNINITMENUPOPUP ||
11127         message == WM_KEYDOWN ||
11128         message == WM_KEYUP ||
11129         message == WM_CHAR ||
11130         message == WM_SYSKEYDOWN ||
11131         message == WM_SYSKEYUP ||
11132         message == WM_SYSCHAR ||
11133         message == WM_COMMAND ||
11134         message == WM_MENUCOMMAND)
11135     {
11136         struct recvd_message msg;
11137
11138         msg.hwnd = hwnd;
11139         msg.message = message;
11140         msg.flags = sent|wparam|lparam;
11141         msg.wParam = wp;
11142         msg.lParam = lp;
11143         msg.descr = "parent_menu_proc";
11144         add_message(&msg);
11145     }
11146
11147     return DefWindowProcA(hwnd, message, wp, lp);
11148 }
11149
11150 static void set_menu_style(HMENU hmenu, DWORD style)
11151 {
11152     MENUINFO mi;
11153     BOOL ret;
11154
11155     mi.cbSize = sizeof(mi);
11156     mi.fMask = MIM_STYLE;
11157     mi.dwStyle = style;
11158     SetLastError(0xdeadbeef);
11159     ret = pSetMenuInfo(hmenu, &mi);
11160     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11161 }
11162
11163 static DWORD get_menu_style(HMENU hmenu)
11164 {
11165     MENUINFO mi;
11166     BOOL ret;
11167
11168     mi.cbSize = sizeof(mi);
11169     mi.fMask = MIM_STYLE;
11170     mi.dwStyle = 0;
11171     SetLastError(0xdeadbeef);
11172     ret = pGetMenuInfo(hmenu, &mi);
11173     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11174
11175     return mi.dwStyle;
11176 }
11177
11178 static void test_menu_messages(void)
11179 {
11180     MSG msg;
11181     WNDCLASSA cls;
11182     HMENU hmenu, hmenu_popup;
11183     HWND hwnd;
11184     DWORD style;
11185
11186     if (!pGetMenuInfo || !pSetMenuInfo)
11187     {
11188         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11189         return;
11190     }
11191     cls.style = 0;
11192     cls.lpfnWndProc = parent_menu_proc;
11193     cls.cbClsExtra = 0;
11194     cls.cbWndExtra = 0;
11195     cls.hInstance = GetModuleHandleA(0);
11196     cls.hIcon = 0;
11197     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11198     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11199     cls.lpszMenuName = NULL;
11200     cls.lpszClassName = "TestMenuClass";
11201     UnregisterClass(cls.lpszClassName, cls.hInstance);
11202     if (!RegisterClassA(&cls)) assert(0);
11203
11204     SetLastError(0xdeadbeef);
11205     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11206                            100, 100, 200, 200, 0, 0, 0, NULL);
11207     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11208
11209     SetLastError(0xdeadbeef);
11210     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11211     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11212
11213     SetMenu(hwnd, hmenu);
11214     SetForegroundWindow( hwnd );
11215
11216     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11217     style = get_menu_style(hmenu);
11218     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11219
11220     hmenu_popup = GetSubMenu(hmenu, 0);
11221     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11222     style = get_menu_style(hmenu_popup);
11223     ok(style == 0, "expected 0, got %u\n", style);
11224
11225     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11226     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11227     style = get_menu_style(hmenu_popup);
11228     ok(style == 0, "expected 0, got %u\n", style);
11229
11230     /* Alt+E, Enter */
11231     trace("testing a popup menu command\n");
11232     flush_sequence();
11233     keybd_event(VK_MENU, 0, 0, 0);
11234     keybd_event('E', 0, 0, 0);
11235     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11236     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11237     keybd_event(VK_RETURN, 0, 0, 0);
11238     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11239     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11240     {
11241         TranslateMessage(&msg);
11242         DispatchMessage(&msg);
11243     }
11244     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11245
11246     /* Alt+F, Right, Enter */
11247     trace("testing submenu of a popup menu command\n");
11248     flush_sequence();
11249     keybd_event(VK_MENU, 0, 0, 0);
11250     keybd_event('F', 0, 0, 0);
11251     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11252     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11253     keybd_event(VK_RIGHT, 0, 0, 0);
11254     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11255     keybd_event(VK_RETURN, 0, 0, 0);
11256     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11257     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11258     {
11259         TranslateMessage(&msg);
11260         DispatchMessage(&msg);
11261     }
11262     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11263
11264     set_menu_style(hmenu, 0);
11265     style = get_menu_style(hmenu);
11266     ok(style == 0, "expected 0, got %u\n", style);
11267
11268     hmenu_popup = GetSubMenu(hmenu, 0);
11269     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11270     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11271     style = get_menu_style(hmenu_popup);
11272     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11273
11274     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11275     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11276     style = get_menu_style(hmenu_popup);
11277     ok(style == 0, "expected 0, got %u\n", style);
11278
11279     /* Alt+F, Right, Enter */
11280     trace("testing submenu of a popup menu command\n");
11281     flush_sequence();
11282     keybd_event(VK_MENU, 0, 0, 0);
11283     keybd_event('F', 0, 0, 0);
11284     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11285     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11286     keybd_event(VK_RIGHT, 0, 0, 0);
11287     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11288     keybd_event(VK_RETURN, 0, 0, 0);
11289     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11290     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11291     {
11292         TranslateMessage(&msg);
11293         DispatchMessage(&msg);
11294     }
11295     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11296
11297     DestroyWindow(hwnd);
11298     DestroyMenu(hmenu);
11299 }
11300
11301
11302 static void test_paintingloop(void)
11303 {
11304     HWND hwnd;
11305
11306     paint_loop_done = 0;
11307     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11308                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11309                                 100, 100, 100, 100, 0, 0, 0, NULL );
11310     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11311     ShowWindow(hwnd,SW_NORMAL);
11312     SetFocus(hwnd);
11313
11314     while (!paint_loop_done)
11315     {
11316         MSG msg;
11317         if (PeekMessageA(&msg, 0, 0, 0, 1))
11318         {
11319             TranslateMessage(&msg);
11320             DispatchMessage(&msg);
11321         }
11322     }
11323     DestroyWindow(hwnd);
11324 }
11325
11326 START_TEST(msg)
11327 {
11328     BOOL ret;
11329     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11330
11331     init_procs();
11332
11333     if (!RegisterWindowClasses()) assert(0);
11334
11335     if (pSetWinEventHook)
11336     {
11337         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11338                                        GetModuleHandleA(0), win_event_proc,
11339                                        0, GetCurrentThreadId(),
11340                                        WINEVENT_INCONTEXT);
11341         assert(hEvent_hook);
11342
11343         if (pIsWinEventHookInstalled)
11344         {
11345             UINT event;
11346             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11347                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11348         }
11349     }
11350
11351     cbt_hook_thread_id = GetCurrentThreadId();
11352     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11353     if (!hCBT_hook) skip( "cannot set global hook, will skip hook tests\n" );
11354
11355     test_winevents();
11356
11357     /* Fix message sequences before removing 4 lines below */
11358 #if 1
11359     if (pUnhookWinEvent && hEvent_hook)
11360     {
11361         ret = pUnhookWinEvent(hEvent_hook);
11362         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11363         pUnhookWinEvent = 0;
11364     }
11365     hEvent_hook = 0;
11366 #endif
11367
11368     test_ShowWindow();
11369     test_PeekMessage();
11370     test_PeekMessage2();
11371     test_scrollwindowex();
11372     test_messages();
11373     test_setwindowpos();
11374     test_showwindow();
11375     invisible_parent_tests();
11376     test_mdi_messages();
11377     test_button_messages();
11378     test_static_messages();
11379     test_listbox_messages();
11380     test_combobox_messages();
11381     test_wmime_keydown_message();
11382     test_paint_messages();
11383     test_interthread_messages();
11384     test_message_conversion();
11385     test_accelerators();
11386     test_timers();
11387     test_timers_no_wnd();
11388     if (hCBT_hook) test_set_hook();
11389     test_DestroyWindow();
11390     test_DispatchMessage();
11391     test_SendMessageTimeout();
11392     test_edit_messages();
11393     test_quit_message();
11394     test_SetActiveWindow();
11395
11396     if (!pTrackMouseEvent)
11397         skip("TrackMouseEvent is not available\n");
11398     else
11399         test_TrackMouseEvent();
11400
11401     test_SetWindowRgn();
11402     test_sys_menu();
11403     test_dialog_messages();
11404     test_nullCallback();
11405     test_dbcs_wm_char();
11406     test_menu_messages();
11407     test_paintingloop();
11408     /* keep it the last test, under Windows it tends to break the tests
11409      * which rely on active/foreground windows being correct.
11410      */
11411     test_SetForegroundWindow();
11412
11413     UnhookWindowsHookEx(hCBT_hook);
11414     if (pUnhookWinEvent)
11415     {
11416         ret = pUnhookWinEvent(hEvent_hook);
11417         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11418         SetLastError(0xdeadbeef);
11419         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11420         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11421            GetLastError() == 0xdeadbeef, /* Win9x */
11422            "unexpected error %d\n", GetLastError());
11423     }
11424     else
11425         skip("UnhookWinEvent is not available\n");
11426 }