mapi32/tests: Fix typo.
[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 = (struct 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 = (HWND)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 = (HWINEVENTHOOK)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 = (HWND)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 = (HWINEVENTHOOK)pSetWinEventHook(
7973         EVENT_MIN, EVENT_MAX,
7974         0, win_event_global_hook_proc,
7975         GetCurrentProcessId(), 0,
7976         WINEVENT_OUTOFCONTEXT);
7977     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7978
7979     hevent = CreateEventA(NULL, 0, 0, NULL);
7980     assert(hevent);
7981     hwnd2 = (HWND)hevent;
7982
7983     flush_sequence();
7984
7985     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7986     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7987
7988     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7989
7990     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7991     /* process pending winevent messages */
7992     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7993     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7994
7995     flush_sequence();
7996     /* this one should be received only by old hook proc */
7997     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7998     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7999     /* this one should be received only by old hook proc */
8000     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8001
8002     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8003     /* process pending winevent messages */
8004     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8005     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8006
8007     ret = pUnhookWinEvent(hhook);
8008     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8009
8010     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8011     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8012     CloseHandle(hthread);
8013     CloseHandle(hevent);
8014     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8015     /****** end of out of context event test *************/
8016
8017     /****** start of MOUSE_LL hook test *************/
8018     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8019     /* WH_MOUSE_LL is not supported on Win9x platforms */
8020     if (!hCBT_global_hook)
8021     {
8022         trace("Skipping WH_MOUSE_LL test on this platform\n");
8023         goto skip_mouse_ll_hook_test;
8024     }
8025
8026     hevent = CreateEventA(NULL, 0, 0, NULL);
8027     assert(hevent);
8028     hwnd2 = (HWND)hevent;
8029
8030     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8031     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8032
8033     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8034         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8035
8036     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8037     flush_sequence();
8038
8039     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8040     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8041     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8042
8043     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8044
8045     ret = UnhookWindowsHookEx(hCBT_global_hook);
8046     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8047
8048     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8049     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8050     CloseHandle(hthread);
8051     CloseHandle(hevent);
8052     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8053     /****** end of MOUSE_LL hook test *************/
8054 skip_mouse_ll_hook_test:
8055
8056     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8057 }
8058
8059 static void test_set_hook(void)
8060 {
8061     BOOL ret;
8062     HHOOK hhook;
8063     HWINEVENTHOOK hwinevent_hook;
8064
8065     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8066     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8067     UnhookWindowsHookEx(hhook);
8068
8069     if (0)
8070     {
8071     /* this test doesn't pass under Win9x: BUG! */
8072     SetLastError(0xdeadbeef);
8073     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8074     ok(!hhook, "global hook requires hModule != 0\n");
8075     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8076     }
8077
8078     SetLastError(0xdeadbeef);
8079     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8080     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8081     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8082        GetLastError() == 0xdeadbeef, /* Win9x */
8083        "unexpected error %d\n", GetLastError());
8084
8085     SetLastError(0xdeadbeef);
8086     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8087     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8088        GetLastError() == 0xdeadbeef, /* Win9x */
8089        "unexpected error %d\n", GetLastError());
8090
8091     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8092
8093     /* even process local incontext hooks require hmodule */
8094     SetLastError(0xdeadbeef);
8095     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8096         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8097     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8098     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8099        GetLastError() == 0xdeadbeef, /* Win9x */
8100        "unexpected error %d\n", GetLastError());
8101
8102     /* even thread local incontext hooks require hmodule */
8103     SetLastError(0xdeadbeef);
8104     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8105         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8106     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8107     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8108        GetLastError() == 0xdeadbeef, /* Win9x */
8109        "unexpected error %d\n", GetLastError());
8110
8111     if (0)
8112     {
8113     /* these 3 tests don't pass under Win9x */
8114     SetLastError(0xdeadbeef);
8115     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
8116         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8117     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8118     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8119
8120     SetLastError(0xdeadbeef);
8121     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
8122         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8123     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8124     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8125
8126     SetLastError(0xdeadbeef);
8127     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8128         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8129     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8130     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8131     }
8132
8133     SetLastError(0xdeadbeef);
8134     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
8135         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8136     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8137     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8138     ret = pUnhookWinEvent(hwinevent_hook);
8139     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8140
8141 todo_wine {
8142     /* This call succeeds under win2k SP4, but fails under Wine.
8143        Does win2k test/use passed process id? */
8144     SetLastError(0xdeadbeef);
8145     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8146         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8147     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8148     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8149     ret = pUnhookWinEvent(hwinevent_hook);
8150     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8151 }
8152
8153     SetLastError(0xdeadbeef);
8154     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8155     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8156         GetLastError() == 0xdeadbeef, /* Win9x */
8157         "unexpected error %d\n", GetLastError());
8158 }
8159
8160 static const struct message ScrollWindowPaint1[] = {
8161     { WM_PAINT, sent },
8162     { WM_ERASEBKGND, sent|beginpaint },
8163     { 0 }
8164 };
8165
8166 static const struct message ScrollWindowPaint2[] = {
8167     { WM_PAINT, sent },
8168     { 0 }
8169 };
8170
8171 static void test_scrollwindowex(void)
8172 {
8173     HWND hwnd, hchild;
8174     RECT rect={0,0,130,130};
8175
8176     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8177             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8178             100, 100, 200, 200, 0, 0, 0, NULL);
8179     ok (hwnd != 0, "Failed to create overlapped window\n");
8180     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8181             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8182             10, 10, 150, 150, hwnd, 0, 0, NULL);
8183     ok (hchild != 0, "Failed to create child\n");
8184     UpdateWindow(hwnd);
8185     flush_events();
8186     flush_sequence();
8187
8188     /* scroll without the child window */
8189     trace("start scroll\n");
8190     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8191             SW_ERASE|SW_INVALIDATE);
8192     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8193     trace("end scroll\n");
8194     flush_sequence();
8195     flush_events();
8196     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8197     flush_events();
8198     flush_sequence();
8199
8200     /* Now without the SW_ERASE flag */
8201     trace("start scroll\n");
8202     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8203     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8204     trace("end scroll\n");
8205     flush_sequence();
8206     flush_events();
8207     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8208     flush_events();
8209     flush_sequence();
8210
8211     /* now scroll the child window as well */
8212     trace("start scroll\n");
8213     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8214             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8215     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8216     /* windows sometimes a WM_MOVE */
8217     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8218     trace("end scroll\n");
8219     flush_sequence();
8220     flush_events();
8221     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8222     flush_events();
8223     flush_sequence();
8224
8225     /* now scroll with ScrollWindow() */
8226     trace("start scroll with ScrollWindow\n");
8227     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8228     trace("end scroll\n");
8229     flush_sequence();
8230     flush_events();
8231     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8232
8233     ok(DestroyWindow(hchild), "failed to destroy window\n");
8234     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8235     flush_sequence();
8236 }
8237
8238 static const struct message destroy_window_with_children[] = {
8239     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8240     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8241     { 0x0090, sent|optional },
8242     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8243     { 0x0090, sent|optional },
8244     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8245     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8246     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8247     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8248     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8249     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8250     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8251     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8252     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8253     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8254     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8255     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8256     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8257     { 0 }
8258 };
8259
8260 static void test_DestroyWindow(void)
8261 {
8262     BOOL ret;
8263     HWND parent, child1, child2, child3, child4, test;
8264     UINT_PTR child_id = WND_CHILD_ID + 1;
8265
8266     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8267                              100, 100, 200, 200, 0, 0, 0, NULL);
8268     assert(parent != 0);
8269     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8270                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8271     assert(child1 != 0);
8272     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8273                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8274     assert(child2 != 0);
8275     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8276                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8277     assert(child3 != 0);
8278     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8279                              0, 0, 50, 50, parent, 0, 0, NULL);
8280     assert(child4 != 0);
8281
8282     /* test owner/parent of child2 */
8283     test = GetParent(child2);
8284     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8285     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8286     if(pGetAncestor) {
8287         test = pGetAncestor(child2, GA_PARENT);
8288         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8289     }
8290     test = GetWindow(child2, GW_OWNER);
8291     ok(!test, "wrong owner %p\n", test);
8292
8293     test = SetParent(child2, parent);
8294     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8295
8296     /* test owner/parent of the parent */
8297     test = GetParent(parent);
8298     ok(!test, "wrong parent %p\n", test);
8299     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8300     if(pGetAncestor) {
8301         test = pGetAncestor(parent, GA_PARENT);
8302         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8303     }
8304     test = GetWindow(parent, GW_OWNER);
8305     ok(!test, "wrong owner %p\n", test);
8306
8307     /* test owner/parent of child1 */
8308     test = GetParent(child1);
8309     ok(test == parent, "wrong parent %p\n", test);
8310     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8311     if(pGetAncestor) {
8312         test = pGetAncestor(child1, GA_PARENT);
8313         ok(test == parent, "wrong parent %p\n", test);
8314     }
8315     test = GetWindow(child1, GW_OWNER);
8316     ok(!test, "wrong owner %p\n", test);
8317
8318     /* test owner/parent of child2 */
8319     test = GetParent(child2);
8320     ok(test == parent, "wrong parent %p\n", test);
8321     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8322     if(pGetAncestor) {
8323         test = pGetAncestor(child2, GA_PARENT);
8324         ok(test == parent, "wrong parent %p\n", test);
8325     }
8326     test = GetWindow(child2, GW_OWNER);
8327     ok(!test, "wrong owner %p\n", test);
8328
8329     /* test owner/parent of child3 */
8330     test = GetParent(child3);
8331     ok(test == child1, "wrong parent %p\n", test);
8332     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8333     if(pGetAncestor) {
8334         test = pGetAncestor(child3, GA_PARENT);
8335         ok(test == child1, "wrong parent %p\n", test);
8336     }
8337     test = GetWindow(child3, GW_OWNER);
8338     ok(!test, "wrong owner %p\n", test);
8339
8340     /* test owner/parent of child4 */
8341     test = GetParent(child4);
8342     ok(test == parent, "wrong parent %p\n", test);
8343     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8344     if(pGetAncestor) {
8345         test = pGetAncestor(child4, GA_PARENT);
8346         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8347     }
8348     test = GetWindow(child4, GW_OWNER);
8349     ok(test == parent, "wrong owner %p\n", test);
8350
8351     flush_sequence();
8352
8353     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8354            parent, child1, child2, child3, child4);
8355
8356     SetCapture(child4);
8357     test = GetCapture();
8358     ok(test == child4, "wrong capture window %p\n", test);
8359
8360     test_DestroyWindow_flag = TRUE;
8361     ret = DestroyWindow(parent);
8362     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8363     test_DestroyWindow_flag = FALSE;
8364     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8365
8366     ok(!IsWindow(parent), "parent still exists\n");
8367     ok(!IsWindow(child1), "child1 still exists\n");
8368     ok(!IsWindow(child2), "child2 still exists\n");
8369     ok(!IsWindow(child3), "child3 still exists\n");
8370     ok(!IsWindow(child4), "child4 still exists\n");
8371
8372     test = GetCapture();
8373     ok(!test, "wrong capture window %p\n", test);
8374 }
8375
8376
8377 static const struct message WmDispatchPaint[] = {
8378     { WM_NCPAINT, sent },
8379     { WM_GETTEXT, sent|defwinproc|optional },
8380     { WM_GETTEXT, sent|defwinproc|optional },
8381     { WM_ERASEBKGND, sent },
8382     { 0 }
8383 };
8384
8385 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8386 {
8387     if (message == WM_PAINT) return 0;
8388     return MsgCheckProcA( hwnd, message, wParam, lParam );
8389 }
8390
8391 static void test_DispatchMessage(void)
8392 {
8393     RECT rect;
8394     MSG msg;
8395     int count;
8396     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8397                                100, 100, 200, 200, 0, 0, 0, NULL);
8398     ShowWindow( hwnd, SW_SHOW );
8399     UpdateWindow( hwnd );
8400     flush_events();
8401     flush_sequence();
8402     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8403
8404     SetRect( &rect, -5, -5, 5, 5 );
8405     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8406     count = 0;
8407     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8408     {
8409         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8410         else
8411         {
8412             flush_sequence();
8413             DispatchMessage( &msg );
8414             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8415             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8416             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8417             if (++count > 10) break;
8418         }
8419     }
8420     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8421
8422     trace("now without DispatchMessage\n");
8423     flush_sequence();
8424     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8425     count = 0;
8426     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8427     {
8428         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8429         else
8430         {
8431             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8432             flush_sequence();
8433             /* this will send WM_NCCPAINT just like DispatchMessage does */
8434             GetUpdateRgn( hwnd, hrgn, TRUE );
8435             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8436             DeleteObject( hrgn );
8437             GetClientRect( hwnd, &rect );
8438             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8439             ok( !count, "Got multiple WM_PAINTs\n" );
8440             if (++count > 10) break;
8441         }
8442     }
8443     DestroyWindow(hwnd);
8444 }
8445
8446
8447 static const struct message WmUser[] = {
8448     { WM_USER, sent },
8449     { 0 }
8450 };
8451
8452 struct sendmsg_info
8453 {
8454     HWND  hwnd;
8455     DWORD timeout;
8456     DWORD ret;
8457 };
8458
8459 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8460 {
8461     struct sendmsg_info *info = arg;
8462     SetLastError( 0xdeadbeef );
8463     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8464     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8465                         broken(GetLastError() == 0),  /* win9x */
8466                         "unexpected error %d\n", GetLastError());
8467     return 0;
8468 }
8469
8470 static void wait_for_thread( HANDLE thread )
8471 {
8472     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8473     {
8474         MSG msg;
8475         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8476     }
8477 }
8478
8479 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8480 {
8481     if (message == WM_USER) Sleep(200);
8482     return MsgCheckProcA( hwnd, message, wParam, lParam );
8483 }
8484
8485 static void test_SendMessageTimeout(void)
8486 {
8487     HANDLE thread;
8488     struct sendmsg_info info;
8489     DWORD tid;
8490     BOOL is_win9x;
8491
8492     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8493                                100, 100, 200, 200, 0, 0, 0, NULL);
8494     flush_events();
8495     flush_sequence();
8496
8497     info.timeout = 1000;
8498     info.ret = 0xdeadbeef;
8499     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8500     wait_for_thread( thread );
8501     CloseHandle( thread );
8502     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8503     ok_sequence( WmUser, "WmUser", FALSE );
8504
8505     info.timeout = 1;
8506     info.ret = 0xdeadbeef;
8507     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8508     Sleep(100);  /* SendMessageTimeout should time out here */
8509     wait_for_thread( thread );
8510     CloseHandle( thread );
8511     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8512     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8513
8514     /* 0 means infinite timeout (but not on win9x) */
8515     info.timeout = 0;
8516     info.ret = 0xdeadbeef;
8517     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8518     Sleep(100);
8519     wait_for_thread( thread );
8520     CloseHandle( thread );
8521     is_win9x = !info.ret;
8522     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8523     else ok_sequence( WmUser, "WmUser", FALSE );
8524
8525     /* timeout is treated as signed despite the prototype (but not on win9x) */
8526     info.timeout = 0x7fffffff;
8527     info.ret = 0xdeadbeef;
8528     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8529     Sleep(100);
8530     wait_for_thread( thread );
8531     CloseHandle( thread );
8532     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8533     ok_sequence( WmUser, "WmUser", FALSE );
8534
8535     info.timeout = 0x80000000;
8536     info.ret = 0xdeadbeef;
8537     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8538     Sleep(100);
8539     wait_for_thread( thread );
8540     CloseHandle( thread );
8541     if (is_win9x)
8542     {
8543         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8544         ok_sequence( WmUser, "WmUser", FALSE );
8545     }
8546     else
8547     {
8548         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8549         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8550     }
8551
8552     /* now check for timeout during message processing */
8553     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8554     info.timeout = 100;
8555     info.ret = 0xdeadbeef;
8556     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8557     wait_for_thread( thread );
8558     CloseHandle( thread );
8559     /* we should time out but still get the message */
8560     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8561     ok_sequence( WmUser, "WmUser", FALSE );
8562
8563     DestroyWindow( info.hwnd );
8564 }
8565
8566
8567 /****************** edit message test *************************/
8568 #define ID_EDIT 0x1234
8569 static const struct message sl_edit_setfocus[] =
8570 {
8571     { HCBT_SETFOCUS, hook },
8572     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8573     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8574     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8575     { WM_SETFOCUS, sent|wparam, 0 },
8576     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8577     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8578     { WM_CTLCOLOREDIT, sent|parent },
8579     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8580     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8581     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8582     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8583     { 0 }
8584 };
8585 static const struct message ml_edit_setfocus[] =
8586 {
8587     { HCBT_SETFOCUS, hook },
8588     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8589     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8590     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8591     { WM_SETFOCUS, sent|wparam, 0 },
8592     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8593     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8594     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8595     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8596     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8597     { 0 }
8598 };
8599 static const struct message sl_edit_killfocus[] =
8600 {
8601     { HCBT_SETFOCUS, hook },
8602     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8603     { WM_KILLFOCUS, sent|wparam, 0 },
8604     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8605     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8606     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8607     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8608     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8609     { 0 }
8610 };
8611 static const struct message sl_edit_lbutton_dblclk[] =
8612 {
8613     { WM_LBUTTONDBLCLK, sent },
8614     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8615     { 0 }
8616 };
8617 static const struct message sl_edit_lbutton_down[] =
8618 {
8619     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8620     { HCBT_SETFOCUS, hook },
8621     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8622     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8623     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8624     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8625     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8626     { WM_CTLCOLOREDIT, sent|parent },
8627     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8628     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8629     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8630     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8631     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8632     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8633     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8634     { WM_CTLCOLOREDIT, sent|parent|optional },
8635     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8636     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8637     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8638     { 0 }
8639 };
8640 static const struct message ml_edit_lbutton_down[] =
8641 {
8642     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8643     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8644     { HCBT_SETFOCUS, hook },
8645     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8646     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8647     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8648     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8649     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8650     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8651     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8652     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8653     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8654     { 0 }
8655 };
8656 static const struct message sl_edit_lbutton_up[] =
8657 {
8658     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8659     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8660     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8661     { WM_CAPTURECHANGED, sent|defwinproc },
8662     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8663     { 0 }
8664 };
8665 static const struct message ml_edit_lbutton_up[] =
8666 {
8667     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8668     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8669     { WM_CAPTURECHANGED, sent|defwinproc },
8670     { 0 }
8671 };
8672
8673 static WNDPROC old_edit_proc;
8674
8675 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8676 {
8677     static long defwndproc_counter = 0;
8678     LRESULT ret;
8679     struct recvd_message msg;
8680
8681     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8682
8683     msg.hwnd = hwnd;
8684     msg.message = message;
8685     msg.flags = sent|wparam|lparam;
8686     if (defwndproc_counter) msg.flags |= defwinproc;
8687     msg.wParam = wParam;
8688     msg.lParam = lParam;
8689     msg.descr = "edit";
8690     add_message(&msg);
8691
8692     defwndproc_counter++;
8693     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8694     defwndproc_counter--;
8695
8696     return ret;
8697 }
8698
8699 static void subclass_edit(void)
8700 {
8701     WNDCLASSA cls;
8702
8703     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8704
8705     old_edit_proc = cls.lpfnWndProc;
8706
8707     cls.hInstance = GetModuleHandle(0);
8708     cls.lpfnWndProc = edit_hook_proc;
8709     cls.lpszClassName = "my_edit_class";
8710     UnregisterClass(cls.lpszClassName, cls.hInstance);
8711     if (!RegisterClassA(&cls)) assert(0);
8712 }
8713
8714 static void test_edit_messages(void)
8715 {
8716     HWND hwnd, parent;
8717     DWORD dlg_code;
8718
8719     subclass_edit();
8720     log_all_parent_messages++;
8721
8722     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8723                              100, 100, 200, 200, 0, 0, 0, NULL);
8724     ok (parent != 0, "Failed to create parent window\n");
8725
8726     /* test single line edit */
8727     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8728                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8729     ok(hwnd != 0, "Failed to create edit window\n");
8730
8731     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8732     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8733
8734     ShowWindow(hwnd, SW_SHOW);
8735     UpdateWindow(hwnd);
8736     SetFocus(0);
8737     flush_sequence();
8738
8739     SetFocus(hwnd);
8740     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8741
8742     SetFocus(0);
8743     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8744
8745     SetFocus(0);
8746     ReleaseCapture();
8747     flush_sequence();
8748
8749     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8750     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8751
8752     SetFocus(0);
8753     ReleaseCapture();
8754     flush_sequence();
8755
8756     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8757     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8758
8759     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8760     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8761
8762     DestroyWindow(hwnd);
8763
8764     /* test multiline edit */
8765     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8766                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8767     ok(hwnd != 0, "Failed to create edit window\n");
8768
8769     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8770     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8771        "wrong dlg_code %08x\n", dlg_code);
8772
8773     ShowWindow(hwnd, SW_SHOW);
8774     UpdateWindow(hwnd);
8775     SetFocus(0);
8776     flush_sequence();
8777
8778     SetFocus(hwnd);
8779     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8780
8781     SetFocus(0);
8782     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8783
8784     SetFocus(0);
8785     ReleaseCapture();
8786     flush_sequence();
8787
8788     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8789     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8790
8791     SetFocus(0);
8792     ReleaseCapture();
8793     flush_sequence();
8794
8795     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8796     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8797
8798     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8799     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8800
8801     DestroyWindow(hwnd);
8802     DestroyWindow(parent);
8803
8804     log_all_parent_messages--;
8805 }
8806
8807 /**************************** End of Edit test ******************************/
8808
8809 static const struct message WmKeyDownSkippedSeq[] =
8810 {
8811     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8812     { 0 }
8813 };
8814 static const struct message WmKeyDownWasDownSkippedSeq[] =
8815 {
8816     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8817     { 0 }
8818 };
8819 static const struct message WmKeyUpSkippedSeq[] =
8820 {
8821     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8822     { 0 }
8823 };
8824 static const struct message WmUserKeyUpSkippedSeq[] =
8825 {
8826     { WM_USER, sent },
8827     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8828     { 0 }
8829 };
8830
8831 #define EV_STOP 0
8832 #define EV_SENDMSG 1
8833 #define EV_ACK 2
8834
8835 struct peekmsg_info
8836 {
8837     HWND  hwnd;
8838     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8839 };
8840
8841 static DWORD CALLBACK send_msg_thread_2(void *param)
8842 {
8843     DWORD ret;
8844     struct peekmsg_info *info = param;
8845
8846     trace("thread: looping\n");
8847     SetEvent(info->hevent[EV_ACK]);
8848
8849     while (1)
8850     {
8851         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8852
8853         switch (ret)
8854         {
8855         case WAIT_OBJECT_0 + EV_STOP:
8856             trace("thread: exiting\n");
8857             return 0;
8858
8859         case WAIT_OBJECT_0 + EV_SENDMSG:
8860             trace("thread: sending message\n");
8861             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8862                 "SendNotifyMessageA failed error %u\n", GetLastError());
8863             SetEvent(info->hevent[EV_ACK]);
8864             break;
8865
8866         default:
8867             trace("unexpected return: %04x\n", ret);
8868             assert(0);
8869             break;
8870         }
8871     }
8872     return 0;
8873 }
8874
8875 static void test_PeekMessage(void)
8876 {
8877     MSG msg;
8878     HANDLE hthread;
8879     DWORD tid, qstatus;
8880     UINT qs_all_input = QS_ALLINPUT;
8881     UINT qs_input = QS_INPUT;
8882     BOOL ret;
8883     struct peekmsg_info info;
8884
8885     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8886                               100, 100, 200, 200, 0, 0, 0, NULL);
8887     assert(info.hwnd);
8888     ShowWindow(info.hwnd, SW_SHOW);
8889     UpdateWindow(info.hwnd);
8890     SetFocus(info.hwnd);
8891
8892     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8893     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8894     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8895
8896     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8897     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8898
8899     flush_events();
8900     flush_sequence();
8901
8902     SetLastError(0xdeadbeef);
8903     qstatus = GetQueueStatus(qs_all_input);
8904     if (GetLastError() == ERROR_INVALID_FLAGS)
8905     {
8906         trace("QS_RAWINPUT not supported on this platform\n");
8907         qs_all_input &= ~QS_RAWINPUT;
8908         qs_input &= ~QS_RAWINPUT;
8909     }
8910     if (qstatus & QS_POSTMESSAGE)
8911     {
8912         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8913         qstatus = GetQueueStatus(qs_all_input);
8914     }
8915     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8916
8917     trace("signalling to send message\n");
8918     SetEvent(info.hevent[EV_SENDMSG]);
8919     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8920
8921     /* pass invalid QS_xxxx flags */
8922     SetLastError(0xdeadbeef);
8923     qstatus = GetQueueStatus(0xffffffff);
8924     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8925     if (!qstatus)
8926     {
8927         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8928         qstatus = GetQueueStatus(qs_all_input);
8929     }
8930     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8931        "wrong qstatus %08x\n", qstatus);
8932
8933     msg.message = 0;
8934     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8935     ok(!ret,
8936        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8937         msg.message);
8938     ok_sequence(WmUser, "WmUser", FALSE);
8939
8940     qstatus = GetQueueStatus(qs_all_input);
8941     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8942
8943     keybd_event('N', 0, 0, 0);
8944     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8945     qstatus = GetQueueStatus(qs_all_input);
8946     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8947        "wrong qstatus %08x\n", qstatus);
8948
8949     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8950     qstatus = GetQueueStatus(qs_all_input);
8951     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8952        "wrong qstatus %08x\n", qstatus);
8953
8954     InvalidateRect(info.hwnd, NULL, FALSE);
8955     qstatus = GetQueueStatus(qs_all_input);
8956     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8957        "wrong qstatus %08x\n", qstatus);
8958
8959     trace("signalling to send message\n");
8960     SetEvent(info.hevent[EV_SENDMSG]);
8961     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8962
8963     qstatus = GetQueueStatus(qs_all_input);
8964     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8965        "wrong qstatus %08x\n", qstatus);
8966
8967     msg.message = 0;
8968     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8969     if (ret && msg.message == WM_CHAR)
8970     {
8971         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8972         goto done;
8973     }
8974     ok(!ret,
8975        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8976         msg.message);
8977     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
8978     {
8979         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8980         goto done;
8981     }
8982     ok_sequence(WmUser, "WmUser", FALSE);
8983
8984     qstatus = GetQueueStatus(qs_all_input);
8985     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8986        "wrong qstatus %08x\n", qstatus);
8987
8988     trace("signalling to send message\n");
8989     SetEvent(info.hevent[EV_SENDMSG]);
8990     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8991
8992     qstatus = GetQueueStatus(qs_all_input);
8993     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8994        "wrong qstatus %08x\n", qstatus);
8995
8996     msg.message = 0;
8997     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
8998     ok(!ret,
8999        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9000         msg.message);
9001     ok_sequence(WmUser, "WmUser", FALSE);
9002
9003     qstatus = GetQueueStatus(qs_all_input);
9004     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9005        "wrong qstatus %08x\n", qstatus);
9006
9007     msg.message = 0;
9008     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9009     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9010        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9011        ret, msg.message, msg.wParam);
9012     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9013
9014     qstatus = GetQueueStatus(qs_all_input);
9015     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9016        "wrong qstatus %08x\n", qstatus);
9017
9018     msg.message = 0;
9019     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9020     ok(!ret,
9021        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9022         msg.message);
9023     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9024
9025     qstatus = GetQueueStatus(qs_all_input);
9026     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9027        "wrong qstatus %08x\n", qstatus);
9028
9029     msg.message = 0;
9030     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9031     ok(ret && msg.message == WM_PAINT,
9032        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9033     DispatchMessageA(&msg);
9034     ok_sequence(WmPaint, "WmPaint", FALSE);
9035
9036     qstatus = GetQueueStatus(qs_all_input);
9037     ok(qstatus == MAKELONG(0, QS_KEY),
9038        "wrong qstatus %08x\n", qstatus);
9039
9040     msg.message = 0;
9041     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9042     ok(!ret,
9043        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9044         msg.message);
9045     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9046
9047     qstatus = GetQueueStatus(qs_all_input);
9048     ok(qstatus == MAKELONG(0, QS_KEY),
9049        "wrong qstatus %08x\n", qstatus);
9050
9051     trace("signalling to send message\n");
9052     SetEvent(info.hevent[EV_SENDMSG]);
9053     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9054
9055     qstatus = GetQueueStatus(qs_all_input);
9056     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9057        "wrong qstatus %08x\n", qstatus);
9058
9059     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9060
9061     qstatus = GetQueueStatus(qs_all_input);
9062     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9063        "wrong qstatus %08x\n", qstatus);
9064
9065     msg.message = 0;
9066     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9067     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9068        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9069        ret, msg.message, msg.wParam);
9070     ok_sequence(WmUser, "WmUser", FALSE);
9071
9072     qstatus = GetQueueStatus(qs_all_input);
9073     ok(qstatus == MAKELONG(0, QS_KEY),
9074        "wrong qstatus %08x\n", qstatus);
9075
9076     msg.message = 0;
9077     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9078     ok(!ret,
9079        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9080         msg.message);
9081     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9082
9083     qstatus = GetQueueStatus(qs_all_input);
9084     ok(qstatus == MAKELONG(0, QS_KEY),
9085        "wrong qstatus %08x\n", qstatus);
9086
9087     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9088
9089     qstatus = GetQueueStatus(qs_all_input);
9090     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9091        "wrong qstatus %08x\n", qstatus);
9092
9093     trace("signalling to send message\n");
9094     SetEvent(info.hevent[EV_SENDMSG]);
9095     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9096
9097     qstatus = GetQueueStatus(qs_all_input);
9098     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9099        "wrong qstatus %08x\n", qstatus);
9100
9101     msg.message = 0;
9102     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9103     ok(!ret,
9104        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9105         msg.message);
9106     ok_sequence(WmUser, "WmUser", FALSE);
9107
9108     qstatus = GetQueueStatus(qs_all_input);
9109     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9110        "wrong qstatus %08x\n", qstatus);
9111
9112     msg.message = 0;
9113     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9114         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9115     else /* workaround for a missing QS_RAWINPUT support */
9116         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9117     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9118        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9119        ret, msg.message, msg.wParam);
9120     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9121
9122     qstatus = GetQueueStatus(qs_all_input);
9123     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9124        "wrong qstatus %08x\n", qstatus);
9125
9126     msg.message = 0;
9127     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9128         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9129     else /* workaround for a missing QS_RAWINPUT support */
9130         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9131     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9132        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9133        ret, msg.message, msg.wParam);
9134     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9135
9136     qstatus = GetQueueStatus(qs_all_input);
9137     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9138        "wrong qstatus %08x\n", qstatus);
9139
9140     msg.message = 0;
9141     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9142     ok(!ret,
9143        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9144         msg.message);
9145     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9146
9147     qstatus = GetQueueStatus(qs_all_input);
9148     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9149        "wrong qstatus %08x\n", qstatus);
9150
9151     msg.message = 0;
9152     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9153     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9154        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9155        ret, msg.message, msg.wParam);
9156     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9157
9158     qstatus = GetQueueStatus(qs_all_input);
9159     ok(qstatus == 0,
9160        "wrong qstatus %08x\n", qstatus);
9161
9162     msg.message = 0;
9163     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9164     ok(!ret,
9165        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9166         msg.message);
9167     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9168
9169     qstatus = GetQueueStatus(qs_all_input);
9170     ok(qstatus == 0,
9171        "wrong qstatus %08x\n", qstatus);
9172
9173     /* test whether presence of the quit flag in the queue affects
9174      * the queue state
9175      */
9176     PostQuitMessage(0x1234abcd);
9177
9178     qstatus = GetQueueStatus(qs_all_input);
9179     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9180        "wrong qstatus %08x\n", qstatus);
9181
9182     PostMessageA(info.hwnd, WM_USER, 0, 0);
9183
9184     qstatus = GetQueueStatus(qs_all_input);
9185     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9186        "wrong qstatus %08x\n", qstatus);
9187
9188     msg.message = 0;
9189     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9190     ok(ret && msg.message == WM_USER,
9191        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9192     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9193
9194     qstatus = GetQueueStatus(qs_all_input);
9195     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9196        "wrong qstatus %08x\n", qstatus);
9197
9198     msg.message = 0;
9199     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9200     ok(ret && msg.message == WM_QUIT,
9201        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9202     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9203     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9204     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9205
9206     qstatus = GetQueueStatus(qs_all_input);
9207 todo_wine {
9208     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9209        "wrong qstatus %08x\n", qstatus);
9210 }
9211
9212     msg.message = 0;
9213     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9214     ok(!ret,
9215        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9216         msg.message);
9217     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9218
9219     qstatus = GetQueueStatus(qs_all_input);
9220     ok(qstatus == 0,
9221        "wrong qstatus %08x\n", qstatus);
9222
9223     /* some GetMessage tests */
9224
9225     keybd_event('N', 0, 0, 0);
9226     qstatus = GetQueueStatus(qs_all_input);
9227     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9228
9229     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9230     qstatus = GetQueueStatus(qs_all_input);
9231     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9232
9233     if (qstatus)
9234     {
9235         ret = GetMessageA( &msg, 0, 0, 0 );
9236         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9237            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9238            ret, msg.message, msg.wParam);
9239         qstatus = GetQueueStatus(qs_all_input);
9240         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9241     }
9242
9243     if (qstatus)
9244     {
9245         ret = GetMessageA( &msg, 0, 0, 0 );
9246         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9247            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9248            ret, msg.message, msg.wParam);
9249         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9250         qstatus = GetQueueStatus(qs_all_input);
9251         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9252     }
9253
9254     keybd_event('N', 0, 0, 0);
9255     qstatus = GetQueueStatus(qs_all_input);
9256     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9257
9258     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9259     qstatus = GetQueueStatus(qs_all_input);
9260     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9261
9262     if (qstatus & (QS_KEY << 16))
9263     {
9264         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9265         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9266            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9267            ret, msg.message, msg.wParam);
9268         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9269         qstatus = GetQueueStatus(qs_all_input);
9270         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9271     }
9272
9273     if (qstatus)
9274     {
9275         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9276         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9277            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9278            ret, msg.message, msg.wParam);
9279         qstatus = GetQueueStatus(qs_all_input);
9280         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9281     }
9282
9283     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9284     qstatus = GetQueueStatus(qs_all_input);
9285     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9286
9287     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9288     qstatus = GetQueueStatus(qs_all_input);
9289     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9290
9291     trace("signalling to send message\n");
9292     SetEvent(info.hevent[EV_SENDMSG]);
9293     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9294     qstatus = GetQueueStatus(qs_all_input);
9295     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9296        "wrong qstatus %08x\n", qstatus);
9297
9298     if (qstatus & (QS_KEY << 16))
9299     {
9300         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9301         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9302            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9303            ret, msg.message, msg.wParam);
9304         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9305         qstatus = GetQueueStatus(qs_all_input);
9306         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9307     }
9308
9309     if (qstatus)
9310     {
9311         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9312         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9313            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9314            ret, msg.message, msg.wParam);
9315         qstatus = GetQueueStatus(qs_all_input);
9316         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9317     }
9318 done:
9319     trace("signalling to exit\n");
9320     SetEvent(info.hevent[EV_STOP]);
9321
9322     WaitForSingleObject(hthread, INFINITE);
9323
9324     CloseHandle(hthread);
9325     CloseHandle(info.hevent[0]);
9326     CloseHandle(info.hevent[1]);
9327     CloseHandle(info.hevent[2]);
9328
9329     DestroyWindow(info.hwnd);
9330 }
9331
9332 static void wait_move_event(HWND hwnd, int x, int y)
9333 {
9334     MSG msg;
9335     DWORD time;
9336     BOOL  ret;
9337     int go = 0;
9338
9339     time = GetTickCount();
9340     while (GetTickCount() - time < 200 && !go) {
9341         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9342         go  = ret && msg.pt.x > x && msg.pt.y > y;
9343         if (ret && !go) PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9344     }
9345 }
9346
9347 #define STEP 20
9348 static void test_PeekMessage2(void)
9349 {
9350     HWND hwnd;
9351     BOOL ret;
9352     MSG msg;
9353     UINT message;
9354     DWORD time1, time2, time3;
9355     int x1, y1, x2, y2, x3, y3;
9356     POINT pos;
9357
9358     time1 = time2 = time3 = 0;
9359     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9360
9361     /* Initialise window and make sure it is ready for events */
9362     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9363                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9364     assert(hwnd);
9365     trace("Window for test_PeekMessage2 %p\n", hwnd);
9366     ShowWindow(hwnd, SW_SHOW);
9367     UpdateWindow(hwnd);
9368     SetFocus(hwnd);
9369     GetCursorPos(&pos);
9370     SetCursorPos(100, 100);
9371     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9372     flush_events();
9373
9374     /* Do initial mousemove, wait until we can see it
9375        and then do our test peek with PM_NOREMOVE. */
9376     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9377     wait_move_event(hwnd, 80, 80);
9378
9379     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9380     ok(ret, "no message available\n");
9381     if (ret) {
9382         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9383         message = msg.message;
9384         time1 = msg.time;
9385         x1 = msg.pt.x;
9386         y1 = msg.pt.y;
9387         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9388         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9389     }
9390
9391     /* Allow time to advance a bit, and then simulate the user moving their
9392      * mouse around. After that we peek again with PM_NOREMOVE.
9393      * Although the previous mousemove message was never removed, the
9394      * mousemove we now peek should reflect the recent mouse movements
9395      * because the input queue will merge the move events. */
9396     Sleep(2);
9397     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9398     wait_move_event(hwnd, x1, y1);
9399
9400     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9401     ok(ret, "no message available\n");
9402     if (ret) {
9403         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9404         message = msg.message;
9405         time2 = msg.time;
9406         x2 = msg.pt.x;
9407         y2 = msg.pt.y;
9408         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9409         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9410         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9411         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9412     }
9413
9414     /* Have another go, to drive the point home */
9415     Sleep(2);
9416     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9417     wait_move_event(hwnd, x2, y2);
9418
9419     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9420     ok(ret, "no message available\n");
9421     if (ret) {
9422         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9423         message = msg.message;
9424         time3 = msg.time;
9425         x3 = msg.pt.x;
9426         y3 = msg.pt.y;
9427         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9428         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9429         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9430     }
9431
9432     DestroyWindow(hwnd);
9433     SetCursorPos(pos.x, pos.y);
9434     flush_events();
9435 }
9436
9437 static void test_quit_message(void)
9438 {
9439     MSG msg;
9440     BOOL ret;
9441
9442     /* test using PostQuitMessage */
9443     flush_events();
9444     PostQuitMessage(0xbeef);
9445
9446     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9447     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9448     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9449     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9450
9451     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9452     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9453
9454     ret = GetMessage(&msg, NULL, 0, 0);
9455     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9456     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9457
9458     /* note: WM_QUIT message received after WM_USER message */
9459     ret = GetMessage(&msg, NULL, 0, 0);
9460     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9461     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9462     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9463
9464     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9465     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9466
9467     /* now test with PostThreadMessage - different behaviour! */
9468     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9469
9470     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9471     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9472     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9473     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9474
9475     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9476     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9477
9478     /* note: we receive the WM_QUIT message first this time */
9479     ret = GetMessage(&msg, NULL, 0, 0);
9480     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9481     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9482     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9483
9484     ret = GetMessage(&msg, NULL, 0, 0);
9485     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9486     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9487 }
9488
9489 static const struct message WmMouseHoverSeq[] = {
9490     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9491     { WM_MOUSEACTIVATE, sent|optional },
9492     { WM_TIMER, sent|optional }, /* XP sends it */
9493     { WM_SYSTIMER, sent },
9494     { WM_MOUSEHOVER, sent|wparam, 0 },
9495     { 0 }
9496 };
9497
9498 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9499 {
9500     MSG msg;
9501     DWORD start_ticks, end_ticks;
9502
9503     start_ticks = GetTickCount();
9504     /* add some deviation (50%) to cover not expected delays */
9505     start_ticks += timeout / 2;
9506
9507     do
9508     {
9509         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9510         {
9511             /* Timer proc messages are not dispatched to the window proc,
9512              * and therefore not logged.
9513              */
9514             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9515             {
9516                 struct recvd_message s_msg;
9517
9518                 s_msg.hwnd = msg.hwnd;
9519                 s_msg.message = msg.message;
9520                 s_msg.flags = sent|wparam|lparam;
9521                 s_msg.wParam = msg.wParam;
9522                 s_msg.lParam = msg.lParam;
9523                 s_msg.descr = "msg_loop";
9524                 add_message(&s_msg);
9525             }
9526             DispatchMessage(&msg);
9527         }
9528
9529         end_ticks = GetTickCount();
9530
9531         /* inject WM_MOUSEMOVE to see how it changes tracking */
9532         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9533         {
9534             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9535             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9536
9537             inject_mouse_move = FALSE;
9538         }
9539     } while (start_ticks + timeout >= end_ticks);
9540 }
9541
9542 static void test_TrackMouseEvent(void)
9543 {
9544     TRACKMOUSEEVENT tme;
9545     BOOL ret;
9546     HWND hwnd, hchild;
9547     RECT rc_parent, rc_child;
9548     UINT default_hover_time, hover_width = 0, hover_height = 0;
9549
9550 #define track_hover(track_hwnd, track_hover_time) \
9551     tme.cbSize = sizeof(tme); \
9552     tme.dwFlags = TME_HOVER; \
9553     tme.hwndTrack = track_hwnd; \
9554     tme.dwHoverTime = track_hover_time; \
9555     SetLastError(0xdeadbeef); \
9556     ret = pTrackMouseEvent(&tme); \
9557     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9558
9559 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9560     tme.cbSize = sizeof(tme); \
9561     tme.dwFlags = TME_QUERY; \
9562     tme.hwndTrack = (HWND)0xdeadbeef; \
9563     tme.dwHoverTime = 0xdeadbeef; \
9564     SetLastError(0xdeadbeef); \
9565     ret = pTrackMouseEvent(&tme); \
9566     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9567     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9568     ok(tme.dwFlags == (expected_track_flags), \
9569        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9570     ok(tme.hwndTrack == (expected_track_hwnd), \
9571        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9572     ok(tme.dwHoverTime == (expected_hover_time), \
9573        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9574
9575 #define track_hover_cancel(track_hwnd) \
9576     tme.cbSize = sizeof(tme); \
9577     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9578     tme.hwndTrack = track_hwnd; \
9579     tme.dwHoverTime = 0xdeadbeef; \
9580     SetLastError(0xdeadbeef); \
9581     ret = pTrackMouseEvent(&tme); \
9582     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9583
9584     default_hover_time = 0xdeadbeef;
9585     SetLastError(0xdeadbeef);
9586     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9587     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9588        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9589     if (!ret) default_hover_time = 400;
9590     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9591
9592     SetLastError(0xdeadbeef);
9593     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9594     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9595        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9596     if (!ret) hover_width = 4;
9597     SetLastError(0xdeadbeef);
9598     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9599     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9600        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9601     if (!ret) hover_height = 4;
9602     trace("hover rect is %u x %d\n", hover_width, hover_height);
9603
9604     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9605                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9606                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9607                           NULL, NULL, 0);
9608     assert(hwnd);
9609
9610     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9611                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9612                           50, 50, 200, 200, hwnd,
9613                           NULL, NULL, 0);
9614     assert(hchild);
9615
9616     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9617     flush_events();
9618     flush_sequence();
9619
9620     tme.cbSize = 0;
9621     tme.dwFlags = TME_QUERY;
9622     tme.hwndTrack = (HWND)0xdeadbeef;
9623     tme.dwHoverTime = 0xdeadbeef;
9624     SetLastError(0xdeadbeef);
9625     ret = pTrackMouseEvent(&tme);
9626     ok(!ret, "TrackMouseEvent should fail\n");
9627     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9628        "not expected error %u\n", GetLastError());
9629
9630     tme.cbSize = sizeof(tme);
9631     tme.dwFlags = TME_HOVER;
9632     tme.hwndTrack = (HWND)0xdeadbeef;
9633     tme.dwHoverTime = 0xdeadbeef;
9634     SetLastError(0xdeadbeef);
9635     ret = pTrackMouseEvent(&tme);
9636     ok(!ret, "TrackMouseEvent should fail\n");
9637     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9638        "not expected error %u\n", GetLastError());
9639
9640     tme.cbSize = sizeof(tme);
9641     tme.dwFlags = TME_HOVER | TME_CANCEL;
9642     tme.hwndTrack = (HWND)0xdeadbeef;
9643     tme.dwHoverTime = 0xdeadbeef;
9644     SetLastError(0xdeadbeef);
9645     ret = pTrackMouseEvent(&tme);
9646     ok(!ret, "TrackMouseEvent should fail\n");
9647     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9648        "not expected error %u\n", GetLastError());
9649
9650     GetWindowRect(hwnd, &rc_parent);
9651     GetWindowRect(hchild, &rc_child);
9652     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9653
9654     /* Process messages so that the system updates its internal current
9655      * window and hittest, otherwise TrackMouseEvent calls don't have any
9656      * effect.
9657      */
9658     flush_events();
9659     flush_sequence();
9660
9661     track_query(0, NULL, 0);
9662     track_hover(hchild, 0);
9663     track_query(0, NULL, 0);
9664
9665     flush_events();
9666     flush_sequence();
9667
9668     track_hover(hwnd, 0);
9669     tme.cbSize = sizeof(tme);
9670     tme.dwFlags = TME_QUERY;
9671     tme.hwndTrack = (HWND)0xdeadbeef;
9672     tme.dwHoverTime = 0xdeadbeef;
9673     SetLastError(0xdeadbeef);
9674     ret = pTrackMouseEvent(&tme);
9675     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9676     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9677     if (!tme.dwFlags)
9678     {
9679         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9680         DestroyWindow( hwnd );
9681         return;
9682     }
9683     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9684     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9685     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9686        tme.dwHoverTime, default_hover_time);
9687
9688     pump_msg_loop_timeout(default_hover_time, FALSE);
9689     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9690
9691     track_query(0, NULL, 0);
9692
9693     track_hover(hwnd, HOVER_DEFAULT);
9694     track_query(TME_HOVER, hwnd, default_hover_time);
9695
9696     Sleep(default_hover_time / 2);
9697     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9698     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9699
9700     track_query(TME_HOVER, hwnd, default_hover_time);
9701
9702     pump_msg_loop_timeout(default_hover_time, FALSE);
9703     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9704
9705     track_query(0, NULL, 0);
9706
9707     track_hover(hwnd, HOVER_DEFAULT);
9708     track_query(TME_HOVER, hwnd, default_hover_time);
9709
9710     pump_msg_loop_timeout(default_hover_time, TRUE);
9711     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9712
9713     track_query(0, NULL, 0);
9714
9715     track_hover(hwnd, HOVER_DEFAULT);
9716     track_query(TME_HOVER, hwnd, default_hover_time);
9717     track_hover_cancel(hwnd);
9718
9719     DestroyWindow(hwnd);
9720
9721 #undef track_hover
9722 #undef track_query
9723 #undef track_hover_cancel
9724 }
9725
9726
9727 static const struct message WmSetWindowRgn[] = {
9728     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9729     { WM_NCCALCSIZE, sent|wparam, 1 },
9730     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9731     { WM_GETTEXT, sent|defwinproc|optional },
9732     { WM_ERASEBKGND, sent|optional },
9733     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9734     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9735     { 0 }
9736 };
9737
9738 static const struct message WmSetWindowRgn_no_redraw[] = {
9739     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9740     { WM_NCCALCSIZE, sent|wparam, 1 },
9741     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9742     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9743     { 0 }
9744 };
9745
9746 static const struct message WmSetWindowRgn_clear[] = {
9747     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9748     { WM_NCCALCSIZE, sent|wparam, 1 },
9749     { WM_NCPAINT, sent|optional },
9750     { WM_GETTEXT, sent|defwinproc|optional },
9751     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9752     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9753     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9754     { WM_NCPAINT, sent|optional },
9755     { WM_GETTEXT, sent|defwinproc|optional },
9756     { WM_ERASEBKGND, sent|optional },
9757     { WM_WINDOWPOSCHANGING, sent|optional },
9758     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9759     { WM_NCPAINT, sent|optional },
9760     { WM_GETTEXT, sent|defwinproc|optional },
9761     { WM_ERASEBKGND, sent|optional },
9762     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9763     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9764     { WM_NCPAINT, sent|optional },
9765     { WM_GETTEXT, sent|defwinproc|optional },
9766     { WM_ERASEBKGND, sent|optional },
9767     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9768     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9769     { 0 }
9770 };
9771
9772 static void test_SetWindowRgn(void)
9773 {
9774     HRGN hrgn;
9775     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9776                                 100, 100, 200, 200, 0, 0, 0, NULL);
9777     ok( hwnd != 0, "Failed to create overlapped window\n" );
9778
9779     ShowWindow( hwnd, SW_SHOW );
9780     UpdateWindow( hwnd );
9781     flush_events();
9782     flush_sequence();
9783
9784     trace("testing SetWindowRgn\n");
9785     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9786     SetWindowRgn( hwnd, hrgn, TRUE );
9787     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9788
9789     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9790     SetWindowRgn( hwnd, hrgn, FALSE );
9791     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9792
9793     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9794     SetWindowRgn( hwnd, hrgn, TRUE );
9795     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9796
9797     SetWindowRgn( hwnd, 0, TRUE );
9798     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9799
9800     DestroyWindow( hwnd );
9801 }
9802
9803 /*************************** ShowWindow() test ******************************/
9804 static const struct message WmShowNormal[] = {
9805     { WM_SHOWWINDOW, sent|wparam, 1 },
9806     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9807     { HCBT_ACTIVATE, hook },
9808     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9809     { HCBT_SETFOCUS, hook },
9810     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9811     { 0 }
9812 };
9813 static const struct message WmShow[] = {
9814     { WM_SHOWWINDOW, sent|wparam, 1 },
9815     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9816     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9817     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9818     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9819     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9820     { 0 }
9821 };
9822 static const struct message WmShowNoActivate_1[] = {
9823     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9824     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9825     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9826     { WM_MOVE, sent|defwinproc|optional },
9827     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9828     { 0 }
9829 };
9830 static const struct message WmShowNoActivate_2[] = {
9831     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9832     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9833     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9834     { WM_MOVE, sent|defwinproc },
9835     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9836     { HCBT_SETFOCUS, hook|optional },
9837     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9838     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9839     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9840     { 0 }
9841 };
9842 static const struct message WmShowNA_1[] = {
9843     { WM_SHOWWINDOW, sent|wparam, 1 },
9844     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9845     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9846     { 0 }
9847 };
9848 static const struct message WmShowNA_2[] = {
9849     { WM_SHOWWINDOW, sent|wparam, 1 },
9850     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9851     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9852     { 0 }
9853 };
9854 static const struct message WmRestore_1[] = {
9855     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9856     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9857     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9858     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9859     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9860     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9861     { WM_MOVE, sent|defwinproc },
9862     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9863     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9864     { 0 }
9865 };
9866 static const struct message WmRestore_2[] = {
9867     { WM_SHOWWINDOW, sent|wparam, 1 },
9868     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9869     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9870     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9871     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9872     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9873     { 0 }
9874 };
9875 static const struct message WmRestore_3[] = {
9876     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9877     { WM_GETMINMAXINFO, sent },
9878     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9879     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9880     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9881     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9882     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9883     { WM_MOVE, sent|defwinproc },
9884     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9885     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9886     { 0 }
9887 };
9888 static const struct message WmRestore_4[] = {
9889     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9890     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9891     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9892     { WM_MOVE, sent|defwinproc|optional },
9893     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9894     { 0 }
9895 };
9896 static const struct message WmRestore_5[] = {
9897     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9898     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9899     { HCBT_ACTIVATE, hook|optional },
9900     { HCBT_SETFOCUS, hook|optional },
9901     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9902     { WM_MOVE, sent|defwinproc|optional },
9903     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9904     { 0 }
9905 };
9906 static const struct message WmHide_1[] = {
9907     { WM_SHOWWINDOW, sent|wparam, 0 },
9908     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9909     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9910     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9911     { 0 }
9912 };
9913 static const struct message WmHide_2[] = {
9914     { WM_SHOWWINDOW, sent|wparam, 0 },
9915     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9916     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9917     { 0 }
9918 };
9919 static const struct message WmHide_3[] = {
9920     { WM_SHOWWINDOW, sent|wparam, 0 },
9921     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9922     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9923     { HCBT_SETFOCUS, hook|optional },
9924     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9925     { 0 }
9926 };
9927 static const struct message WmShowMinimized_1[] = {
9928     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9930     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9931     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9933     { WM_MOVE, sent|defwinproc },
9934     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9935     { 0 }
9936 };
9937 static const struct message WmMinimize_1[] = {
9938     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9939     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9940     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9941     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9942     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9943     { WM_MOVE, sent|defwinproc },
9944     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9945     { 0 }
9946 };
9947 static const struct message WmMinimize_2[] = {
9948     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9949     { HCBT_SETFOCUS, hook|optional },
9950     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9951     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9952     { WM_MOVE, sent|defwinproc },
9953     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9954     { 0 }
9955 };
9956 static const struct message WmMinimize_3[] = {
9957     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9958     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9960     { WM_MOVE, sent|defwinproc },
9961     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9962     { 0 }
9963 };
9964 static const struct message WmShowMinNoActivate[] = {
9965     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9966     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9967     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9968     { 0 }
9969 };
9970 static const struct message WmMinMax_1[] = {
9971     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9972     { 0 }
9973 };
9974 static const struct message WmMinMax_2[] = {
9975     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9976     { WM_GETMINMAXINFO, sent|optional },
9977     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
9978     { HCBT_ACTIVATE, hook|optional },
9979     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
9980     { HCBT_SETFOCUS, hook|optional },
9981     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9982     { WM_MOVE, sent|defwinproc|optional },
9983     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
9984     { HCBT_SETFOCUS, hook|optional },
9985     { 0 }
9986 };
9987 static const struct message WmMinMax_3[] = {
9988     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9989     { 0 }
9990 };
9991 static const struct message WmMinMax_4[] = {
9992     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9993     { 0 }
9994 };
9995 static const struct message WmShowMaximized_1[] = {
9996     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9997     { WM_GETMINMAXINFO, sent },
9998     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9999     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10000     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10001     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10002     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10003     { WM_MOVE, sent|defwinproc },
10004     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10005     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10006     { 0 }
10007 };
10008 static const struct message WmShowMaximized_2[] = {
10009     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10010     { WM_GETMINMAXINFO, sent },
10011     { WM_WINDOWPOSCHANGING, sent|optional },
10012     { HCBT_ACTIVATE, hook|optional },
10013     { WM_WINDOWPOSCHANGED, sent|optional },
10014     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10015     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10016     { WM_WINDOWPOSCHANGING, sent },
10017     { HCBT_SETFOCUS, hook|optional },
10018     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10019     { WM_MOVE, sent|defwinproc },
10020     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10021     { HCBT_SETFOCUS, hook|optional },
10022     { 0 }
10023 };
10024 static const struct message WmShowMaximized_3[] = {
10025     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10026     { WM_GETMINMAXINFO, sent },
10027     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10028     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10029     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10030     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10031     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10032     { WM_MOVE, sent|defwinproc|optional },
10033     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10034     { 0 }
10035 };
10036
10037 static void test_ShowWindow(void)
10038 {
10039     /* ShowWindow commands in random order */
10040     static const struct
10041     {
10042         INT cmd; /* ShowWindow command */
10043         LPARAM ret; /* ShowWindow return value */
10044         DWORD style; /* window style after the command */
10045         const struct message *msg; /* message sequence the command produces */
10046         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10047     } sw[] =
10048     {
10049 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10050 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10051 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10052 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10053 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10054 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10055 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10056 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10057 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10058 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10059 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10060 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10061 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10062 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10063 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10064 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10065 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10066 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10067 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10068 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10069 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10070 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10071 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10072 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10073 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10074 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10075 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10076 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10077 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10078 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10079 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10080 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10081 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10082 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10083 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10084 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10085 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10086 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10087 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10088 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10089 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10090 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
10091 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10092 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10093 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10094 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10095 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10096 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10097 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10098 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10099 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10100 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10101 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10102 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10103 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10104 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10105 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10106     };
10107     HWND hwnd;
10108     DWORD style;
10109     LPARAM ret;
10110     INT i;
10111
10112 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10113     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10114                           120, 120, 90, 90,
10115                           0, 0, 0, NULL);
10116     assert(hwnd);
10117
10118     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10119     ok(style == 0, "expected style 0, got %08x\n", style);
10120
10121     flush_events();
10122     flush_sequence();
10123
10124     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10125     {
10126         static const char * const sw_cmd_name[13] =
10127         {
10128             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10129             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10130             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10131             "SW_NORMALNA" /* 0xCC */
10132         };
10133         char comment[64];
10134         INT idx; /* index into the above array of names */
10135
10136         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10137
10138         style = GetWindowLong(hwnd, GWL_STYLE);
10139         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10140         ret = ShowWindow(hwnd, sw[i].cmd);
10141         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10142         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10143         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10144
10145         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10146         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10147
10148         flush_events();
10149         flush_sequence();
10150     }
10151
10152     DestroyWindow(hwnd);
10153 }
10154
10155 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10156 {
10157     struct recvd_message msg;
10158
10159     switch (message)
10160     {
10161     case WM_GETICON:
10162     case WM_GETOBJECT:
10163         return 0;  /* ignore them */
10164     }
10165
10166     msg.hwnd = hwnd;
10167     msg.message = message;
10168     msg.flags = sent|wparam|lparam;
10169     msg.wParam = wParam;
10170     msg.lParam = lParam;
10171     msg.descr = "dialog";
10172     add_message(&msg);
10173
10174     /* calling DefDlgProc leads to a recursion under XP */
10175
10176     switch (message)
10177     {
10178     case WM_INITDIALOG:
10179     case WM_GETDLGCODE:
10180         return 0;
10181     }
10182     return 1;
10183 }
10184
10185 static const struct message WmDefDlgSetFocus_1[] = {
10186     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10187     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10188     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10189     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10190     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10191     { HCBT_SETFOCUS, hook },
10192     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10193     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10194     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10195     { WM_SETFOCUS, sent|wparam, 0 },
10196     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10197     { WM_CTLCOLOREDIT, sent },
10198     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10199     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10200     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10201     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10202     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10203     { 0 }
10204 };
10205 static const struct message WmDefDlgSetFocus_2[] = {
10206     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10207     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10208     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10209     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10210     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10211     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10212     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10213     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10214     { 0 }
10215 };
10216 /* Creation of a dialog */
10217 static const struct message WmCreateDialogParamSeq_1[] = {
10218     { HCBT_CREATEWND, hook },
10219     { WM_NCCREATE, sent },
10220     { WM_NCCALCSIZE, sent|wparam, 0 },
10221     { WM_CREATE, sent },
10222     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10223     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10224     { WM_MOVE, sent },
10225     { WM_SETFONT, sent },
10226     { WM_INITDIALOG, sent },
10227     { WM_CHANGEUISTATE, sent|optional },
10228     { 0 }
10229 };
10230 /* Creation of a dialog */
10231 static const struct message WmCreateDialogParamSeq_2[] = {
10232     { HCBT_CREATEWND, hook },
10233     { WM_NCCREATE, sent },
10234     { WM_NCCALCSIZE, sent|wparam, 0 },
10235     { WM_CREATE, sent },
10236     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10237     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10238     { WM_MOVE, sent },
10239     { WM_CHANGEUISTATE, sent|optional },
10240     { 0 }
10241 };
10242
10243 static void test_dialog_messages(void)
10244 {
10245     WNDCLASS cls;
10246     HWND hdlg, hedit1, hedit2, hfocus;
10247     LRESULT ret;
10248
10249 #define set_selection(hctl, start, end) \
10250     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10251     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10252
10253 #define check_selection(hctl, start, end) \
10254     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10255     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10256
10257     subclass_edit();
10258
10259     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10260                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10261                           0, 0, 100, 100, 0, 0, 0, NULL);
10262     ok(hdlg != 0, "Failed to create custom dialog window\n");
10263
10264     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10265                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10266                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10267     ok(hedit1 != 0, "Failed to create edit control\n");
10268     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10269                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10270                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10271     ok(hedit2 != 0, "Failed to create edit control\n");
10272
10273     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10274     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10275
10276     hfocus = GetFocus();
10277     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10278
10279     SetFocus(hedit2);
10280     hfocus = GetFocus();
10281     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10282
10283     check_selection(hedit1, 0, 0);
10284     check_selection(hedit2, 0, 0);
10285
10286     set_selection(hedit2, 0, -1);
10287     check_selection(hedit2, 0, 3);
10288
10289     SetFocus(0);
10290     hfocus = GetFocus();
10291     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10292
10293     flush_sequence();
10294     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10295     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10296     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10297
10298     hfocus = GetFocus();
10299     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10300
10301     check_selection(hedit1, 0, 5);
10302     check_selection(hedit2, 0, 3);
10303
10304     flush_sequence();
10305     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10306     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10307     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10308
10309     hfocus = GetFocus();
10310     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10311
10312     check_selection(hedit1, 0, 5);
10313     check_selection(hedit2, 0, 3);
10314
10315     EndDialog(hdlg, 0);
10316     DestroyWindow(hedit1);
10317     DestroyWindow(hedit2);
10318     DestroyWindow(hdlg);
10319     flush_sequence();
10320
10321 #undef set_selection
10322 #undef check_selection
10323
10324     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10325     cls.lpszClassName = "MyDialogClass";
10326     cls.hInstance = GetModuleHandle(0);
10327     /* need a cast since a dlgproc is used as a wndproc */
10328     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10329     if (!RegisterClass(&cls)) assert(0);
10330
10331     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10332     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10333     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10334     EndDialog(hdlg, 0);
10335     DestroyWindow(hdlg);
10336     flush_sequence();
10337
10338     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10339     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10340     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10341     EndDialog(hdlg, 0);
10342     DestroyWindow(hdlg);
10343     flush_sequence();
10344
10345     UnregisterClass(cls.lpszClassName, cls.hInstance);
10346 }
10347
10348 static void test_nullCallback(void)
10349 {
10350     HWND hwnd;
10351
10352     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10353                            100, 100, 200, 200, 0, 0, 0, NULL);
10354     ok (hwnd != 0, "Failed to create overlapped window\n");
10355
10356     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10357     flush_events();
10358     DestroyWindow(hwnd);
10359 }
10360
10361 /* SetActiveWindow( 0 ) hwnd visible */
10362 static const struct message SetActiveWindowSeq0[] =
10363 {
10364     { HCBT_ACTIVATE, hook },
10365     { WM_NCACTIVATE, sent|wparam, 0 },
10366     { WM_GETTEXT, sent|defwinproc|optional },
10367     { WM_ACTIVATE, sent|wparam, 0 },
10368     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10369     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10370     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10371     { WM_NCACTIVATE, sent|wparam, 1 },
10372     { WM_GETTEXT, sent|defwinproc|optional },
10373     { WM_ACTIVATE, sent|wparam, 1 },
10374     { HCBT_SETFOCUS, hook },
10375     { WM_KILLFOCUS, sent|defwinproc },
10376     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10377     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10378     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10379     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10380     { WM_SETFOCUS, sent|defwinproc },
10381     { WM_GETTEXT, sent|optional },
10382     { 0 }
10383 };
10384 /* SetActiveWindow( hwnd ) hwnd visible */
10385 static const struct message SetActiveWindowSeq1[] =
10386 {
10387     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10388     { 0 }
10389 };
10390 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10391 static const struct message SetActiveWindowSeq2[] =
10392 {
10393     { HCBT_ACTIVATE, hook },
10394     { WM_NCACTIVATE, sent|wparam, 0 },
10395     { WM_GETTEXT, sent|defwinproc|optional },
10396     { WM_ACTIVATE, sent|wparam, 0 },
10397     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10398     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10399     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10400     { WM_NCPAINT, sent|optional },
10401     { WM_GETTEXT, sent|defwinproc|optional },
10402     { WM_ERASEBKGND, sent|optional },
10403     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10404     { WM_NCACTIVATE, sent|wparam, 1 },
10405     { WM_GETTEXT, sent|defwinproc|optional },
10406     { WM_ACTIVATE, sent|wparam, 1 },
10407     { HCBT_SETFOCUS, hook },
10408     { WM_KILLFOCUS, sent|defwinproc },
10409     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10410     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10411     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10412     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10413     { WM_SETFOCUS, sent|defwinproc },
10414     { WM_GETTEXT, sent|optional },
10415     { 0 }
10416 };
10417
10418 /* SetActiveWindow( hwnd ) hwnd not visible */
10419 static const struct message SetActiveWindowSeq3[] =
10420 {
10421     { HCBT_ACTIVATE, hook },
10422     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10423     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10424     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10425     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10426     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10427     { WM_ACTIVATEAPP, sent|wparam, 1 },
10428     { WM_ACTIVATEAPP, sent|wparam, 1 },
10429     { WM_NCACTIVATE, sent|wparam, 1 },
10430     { WM_ACTIVATE, sent|wparam, 1 },
10431     { HCBT_SETFOCUS, hook },
10432     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10433     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10434     { WM_SETFOCUS, sent|defwinproc },
10435     { 0 }
10436 };
10437 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10438 static const struct message SetActiveWindowSeq4[] =
10439 {
10440     { HCBT_ACTIVATE, hook },
10441     { WM_NCACTIVATE, sent|wparam, 0 },
10442     { WM_GETTEXT, sent|defwinproc|optional },
10443     { WM_ACTIVATE, sent|wparam, 0 },
10444     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10445     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10446     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10447     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10448     { WM_NCACTIVATE, sent|wparam, 1 },
10449     { WM_GETTEXT, sent|defwinproc|optional },
10450     { WM_ACTIVATE, sent|wparam, 1 },
10451     { HCBT_SETFOCUS, hook },
10452     { WM_KILLFOCUS, sent|defwinproc },
10453     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10454     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10455     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10456     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10457     { WM_SETFOCUS, sent|defwinproc },
10458     { 0 }
10459 };
10460
10461
10462 static void test_SetActiveWindow(void)
10463 {
10464     HWND hwnd, popup, ret;
10465
10466     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10467                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10468                            100, 100, 200, 200, 0, 0, 0, NULL);
10469
10470     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10471                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10472                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10473
10474     ok(hwnd != 0, "Failed to create overlapped window\n");
10475     ok(popup != 0, "Failed to create popup window\n");
10476     SetForegroundWindow( popup );
10477     flush_sequence();
10478
10479     trace("SetActiveWindow(0)\n");
10480     ret = SetActiveWindow(0);
10481     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10482     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10483     flush_sequence();
10484
10485     trace("SetActiveWindow(hwnd), hwnd visible\n");
10486     ret = SetActiveWindow(hwnd);
10487     todo_wine
10488     {
10489         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10490     }
10491     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10492     flush_sequence();
10493
10494     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10495     ret = SetActiveWindow(popup);
10496     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10497     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10498     flush_sequence();
10499
10500     ShowWindow(hwnd, SW_HIDE);
10501     ShowWindow(popup, SW_HIDE);
10502     flush_sequence();
10503
10504     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10505     ret = SetActiveWindow(hwnd);
10506     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10507     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10508     flush_sequence();
10509
10510     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10511     ret = SetActiveWindow(popup);
10512     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10513     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10514     flush_sequence();
10515
10516     trace("done\n");
10517
10518     DestroyWindow(hwnd);
10519 }
10520
10521 static const struct message SetForegroundWindowSeq[] =
10522 {
10523     { WM_NCACTIVATE, sent|wparam, 0 },
10524     { WM_GETTEXT, sent|defwinproc|optional },
10525     { WM_ACTIVATE, sent|wparam, 0 },
10526     { WM_ACTIVATEAPP, sent|wparam, 0 },
10527     { WM_KILLFOCUS, sent },
10528     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10529     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10530     { 0 }
10531 };
10532
10533 static void test_SetForegroundWindow(void)
10534 {
10535     HWND hwnd;
10536
10537     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10538                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10539                            100, 100, 200, 200, 0, 0, 0, NULL);
10540     ok (hwnd != 0, "Failed to create overlapped window\n");
10541     flush_sequence();
10542
10543     trace("SetForegroundWindow( 0 )\n");
10544     SetForegroundWindow( 0 );
10545     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10546     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10547     SetForegroundWindow( GetDesktopWindow() );
10548     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10549                                         "foreground top level window", FALSE);
10550     trace("done\n");
10551
10552     DestroyWindow(hwnd);
10553 }
10554
10555 static void test_dbcs_wm_char(void)
10556 {
10557     BYTE dbch[2];
10558     WCHAR wch, bad_wch;
10559     HWND hwnd, hwnd2;
10560     MSG msg;
10561     DWORD time;
10562     POINT pt;
10563     DWORD_PTR res;
10564     CPINFOEXA cpinfo;
10565     UINT i, j, k;
10566     struct message wmCharSeq[2];
10567
10568     if (!pGetCPInfoExA)
10569     {
10570         skip("GetCPInfoExA is not available\n");
10571         return;
10572     }
10573
10574     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10575     if (cpinfo.MaxCharSize != 2)
10576     {
10577         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10578         return;
10579     }
10580
10581     dbch[0] = dbch[1] = 0;
10582     wch = 0;
10583     bad_wch = cpinfo.UnicodeDefaultChar;
10584     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10585         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10586             for (k = 128; k <= 255; k++)
10587             {
10588                 char str[2];
10589                 WCHAR wstr[2];
10590                 str[0] = j;
10591                 str[1] = k;
10592                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10593                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10594                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10595                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10596                 {
10597                     dbch[0] = j;
10598                     dbch[1] = k;
10599                     wch = wstr[0];
10600                     break;
10601                 }
10602             }
10603
10604     if (!wch)
10605     {
10606         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10607         return;
10608     }
10609     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10610            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10611
10612     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10613                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10614     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10615                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10616     ok (hwnd != 0, "Failed to create overlapped window\n");
10617     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10618     flush_sequence();
10619
10620     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10621     wmCharSeq[0].message = WM_CHAR;
10622     wmCharSeq[0].flags = sent|wparam;
10623     wmCharSeq[0].wParam = wch;
10624
10625     /* posted message */
10626     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10627     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10628     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10629     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10630     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10631     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10632     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10633
10634     /* posted thread message */
10635     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10636     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10637     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10638     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10639     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10640     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10641     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10642
10643     /* sent message */
10644     flush_sequence();
10645     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10646     ok_sequence( WmEmptySeq, "no messages", FALSE );
10647     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10648     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10649     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10650
10651     /* sent message with timeout */
10652     flush_sequence();
10653     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10654     ok_sequence( WmEmptySeq, "no messages", FALSE );
10655     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10656     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10657     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10658
10659     /* sent message with timeout and callback */
10660     flush_sequence();
10661     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10662     ok_sequence( WmEmptySeq, "no messages", FALSE );
10663     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10664     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10665     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10666
10667     /* sent message with callback */
10668     flush_sequence();
10669     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10670     ok_sequence( WmEmptySeq, "no messages", FALSE );
10671     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10672     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10673     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10674
10675     /* direct window proc call */
10676     flush_sequence();
10677     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10678     ok_sequence( WmEmptySeq, "no messages", FALSE );
10679     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10680     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10681
10682     /* dispatch message */
10683     msg.hwnd = hwnd;
10684     msg.message = WM_CHAR;
10685     msg.wParam = dbch[0];
10686     msg.lParam = 0;
10687     DispatchMessageA( &msg );
10688     ok_sequence( WmEmptySeq, "no messages", FALSE );
10689     msg.wParam = dbch[1];
10690     DispatchMessageA( &msg );
10691     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10692
10693     /* window handle is irrelevant */
10694     flush_sequence();
10695     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10696     ok_sequence( WmEmptySeq, "no messages", FALSE );
10697     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10698     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10699     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10700
10701     /* interleaved post and send */
10702     flush_sequence();
10703     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10704     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10705     ok_sequence( WmEmptySeq, "no messages", FALSE );
10706     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10707     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10708     ok_sequence( WmEmptySeq, "no messages", FALSE );
10709     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10710     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10711     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10712     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10713     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10714     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10715     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10716
10717     /* interleaved sent message and winproc */
10718     flush_sequence();
10719     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10720     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10721     ok_sequence( WmEmptySeq, "no messages", FALSE );
10722     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10723     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10724     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10725     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10726
10727     /* interleaved winproc and dispatch */
10728     msg.hwnd = hwnd;
10729     msg.message = WM_CHAR;
10730     msg.wParam = dbch[0];
10731     msg.lParam = 0;
10732     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10733     DispatchMessageA( &msg );
10734     ok_sequence( WmEmptySeq, "no messages", FALSE );
10735     msg.wParam = dbch[1];
10736     DispatchMessageA( &msg );
10737     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10738     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10739     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10740
10741     /* interleaved sends */
10742     flush_sequence();
10743     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10744     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10745     ok_sequence( WmEmptySeq, "no messages", FALSE );
10746     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10747     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10748     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10749     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10750
10751     /* dbcs WM_CHAR */
10752     flush_sequence();
10753     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10754     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10755     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10756
10757     /* other char messages are not magic */
10758     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10759     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10760     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10761     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10762     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10763     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10764     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10765     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10766     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10767     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10768
10769     /* test retrieving messages */
10770
10771     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10772     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10773     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10774     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10775     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10776     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10777     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10778     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10779     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10780     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10781
10782     /* message filters */
10783     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10784     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10785     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10786     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10787     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10788     /* message id is filtered, hwnd is not */
10789     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10790     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10791     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10792     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10793     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10794     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10795
10796     /* mixing GetMessage and PostMessage */
10797     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10798     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10799     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10800     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10801     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10802     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10803     time = msg.time;
10804     pt = msg.pt;
10805     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10806     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10807     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10808     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10809     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10810     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10811     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10812     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 );
10813     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10814
10815     /* without PM_REMOVE */
10816     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10817     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10818     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10819     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10820     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10821     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10822     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10823     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10824     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10825     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10826     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10827     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10828     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10829     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10830     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10831     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10832     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10833     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10834
10835     DestroyWindow(hwnd);
10836 }
10837
10838 #define ID_LISTBOX 0x000f
10839
10840 static const struct message wm_lb_setcursel_0[] =
10841 {
10842     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10843     { WM_CTLCOLORLISTBOX, sent|parent },
10844     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10845     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10846     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10847     { 0 }
10848 };
10849 static const struct message wm_lb_setcursel_1[] =
10850 {
10851     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10852     { WM_CTLCOLORLISTBOX, sent|parent },
10853     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10854     { WM_CTLCOLORLISTBOX, sent|parent },
10855     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10856     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10857     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10858     { 0 }
10859 };
10860 static const struct message wm_lb_setcursel_2[] =
10861 {
10862     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10863     { WM_CTLCOLORLISTBOX, sent|parent },
10864     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10865     { WM_CTLCOLORLISTBOX, sent|parent },
10866     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10867     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10868     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10869     { 0 }
10870 };
10871 static const struct message wm_lb_click_0[] =
10872 {
10873     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10874     { HCBT_SETFOCUS, hook },
10875     { WM_KILLFOCUS, sent|parent },
10876     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10877     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10878     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10879     { WM_SETFOCUS, sent|defwinproc },
10880
10881     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10882     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10883     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10884     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10885     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10886
10887     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10888     { WM_CTLCOLORLISTBOX, sent|parent },
10889     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10890     { WM_CTLCOLORLISTBOX, sent|parent },
10891     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10892     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10893
10894     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10895     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10896
10897     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10898     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10899     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10900     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10901     { 0 }
10902 };
10903
10904 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10905
10906 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10907
10908 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10909 {
10910     static long defwndproc_counter = 0;
10911     LRESULT ret;
10912     struct recvd_message msg;
10913
10914     /* do not log painting messages */
10915     if (message != WM_PAINT &&
10916         message != WM_NCPAINT &&
10917         message != WM_SYNCPAINT &&
10918         message != WM_ERASEBKGND &&
10919         message != WM_NCHITTEST &&
10920         message != WM_GETTEXT &&
10921         message != WM_GETOBJECT &&
10922         message != WM_GETICON &&
10923         message != WM_DEVICECHANGE)
10924     {
10925         msg.hwnd = hwnd;
10926         msg.message = message;
10927         msg.flags = sent|wparam|lparam;
10928         if (defwndproc_counter) msg.flags |= defwinproc;
10929         msg.wParam = wp;
10930         msg.lParam = lp;
10931         msg.descr = "listbox";
10932         add_message(&msg);
10933     }
10934
10935     defwndproc_counter++;
10936     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10937     defwndproc_counter--;
10938
10939     return ret;
10940 }
10941
10942 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10943                                int caret_index, int top_index, int line)
10944 {
10945     LRESULT ret;
10946
10947     /* calling an orig proc helps to avoid unnecessary message logging */
10948     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10949     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10950     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10951     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10952     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10953     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10954     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10955     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10956 }
10957
10958 static void test_listbox_messages(void)
10959 {
10960     HWND parent, listbox;
10961     LRESULT ret;
10962
10963     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10964                              100, 100, 200, 200, 0, 0, 0, NULL);
10965     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10966                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10967                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10968     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10969
10970     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10971
10972     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10973     ok(ret == 0, "expected 0, got %ld\n", ret);
10974     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10975     ok(ret == 1, "expected 1, got %ld\n", ret);
10976     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10977     ok(ret == 2, "expected 2, got %ld\n", ret);
10978
10979     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10980
10981     flush_sequence();
10982
10983     log_all_parent_messages++;
10984
10985     trace("selecting item 0\n");
10986     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10987     ok(ret == 0, "expected 0, got %ld\n", ret);
10988     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10989     check_lb_state(listbox, 3, 0, 0, 0);
10990     flush_sequence();
10991
10992     trace("selecting item 1\n");
10993     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10994     ok(ret == 1, "expected 1, got %ld\n", ret);
10995     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10996     check_lb_state(listbox, 3, 1, 1, 0);
10997
10998     trace("selecting item 2\n");
10999     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11000     ok(ret == 2, "expected 2, got %ld\n", ret);
11001     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11002     check_lb_state(listbox, 3, 2, 2, 0);
11003
11004     trace("clicking on item 0\n");
11005     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11006     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11007     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11008     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11009     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11010     check_lb_state(listbox, 3, 0, 0, 0);
11011     flush_sequence();
11012
11013     log_all_parent_messages--;
11014
11015     DestroyWindow(listbox);
11016     DestroyWindow(parent);
11017 }
11018
11019 /*************************** Menu test ******************************/
11020 static const struct message wm_popup_menu_1[] =
11021 {
11022     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11023     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11024     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11025     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11026     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11027     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11028     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11029     { WM_INITMENU, sent|lparam, 0, 0 },
11030     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11031     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11032     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11033     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11034     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11035     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11036     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11037     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11038     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11039     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11040     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11041     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11042     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11043     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11044     { 0 }
11045 };
11046 static const struct message wm_popup_menu_2[] =
11047 {
11048     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11049     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11050     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11051     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11052     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11053     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11054     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11055     { WM_INITMENU, sent|lparam, 0, 0 },
11056     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11057     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11058     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11059     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11060     { HCBT_CREATEWND, hook },
11061     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11062                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11063     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11064     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11065     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11066     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11067     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11068     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11069     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11070     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11071     { HCBT_DESTROYWND, hook },
11072     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11073     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11074     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11075     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11076     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11077     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11078     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11079     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11080     { 0 }
11081 };
11082 static const struct message wm_popup_menu_3[] =
11083 {
11084     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11085     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11086     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11087     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11088     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11089     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11090     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11091     { WM_INITMENU, sent|lparam, 0, 0 },
11092     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11093     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11094     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11095     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11096     { HCBT_CREATEWND, hook },
11097     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11098                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11099     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11100     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11101     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11102     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11103     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11104     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11105     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11106     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11107     { HCBT_DESTROYWND, hook },
11108     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11109     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11110     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11111     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11112     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11113     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11114     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11115     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11116     { 0 }
11117 };
11118
11119 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11120 {
11121     if (message == WM_ENTERIDLE ||
11122         message == WM_INITMENU ||
11123         message == WM_INITMENUPOPUP ||
11124         message == WM_MENUSELECT ||
11125         message == WM_PARENTNOTIFY ||
11126         message == WM_ENTERMENULOOP ||
11127         message == WM_EXITMENULOOP ||
11128         message == WM_UNINITMENUPOPUP ||
11129         message == WM_KEYDOWN ||
11130         message == WM_KEYUP ||
11131         message == WM_CHAR ||
11132         message == WM_SYSKEYDOWN ||
11133         message == WM_SYSKEYUP ||
11134         message == WM_SYSCHAR ||
11135         message == WM_COMMAND ||
11136         message == WM_MENUCOMMAND)
11137     {
11138         struct recvd_message msg;
11139
11140         msg.hwnd = hwnd;
11141         msg.message = message;
11142         msg.flags = sent|wparam|lparam;
11143         msg.wParam = wp;
11144         msg.lParam = lp;
11145         msg.descr = "parent_menu_proc";
11146         add_message(&msg);
11147     }
11148
11149     return DefWindowProcA(hwnd, message, wp, lp);
11150 }
11151
11152 static void set_menu_style(HMENU hmenu, DWORD style)
11153 {
11154     MENUINFO mi;
11155     BOOL ret;
11156
11157     mi.cbSize = sizeof(mi);
11158     mi.fMask = MIM_STYLE;
11159     mi.dwStyle = style;
11160     SetLastError(0xdeadbeef);
11161     ret = pSetMenuInfo(hmenu, &mi);
11162     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11163 }
11164
11165 static DWORD get_menu_style(HMENU hmenu)
11166 {
11167     MENUINFO mi;
11168     BOOL ret;
11169
11170     mi.cbSize = sizeof(mi);
11171     mi.fMask = MIM_STYLE;
11172     mi.dwStyle = 0;
11173     SetLastError(0xdeadbeef);
11174     ret = pGetMenuInfo(hmenu, &mi);
11175     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11176
11177     return mi.dwStyle;
11178 }
11179
11180 static void test_menu_messages(void)
11181 {
11182     MSG msg;
11183     WNDCLASSA cls;
11184     HMENU hmenu, hmenu_popup;
11185     HWND hwnd;
11186     DWORD style;
11187
11188     if (!pGetMenuInfo || !pSetMenuInfo)
11189     {
11190         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11191         return;
11192     }
11193     cls.style = 0;
11194     cls.lpfnWndProc = parent_menu_proc;
11195     cls.cbClsExtra = 0;
11196     cls.cbWndExtra = 0;
11197     cls.hInstance = GetModuleHandleA(0);
11198     cls.hIcon = 0;
11199     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11200     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11201     cls.lpszMenuName = NULL;
11202     cls.lpszClassName = "TestMenuClass";
11203     UnregisterClass(cls.lpszClassName, cls.hInstance);
11204     if (!RegisterClassA(&cls)) assert(0);
11205
11206     SetLastError(0xdeadbeef);
11207     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11208                            100, 100, 200, 200, 0, 0, 0, NULL);
11209     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11210
11211     SetLastError(0xdeadbeef);
11212     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11213     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11214
11215     SetMenu(hwnd, hmenu);
11216     SetForegroundWindow( hwnd );
11217
11218     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11219     style = get_menu_style(hmenu);
11220     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11221
11222     hmenu_popup = GetSubMenu(hmenu, 0);
11223     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11224     style = get_menu_style(hmenu_popup);
11225     ok(style == 0, "expected 0, got %u\n", style);
11226
11227     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11228     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11229     style = get_menu_style(hmenu_popup);
11230     ok(style == 0, "expected 0, got %u\n", style);
11231
11232     /* Alt+E, Enter */
11233     trace("testing a popup menu command\n");
11234     flush_sequence();
11235     keybd_event(VK_MENU, 0, 0, 0);
11236     keybd_event('E', 0, 0, 0);
11237     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11238     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11239     keybd_event(VK_RETURN, 0, 0, 0);
11240     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11241     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11242     {
11243         TranslateMessage(&msg);
11244         DispatchMessage(&msg);
11245     }
11246     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11247
11248     /* Alt+F, Right, Enter */
11249     trace("testing submenu of a popup menu command\n");
11250     flush_sequence();
11251     keybd_event(VK_MENU, 0, 0, 0);
11252     keybd_event('F', 0, 0, 0);
11253     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11254     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11255     keybd_event(VK_RIGHT, 0, 0, 0);
11256     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11257     keybd_event(VK_RETURN, 0, 0, 0);
11258     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11259     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11260     {
11261         TranslateMessage(&msg);
11262         DispatchMessage(&msg);
11263     }
11264     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11265
11266     set_menu_style(hmenu, 0);
11267     style = get_menu_style(hmenu);
11268     ok(style == 0, "expected 0, got %u\n", style);
11269
11270     hmenu_popup = GetSubMenu(hmenu, 0);
11271     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11272     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11273     style = get_menu_style(hmenu_popup);
11274     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11275
11276     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11277     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11278     style = get_menu_style(hmenu_popup);
11279     ok(style == 0, "expected 0, got %u\n", style);
11280
11281     /* Alt+F, Right, Enter */
11282     trace("testing submenu of a popup menu command\n");
11283     flush_sequence();
11284     keybd_event(VK_MENU, 0, 0, 0);
11285     keybd_event('F', 0, 0, 0);
11286     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11287     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11288     keybd_event(VK_RIGHT, 0, 0, 0);
11289     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11290     keybd_event(VK_RETURN, 0, 0, 0);
11291     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11292     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11293     {
11294         TranslateMessage(&msg);
11295         DispatchMessage(&msg);
11296     }
11297     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11298
11299     DestroyWindow(hwnd);
11300     DestroyMenu(hmenu);
11301 }
11302
11303
11304 static void test_paintingloop(void)
11305 {
11306     HWND hwnd;
11307
11308     paint_loop_done = 0;
11309     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11310                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11311                                 100, 100, 100, 100, 0, 0, 0, NULL );
11312     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11313     ShowWindow(hwnd,SW_NORMAL);
11314     SetFocus(hwnd);
11315
11316     while (!paint_loop_done)
11317     {
11318         MSG msg;
11319         if (PeekMessageA(&msg, 0, 0, 0, 1))
11320         {
11321             TranslateMessage(&msg);
11322             DispatchMessage(&msg);
11323         }
11324     }
11325     DestroyWindow(hwnd);
11326 }
11327
11328 START_TEST(msg)
11329 {
11330     BOOL ret;
11331     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11332
11333     init_procs();
11334
11335     if (!RegisterWindowClasses()) assert(0);
11336
11337     if (pSetWinEventHook)
11338     {
11339         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11340                                                       GetModuleHandleA(0),
11341                                                       win_event_proc,
11342                                                       0,
11343                                                       GetCurrentThreadId(),
11344                                                       WINEVENT_INCONTEXT);
11345         assert(hEvent_hook);
11346
11347         if (pIsWinEventHookInstalled)
11348         {
11349             UINT event;
11350             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11351                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11352         }
11353     }
11354
11355     cbt_hook_thread_id = GetCurrentThreadId();
11356     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11357     if (!hCBT_hook) skip( "cannot set global hook, will skip hook tests\n" );
11358
11359     test_winevents();
11360
11361     /* Fix message sequences before removing 4 lines below */
11362 #if 1
11363     if (pUnhookWinEvent && hEvent_hook)
11364     {
11365         ret = pUnhookWinEvent(hEvent_hook);
11366         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11367         pUnhookWinEvent = 0;
11368     }
11369     hEvent_hook = 0;
11370 #endif
11371
11372     test_ShowWindow();
11373     test_PeekMessage();
11374     test_PeekMessage2();
11375     test_scrollwindowex();
11376     test_messages();
11377     test_setwindowpos();
11378     test_showwindow();
11379     invisible_parent_tests();
11380     test_mdi_messages();
11381     test_button_messages();
11382     test_static_messages();
11383     test_listbox_messages();
11384     test_combobox_messages();
11385     test_wmime_keydown_message();
11386     test_paint_messages();
11387     test_interthread_messages();
11388     test_message_conversion();
11389     test_accelerators();
11390     test_timers();
11391     test_timers_no_wnd();
11392     if (hCBT_hook) test_set_hook();
11393     test_DestroyWindow();
11394     test_DispatchMessage();
11395     test_SendMessageTimeout();
11396     test_edit_messages();
11397     test_quit_message();
11398     test_SetActiveWindow();
11399
11400     if (!pTrackMouseEvent)
11401         skip("TrackMouseEvent is not available\n");
11402     else
11403         test_TrackMouseEvent();
11404
11405     test_SetWindowRgn();
11406     test_sys_menu();
11407     test_dialog_messages();
11408     test_nullCallback();
11409     test_dbcs_wm_char();
11410     test_menu_messages();
11411     test_paintingloop();
11412     /* keep it the last test, under Windows it tends to break the tests
11413      * which rely on active/foreground windows being correct.
11414      */
11415     test_SetForegroundWindow();
11416
11417     UnhookWindowsHookEx(hCBT_hook);
11418     if (pUnhookWinEvent)
11419     {
11420         ret = pUnhookWinEvent(hEvent_hook);
11421         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11422         SetLastError(0xdeadbeef);
11423         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11424         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11425            GetLastError() == 0xdeadbeef, /* Win9x */
11426            "unexpected error %d\n", GetLastError());
11427     }
11428     else
11429         skip("UnhookWinEvent is not available\n");
11430 }