user32: Move a few 16-bit stubs to user16.c.
[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 },
165     { WM_GETTEXT, sent|defwinproc|optional },
166     { WM_ACTIVATE, sent|wparam, 1 },
167     { HCBT_SETFOCUS, hook },
168     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
169     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
170     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
171     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
172     { WM_GETTEXT, sent|optional },
173     { WM_NCPAINT, sent|wparam|optional, 1 },
174     { WM_GETTEXT, sent|defwinproc|optional },
175     { WM_ERASEBKGND, sent|optional },
176     /* Win9x adds SWP_NOZORDER below */
177     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
178     { WM_GETTEXT, sent|optional },
179     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
180     { WM_NCPAINT, sent|wparam|optional, 1 },
181     { WM_ERASEBKGND, sent|optional },
182     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
183     { WM_SYNCPAINT, sent|optional },
184     { WM_GETTITLEBARINFOEX, sent|optional },
185     { WM_PAINT, sent|optional },
186     { WM_NCPAINT, sent|beginpaint|optional },
187     { WM_GETTEXT, sent|defwinproc|optional },
188     { WM_ERASEBKGND, sent|beginpaint|optional },
189     { 0 }
190 };
191 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
192  * for a visible overlapped window.
193  */
194 static const struct message WmSWP_HideOverlappedSeq[] = {
195     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
196     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
197     { HCBT_ACTIVATE, hook|optional },
198     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
199     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
200     { WM_NCACTIVATE, sent|optional },
201     { WM_ACTIVATE, sent|optional },
202     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
203     { 0 }
204 };
205
206 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
207  * for a visible overlapped window.
208  */
209 static const struct message WmSWP_ResizeSeq[] = {
210     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
211     { WM_GETMINMAXINFO, sent|defwinproc },
212     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
213     { WM_NCPAINT, sent|optional },
214     { WM_GETTEXT, sent|defwinproc|optional },
215     { WM_ERASEBKGND, sent|optional },
216     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
217     { WM_SIZE, sent|defwinproc|optional },
218     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
219     { WM_NCPAINT, sent|optional },
220     { WM_GETTEXT, sent|defwinproc|optional },
221     { WM_ERASEBKGND, sent|optional },
222     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
223     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
224     { 0 }
225 };
226
227 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
228  * for a visible popup window.
229  */
230 static const struct message WmSWP_ResizePopupSeq[] = {
231     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
232     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
233     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
234     { WM_NCPAINT, sent|optional },
235     { WM_GETTEXT, sent|defwinproc|optional },
236     { WM_ERASEBKGND, sent|optional },
237     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
238     { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
239     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
240     { WM_NCPAINT, sent|optional },
241     { WM_GETTEXT, sent|defwinproc|optional },
242     { WM_ERASEBKGND, sent|optional },
243     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
244     { 0 }
245 };
246
247 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
248  * for a visible overlapped window.
249  */
250 static const struct message WmSWP_MoveSeq[] = {
251     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
252     { WM_NCPAINT, sent|optional },
253     { WM_GETTEXT, sent|defwinproc|optional },
254     { WM_ERASEBKGND, sent|optional },
255     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
256     { WM_MOVE, sent|defwinproc|wparam, 0 },
257     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
258     { 0 }
259 };
260 /* Resize with SetWindowPos(SWP_NOZORDER)
261  * for a visible overlapped window
262  * SWP_NOZORDER is stripped by the logging code
263  */
264 static const struct message WmSWP_ResizeNoZOrder[] = {
265     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
266     { WM_GETMINMAXINFO, sent|defwinproc },
267     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
268     { WM_NCPAINT, sent|optional },
269     { WM_GETTEXT, sent|defwinproc|optional },
270     { WM_ERASEBKGND, sent|optional },
271     { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
272       SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
273     { WM_MOVE, sent|defwinproc|optional },
274     { WM_SIZE, sent|defwinproc|optional },
275     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
276     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
277     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
278     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
279     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
280     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281     { 0 }
282 };
283
284 /* Switch visible mdi children */
285 static const struct message WmSwitchChild[] = {
286     /* Switch MDI child */
287     { WM_MDIACTIVATE, sent },/* in the MDI client */
288     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
289     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
290     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
291     /* Deactivate 2nd MDI child */
292     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
293     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
294     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
295     /* Preparing for maximize and maximaze the 1st MDI child */
296     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
297     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
298     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
299     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
300     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
301     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
302     /* Lock redraw 2nd MDI child */
303     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
304     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
305     /* Restore 2nd MDI child */
306     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
307     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
308     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
309     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
310     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
311     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312     /* Redraw 2nd MDI child */
313     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
314     /* Redraw MDI frame */
315     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
316     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
317     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
318     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
319     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
320     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
321     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
322     { HCBT_SETFOCUS, hook },
323     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
324     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
325     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
326     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
327     { WM_SETFOCUS, sent },/* in the MDI client */
328     { HCBT_SETFOCUS, hook },
329     { WM_KILLFOCUS, sent },/* in the MDI client */
330     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
331     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
332     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
333     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
334     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
335     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
336     { 0 }
337 };
338
339 /* Switch visible not maximized mdi children */
340 static const struct message WmSwitchNotMaximizedChild[] = {
341     /* Switch not maximized MDI child */
342     { WM_MDIACTIVATE, sent },/* in the MDI client */
343     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
344     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
345     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
346     /* Deactivate 1st MDI child */
347     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
348     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
349     /* Activate 2nd MDI child */
350     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
351     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
352     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
353     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
354     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
355     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
356     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
357     { HCBT_SETFOCUS, hook },
358     { WM_KILLFOCUS, sent }, /* in the  MDI client */
359     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
360     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
361     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
362     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
363     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
364     { 0 }
365 };
366
367
368 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
369                 SWP_NOZORDER|SWP_FRAMECHANGED)
370  * for a visible overlapped window with WS_CLIPCHILDREN style set.
371  */
372 static const struct message WmSWP_FrameChanged_clip[] = {
373     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
374     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
375     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
376     { WM_GETTEXT, sent|parent|defwinproc|optional },
377     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
378     { WM_NCPAINT, sent }, /* wparam != 1 */
379     { WM_ERASEBKGND, sent },
380     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
382     { WM_PAINT, sent },
383     { 0 }
384 };
385 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
386                 SWP_NOZORDER|SWP_FRAMECHANGED)
387  * for a visible overlapped window.
388  */
389 static const struct message WmSWP_FrameChangedDeferErase[] = {
390     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
391     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
392     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
393     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
394     { WM_PAINT, sent|parent|optional },
395     { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
396     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
397     { WM_PAINT, sent },
398     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
399     { WM_ERASEBKGND, sent|beginpaint|optional },
400     { 0 }
401 };
402
403 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
404                 SWP_NOZORDER|SWP_FRAMECHANGED)
405  * for a visible overlapped window without WS_CLIPCHILDREN style set.
406  */
407 static const struct message WmSWP_FrameChanged_noclip[] = {
408     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
409     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
410     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
411     { WM_GETTEXT, sent|parent|defwinproc|optional },
412     { WM_ERASEBKGND, sent|parent|optional },
413     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
414     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
415     { WM_PAINT, sent },
416     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
417     { WM_ERASEBKGND, sent|beginpaint|optional },
418     { 0 }
419 };
420
421 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
422 static const struct message WmShowOverlappedSeq[] = {
423     { WM_SHOWWINDOW, sent|wparam, 1 },
424     { WM_NCPAINT, sent|wparam|optional, 1 },
425     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
426     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
427     { WM_NCPAINT, sent|wparam|optional, 1 },
428     { WM_GETTEXT, sent|defwinproc|optional },
429     { WM_ERASEBKGND, sent|optional },
430     { HCBT_ACTIVATE, hook },
431     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
432     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
433     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
434     { WM_NCPAINT, sent|wparam|optional, 1 },
435     { WM_ACTIVATEAPP, sent|wparam, 1 },
436     { WM_NCACTIVATE, sent|wparam, 1 },
437     { WM_GETTEXT, sent|defwinproc|optional },
438     { WM_ACTIVATE, sent|wparam, 1 },
439     { HCBT_SETFOCUS, hook },
440     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
441     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
442     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
443     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
444     { WM_GETTEXT, sent|optional },
445     { WM_NCPAINT, sent|wparam|optional, 1 },
446     { WM_GETTEXT, sent|defwinproc|optional },
447     { WM_ERASEBKGND, sent|optional },
448     /* Win9x adds SWP_NOZORDER below */
449     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
450     { WM_NCCALCSIZE, sent|optional },
451     { WM_GETTEXT, sent|optional },
452     { WM_NCPAINT, sent|optional },
453     { WM_ERASEBKGND, sent|optional },
454     { WM_SYNCPAINT, sent|optional },
455 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
456        * messages. Does that mean that CreateWindow doesn't set initial
457        * window dimensions for overlapped windows?
458        */
459     { WM_SIZE, sent },
460     { WM_MOVE, sent },
461 #endif
462     { WM_PAINT, sent|optional },
463     { WM_NCPAINT, sent|beginpaint|optional },
464     { 0 }
465 };
466 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
467 static const struct message WmShowMaxOverlappedSeq[] = {
468     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
469     { WM_GETMINMAXINFO, sent },
470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
471     { WM_GETMINMAXINFO, sent|defwinproc },
472     { WM_NCCALCSIZE, sent|wparam, TRUE },
473     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
474     { HCBT_ACTIVATE, hook },
475     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
476     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
477     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
478     { WM_ACTIVATEAPP, sent|wparam, 1 },
479     { WM_NCACTIVATE, sent|wparam, 1 },
480     { WM_GETTEXT, sent|defwinproc|optional },
481     { WM_ACTIVATE, sent|wparam, 1 },
482     { HCBT_SETFOCUS, hook },
483     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
484     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
485     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
486     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
487     { WM_GETTEXT, sent|optional },
488     { WM_NCPAINT, sent|wparam|optional, 1 },
489     { WM_GETTEXT, sent|defwinproc|optional },
490     { WM_ERASEBKGND, sent|optional },
491     /* Win9x adds SWP_NOZORDER below */
492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
493     { WM_MOVE, sent|defwinproc },
494     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
495     { WM_GETTEXT, sent|optional },
496     { WM_NCCALCSIZE, sent|optional },
497     { WM_NCPAINT, sent|optional },
498     { WM_ERASEBKGND, sent|optional },
499     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
500     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501     { WM_SYNCPAINT, sent|optional },
502     { WM_GETTITLEBARINFOEX, sent|optional },
503     { WM_PAINT, sent|optional },
504     { WM_NCPAINT, sent|beginpaint|optional },
505     { WM_ERASEBKGND, sent|beginpaint|optional },
506     { 0 }
507 };
508 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
509 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
510     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
511     { WM_GETTEXT, sent|optional },
512     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
513     { WM_GETMINMAXINFO, sent|defwinproc },
514     { WM_NCCALCSIZE, sent|wparam, TRUE },
515     { WM_NCPAINT, sent|optional },
516     { WM_GETTEXT, sent|defwinproc|optional },
517     { WM_ERASEBKGND, sent|optional },
518     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
519     { WM_MOVE, sent|defwinproc|optional },
520     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
521     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
522     { WM_NCPAINT, sent|optional },
523     { WM_ERASEBKGND, sent|optional },
524     { WM_PAINT, sent|optional },
525     { WM_GETTITLEBARINFOEX, sent|optional },
526     { WM_NCPAINT, sent|beginpaint|optional },
527     { WM_ERASEBKGND, sent|beginpaint|optional },
528     { 0 }
529 };
530 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
531 static const struct message WmShowRestoreMinOverlappedSeq[] = {
532     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
533     { WM_QUERYOPEN, sent|optional },
534     { WM_GETTEXT, sent|optional },
535     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
536     { WM_GETMINMAXINFO, sent|defwinproc },
537     { WM_NCCALCSIZE, sent|wparam, TRUE },
538     { HCBT_ACTIVATE, hook },
539     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
540     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
541     { WM_ACTIVATEAPP, sent|wparam, 1 },
542     { WM_NCACTIVATE, sent|wparam, 1 },
543     { WM_GETTEXT, sent|defwinproc|optional },
544     { WM_ACTIVATE, sent|wparam, 1 },
545     { HCBT_SETFOCUS, hook },
546     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
547     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
548     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
549     { WM_GETTEXT, sent|optional },
550     { WM_NCPAINT, sent|wparam|optional, 1 },
551     { WM_GETTEXT, sent|defwinproc|optional },
552     { WM_ERASEBKGND, sent },
553     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
554     { WM_MOVE, sent|defwinproc },
555     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
556     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
557     { WM_NCPAINT, sent|wparam|optional, 1 },
558     { WM_ERASEBKGND, sent|optional },
559     { WM_ACTIVATE, sent|wparam, 1 },
560     { WM_GETTEXT, sent|optional },
561     { WM_PAINT, sent|optional },
562     { WM_GETTITLEBARINFOEX, sent|optional },
563     { WM_NCPAINT, sent|beginpaint|optional },
564     { WM_ERASEBKGND, sent|beginpaint|optional },
565     { 0 }
566 };
567 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
568 static const struct message WmShowMinOverlappedSeq[] = {
569     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
570     { HCBT_SETFOCUS, hook },
571     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
572     { WM_KILLFOCUS, sent },
573     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
574     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
575     { WM_GETTEXT, sent|optional },
576     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
577     { WM_GETMINMAXINFO, sent|defwinproc },
578     { WM_NCCALCSIZE, sent|wparam, TRUE },
579     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
580     { WM_NCPAINT, sent|optional },
581     { WM_GETTEXT, sent|defwinproc|optional },
582     { WM_WINDOWPOSCHANGED, sent },
583     { WM_MOVE, sent|defwinproc },
584     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
585     { WM_NCCALCSIZE, sent|optional },
586     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
587     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
589     { WM_NCACTIVATE, sent|wparam, 0 },
590     { WM_GETTEXT, sent|defwinproc|optional },
591     { WM_ACTIVATE, sent },
592     { WM_ACTIVATEAPP, sent|wparam, 0 },
593
594     /* Vista sometimes restores the window right away... */
595     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
596     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
597     { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
598     { WM_QUERYOPEN, sent|optional },
599     { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
600     { WM_GETMINMAXINFO, sent|optional|defwinproc },
601     { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
602     { HCBT_ACTIVATE, hook|optional },
603     { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
604     { WM_NCACTIVATE, sent|optional },
605     { WM_GETTEXT, sent|optional },
606     { WM_ACTIVATE, sent|optional|wparam, 1 },
607     { HCBT_SETFOCUS, hook|optional },
608     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
609     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
610     { WM_SETFOCUS, sent|optional },
611     { WM_NCPAINT, sent|optional },
612     { WM_GETTEXT, sent|defwinproc|optional },
613     { WM_ERASEBKGND, sent|optional },
614     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
615     { WM_MOVE, sent|defwinproc|optional },
616     { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
617     { WM_ACTIVATE, sent|optional|wparam, 1 },
618     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
619     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
620
621     { WM_PAINT, sent|optional },
622     { WM_NCPAINT, sent|beginpaint|optional },
623     { WM_ERASEBKGND, sent|beginpaint|optional },
624     { 0 }
625 };
626 /* ShowWindow(SW_HIDE) for a visible overlapped window */
627 static const struct message WmHideOverlappedSeq[] = {
628     { WM_SHOWWINDOW, sent|wparam, 0 },
629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
630     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
631     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
632     { WM_SIZE, sent|optional }, /* XP doesn't send it */
633     { WM_MOVE, sent|optional }, /* XP doesn't send it */
634     { WM_NCACTIVATE, sent|wparam|optional, 0 },
635     { WM_ACTIVATE, sent|wparam|optional, 0 },
636     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
637     { HCBT_SETFOCUS, hook|optional },
638     { WM_KILLFOCUS, sent|wparam, 0 },
639     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
640     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
641     { 0 }
642 };
643 /* DestroyWindow for a visible overlapped window */
644 static const struct message WmDestroyOverlappedSeq[] = {
645     { HCBT_DESTROYWND, hook },
646     { 0x0090, sent|optional },
647     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
648     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
649     { 0x0090, sent|optional },
650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
651     { WM_NCACTIVATE, sent|optional|wparam, 0 },
652     { WM_ACTIVATE, sent|optional },
653     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
654     { WM_KILLFOCUS, sent|optional|wparam, 0 },
655     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
656     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
657     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
658     { WM_DESTROY, sent },
659     { WM_NCDESTROY, sent },
660     { 0 }
661 };
662 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
663 static const struct message WmCreateMaxPopupSeq[] = {
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     { WM_SHOWWINDOW, sent|wparam, 1 },
680     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
681     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
682     { HCBT_ACTIVATE, hook },
683     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
684     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
685     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
686     { WM_NCPAINT, sent|wparam|optional, 1 },
687     { WM_ERASEBKGND, sent|optional },
688     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
689     { WM_ACTIVATEAPP, sent|wparam, 1 },
690     { WM_NCACTIVATE, sent },
691     { WM_ACTIVATE, sent|wparam, 1 },
692     { HCBT_SETFOCUS, hook },
693     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
694     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
695     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
696     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
697     { WM_GETTEXT, sent|optional },
698     { WM_SYNCPAINT, sent|wparam|optional, 4 },
699     { WM_NCPAINT, sent|wparam|optional, 1 },
700     { WM_ERASEBKGND, sent|optional },
701     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
702     { WM_ERASEBKGND, sent|defwinproc|optional },
703     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
704     { 0 }
705 };
706 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
707 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
708     { HCBT_CREATEWND, hook },
709     { WM_NCCREATE, sent },
710     { WM_NCCALCSIZE, sent|wparam, 0 },
711     { WM_CREATE, sent },
712     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
713     { WM_SIZE, sent|wparam, SIZE_RESTORED },
714     { WM_MOVE, sent },
715     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
716     { WM_GETMINMAXINFO, sent },
717     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
718     { WM_NCCALCSIZE, sent|wparam, TRUE },
719     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
720     { WM_MOVE, sent|defwinproc },
721     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
722     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
723     { 0 }
724 };
725 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
726 static const struct message WmShowMaxPopupResizedSeq[] = {
727     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
728     { WM_GETMINMAXINFO, sent },
729     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
730     { WM_NCCALCSIZE, sent|wparam, TRUE },
731     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
732     { HCBT_ACTIVATE, hook },
733     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
734     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
735     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
736     { WM_NCPAINT, sent|wparam|optional, 1 },
737     { WM_ERASEBKGND, sent|optional },
738     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
739     { WM_ACTIVATEAPP, sent|wparam, 1 },
740     { WM_NCACTIVATE, sent },
741     { WM_ACTIVATE, sent|wparam, 1 },
742     { HCBT_SETFOCUS, hook },
743     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
744     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
745     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
746     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
747     { WM_GETTEXT, sent|optional },
748     { WM_NCPAINT, sent|wparam|optional, 1 },
749     { WM_ERASEBKGND, sent|optional },
750     { WM_WINDOWPOSCHANGED, sent },
751     /* WinNT4.0 sends WM_MOVE */
752     { WM_MOVE, sent|defwinproc|optional },
753     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
754     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
755     { 0 }
756 };
757 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
758 static const struct message WmShowMaxPopupSeq[] = {
759     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
760     { WM_GETMINMAXINFO, sent },
761     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
762     { WM_NCCALCSIZE, sent|wparam, TRUE },
763     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
764     { HCBT_ACTIVATE, hook },
765     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
766     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
767     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
768     { WM_ACTIVATEAPP, sent|wparam, 1 },
769     { WM_NCACTIVATE, sent },
770     { WM_ACTIVATE, sent|wparam, 1 },
771     { HCBT_SETFOCUS, hook },
772     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
773     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
774     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
775     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
776     { WM_GETTEXT, sent|optional },
777     { WM_SYNCPAINT, sent|wparam|optional, 4 },
778     { WM_NCPAINT, sent|wparam|optional, 1 },
779     { WM_ERASEBKGND, sent|optional },
780     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
781     { WM_ERASEBKGND, sent|defwinproc|optional },
782     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
783     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
784     { 0 }
785 };
786 /* CreateWindow(WS_VISIBLE) for popup window */
787 static const struct message WmCreatePopupSeq[] = {
788     { HCBT_CREATEWND, hook },
789     { WM_NCCREATE, sent },
790     { WM_NCCALCSIZE, sent|wparam, 0 },
791     { WM_CREATE, sent },
792     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
793     { WM_SIZE, sent|wparam, SIZE_RESTORED },
794     { WM_MOVE, sent },
795     { WM_SHOWWINDOW, sent|wparam, 1 },
796     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
797     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
798     { HCBT_ACTIVATE, hook },
799     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
800     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
801     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
802     { WM_NCPAINT, sent|wparam|optional, 1 },
803     { WM_ERASEBKGND, sent|optional },
804     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
805     { WM_ACTIVATEAPP, sent|wparam, 1 },
806     { WM_NCACTIVATE, sent },
807     { WM_ACTIVATE, sent|wparam, 1 },
808     { HCBT_SETFOCUS, hook },
809     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
810     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
811     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
812     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
813     { WM_GETTEXT, sent|optional },
814     { WM_SYNCPAINT, sent|wparam|optional, 4 },
815     { WM_NCPAINT, sent|wparam|optional, 1 },
816     { WM_ERASEBKGND, sent|optional },
817     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
818     { 0 }
819 };
820 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
821 static const struct message WmShowVisMaxPopupSeq[] = {
822     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
823     { WM_GETMINMAXINFO, sent },
824     { WM_GETTEXT, sent|optional },
825     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
826     { WM_GETTEXT, sent|optional },
827     { WM_NCCALCSIZE, sent|wparam, TRUE },
828     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
829     { WM_NCPAINT, sent|wparam|optional, 1 },
830     { WM_ERASEBKGND, sent|optional },
831     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
832     { WM_MOVE, sent|defwinproc },
833     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
834     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
835     { 0 }
836 };
837 /* CreateWindow (for a child popup window, not initially visible) */
838 static const struct message WmCreateChildPopupSeq[] = {
839     { HCBT_CREATEWND, hook },
840     { WM_NCCREATE, sent }, 
841     { WM_NCCALCSIZE, sent|wparam, 0 },
842     { WM_CREATE, sent },
843     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
844     { WM_SIZE, sent|wparam, SIZE_RESTORED },
845     { WM_MOVE, sent },
846     { 0 }
847 };
848 /* CreateWindow (for a popup window, not initially visible,
849  * which sets WS_VISIBLE in WM_CREATE handler)
850  */
851 static const struct message WmCreateInvisiblePopupSeq[] = {
852     { HCBT_CREATEWND, hook },
853     { WM_NCCREATE, sent }, 
854     { WM_NCCALCSIZE, sent|wparam, 0 },
855     { WM_CREATE, sent },
856     { WM_STYLECHANGING, sent },
857     { WM_STYLECHANGED, sent },
858     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
859     { WM_SIZE, sent|wparam, SIZE_RESTORED },
860     { WM_MOVE, sent },
861     { 0 }
862 };
863 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
864  * for a popup window with WS_VISIBLE style set
865  */
866 static const struct message WmShowVisiblePopupSeq_2[] = {
867     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
868     { 0 }
869 };
870 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
871  * for a popup window with WS_VISIBLE style set
872  */
873 static const struct message WmShowVisiblePopupSeq_3[] = {
874     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
875     { HCBT_ACTIVATE, hook },
876     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
877     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
878     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
879     { WM_NCACTIVATE, sent },
880     { WM_ACTIVATE, sent|wparam, 1 },
881     { HCBT_SETFOCUS, hook },
882     { WM_KILLFOCUS, sent|parent },
883     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
884     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
885     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
886     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
887     { WM_SETFOCUS, sent|defwinproc },
888     { WM_GETTEXT, sent|optional },
889     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
890     { 0 }
891 };
892 /* CreateWindow (for child window, not initially visible) */
893 static const struct message WmCreateChildSeq[] = {
894     { HCBT_CREATEWND, hook },
895     { WM_NCCREATE, sent }, 
896     /* child is inserted into parent's child list after WM_NCCREATE returns */
897     { WM_NCCALCSIZE, sent|wparam, 0 },
898     { WM_CREATE, sent },
899     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
900     { WM_SIZE, sent|wparam, SIZE_RESTORED },
901     { WM_MOVE, sent },
902     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
903     { 0 }
904 };
905 /* CreateWindow (for maximized child window, not initially visible) */
906 static const struct message WmCreateMaximizedChildSeq[] = {
907     { HCBT_CREATEWND, hook },
908     { WM_NCCREATE, sent }, 
909     { WM_NCCALCSIZE, sent|wparam, 0 },
910     { WM_CREATE, sent },
911     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
912     { WM_SIZE, sent|wparam, SIZE_RESTORED },
913     { WM_MOVE, sent },
914     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
915     { WM_GETMINMAXINFO, sent },
916     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
917     { WM_NCCALCSIZE, sent|wparam, 1 },
918     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
919     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
920     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
921     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
922     { 0 }
923 };
924 /* CreateWindow (for a child window, initially visible) */
925 static const struct message WmCreateVisibleChildSeq[] = {
926     { HCBT_CREATEWND, hook },
927     { WM_NCCREATE, sent }, 
928     /* child is inserted into parent's child list after WM_NCCREATE returns */
929     { WM_NCCALCSIZE, sent|wparam, 0 },
930     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
931     { WM_CREATE, sent },
932     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
933     { WM_SIZE, sent|wparam, SIZE_RESTORED },
934     { WM_MOVE, sent },
935     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
936     { WM_SHOWWINDOW, sent|wparam, 1 },
937     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
938     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
939     { WM_ERASEBKGND, sent|parent|optional },
940     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
941     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
942     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
943     { 0 }
944 };
945 /* ShowWindow(SW_SHOW) for a not visible child window */
946 static const struct message WmShowChildSeq[] = {
947     { WM_SHOWWINDOW, sent|wparam, 1 },
948     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
949     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
950     { WM_ERASEBKGND, sent|parent|optional },
951     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
952     { 0 }
953 };
954 /* ShowWindow(SW_HIDE) for a visible child window */
955 static const struct message WmHideChildSeq[] = {
956     { WM_SHOWWINDOW, sent|wparam, 0 },
957     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
958     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
959     { WM_ERASEBKGND, sent|parent|optional },
960     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
961     { 0 }
962 };
963 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
964 static const struct message WmHideChildSeq2[] = {
965     { WM_SHOWWINDOW, sent|wparam, 0 },
966     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
967     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
968     { WM_ERASEBKGND, sent|parent|optional },
969     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
970     { 0 }
971 };
972 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
973  * for a not visible child window
974  */
975 static const struct message WmShowChildSeq_2[] = {
976     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
977     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
978     { WM_CHILDACTIVATE, sent },
979     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
980     { 0 }
981 };
982 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
983  * for a not visible child window
984  */
985 static const struct message WmShowChildSeq_3[] = {
986     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
987     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
988     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
989     { 0 }
990 };
991 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
992  * for a visible child window with a caption
993  */
994 static const struct message WmShowChildSeq_4[] = {
995     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
996     { WM_CHILDACTIVATE, sent },
997     { 0 }
998 };
999 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1000 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1001     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1002     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1003     { WM_NCCALCSIZE, sent|wparam, 1 },
1004     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1005     { WM_CHILDACTIVATE, sent|optional },
1006     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1007     { WM_MOVE, sent|defwinproc },
1008     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1009     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1010     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1011     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1012     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1013     { WM_GETTEXT, sent|optional },
1014     { 0 }
1015 };
1016 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1017 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1018     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1019     { 0 }
1020 };
1021 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1022 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1023     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1024     { WM_GETMINMAXINFO, sent },
1025     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1026     { WM_NCCALCSIZE, sent|wparam, 1 },
1027     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1028     { WM_CHILDACTIVATE, sent },
1029     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1030     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1032     { 0 }
1033 };
1034 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1035 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1036     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1037     { 0 }
1038 };
1039 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1040 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1041     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1042     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1043     { WM_NCCALCSIZE, sent|wparam, 1 },
1044     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1045     { WM_CHILDACTIVATE, sent },
1046     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1047     { WM_MOVE, sent|defwinproc },
1048     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1049     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1050     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1051     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1052     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1053     { WM_GETTEXT, sent|optional },
1054     { 0 }
1055 };
1056 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1057 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1058     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1059     { 0 }
1060 };
1061 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1062 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1063     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1064     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1065     { WM_NCCALCSIZE, sent|wparam, 1 },
1066     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1067     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1068     { WM_MOVE, sent|defwinproc },
1069     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1070     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1071     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1072     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1073     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1074     { WM_GETTEXT, sent|optional },
1075     { 0 }
1076 };
1077 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1078 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1079     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1080     { 0 }
1081 };
1082 /* ShowWindow(SW_SHOW) for child with invisible parent */
1083 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1084     { WM_SHOWWINDOW, sent|wparam, 1 },
1085     { 0 }
1086 };
1087 /* ShowWindow(SW_HIDE) for child with invisible parent */
1088 static const struct message WmHideChildInvisibleParentSeq[] = {
1089     { WM_SHOWWINDOW, sent|wparam, 0 },
1090     { 0 }
1091 };
1092 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1093 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1094     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1095     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1096     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1097     { 0 }
1098 };
1099 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1100 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1101     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1102     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1103     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1104     { 0 }
1105 };
1106 /* DestroyWindow for a visible child window */
1107 static const struct message WmDestroyChildSeq[] = {
1108     { HCBT_DESTROYWND, hook },
1109     { 0x0090, sent|optional },
1110     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1111     { WM_SHOWWINDOW, sent|wparam, 0 },
1112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1113     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1114     { WM_ERASEBKGND, sent|parent|optional },
1115     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1116     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1117     { WM_KILLFOCUS, sent },
1118     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1119     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1120     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1121     { WM_SETFOCUS, sent|parent },
1122     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1123     { WM_DESTROY, sent },
1124     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1125     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1126     { WM_NCDESTROY, sent },
1127     { 0 }
1128 };
1129 /* visible child window destroyed by thread exit */
1130 static const struct message WmExitThreadSeq[] = {
1131     { WM_NCDESTROY, sent },  /* actually in grandchild */
1132     { WM_PAINT, sent|parent },
1133     { WM_ERASEBKGND, sent|parent|beginpaint },
1134     { 0 }
1135 };
1136 /* DestroyWindow for a visible child window with invisible parent */
1137 static const struct message WmDestroyInvisibleChildSeq[] = {
1138     { HCBT_DESTROYWND, hook },
1139     { 0x0090, sent|optional },
1140     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1141     { WM_SHOWWINDOW, sent|wparam, 0 },
1142     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1143     { WM_DESTROY, sent },
1144     { WM_NCDESTROY, sent },
1145     { 0 }
1146 };
1147 /* Moving the mouse in nonclient area */
1148 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1149     { WM_NCHITTEST, sent },
1150     { WM_SETCURSOR, sent },
1151     { WM_NCMOUSEMOVE, posted },
1152     { 0 }
1153 };
1154 /* Moving the mouse in client area */
1155 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1156     { WM_NCHITTEST, sent },
1157     { WM_SETCURSOR, sent },
1158     { WM_MOUSEMOVE, posted },
1159     { 0 }
1160 };
1161 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1162 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1163     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1164     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1165     { WM_GETMINMAXINFO, sent|defwinproc },
1166     { WM_ENTERSIZEMOVE, sent|defwinproc },
1167     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1168     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1169     { WM_MOVE, sent|defwinproc },
1170     { WM_EXITSIZEMOVE, sent|defwinproc },
1171     { 0 }
1172 };
1173 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1174 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1175     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1176     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1177     { WM_GETMINMAXINFO, sent|defwinproc },
1178     { WM_ENTERSIZEMOVE, sent|defwinproc },
1179     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1180     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1181     { WM_GETMINMAXINFO, sent|defwinproc },
1182     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1183     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1184     { WM_GETTEXT, sent|defwinproc },
1185     { WM_ERASEBKGND, sent|defwinproc },
1186     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1187     { WM_MOVE, sent|defwinproc },
1188     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1189     { WM_EXITSIZEMOVE, sent|defwinproc },
1190     { 0 }
1191 };
1192 /* Resizing child window with MoveWindow (32) */
1193 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1194     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1195     { WM_NCCALCSIZE, sent|wparam, 1 },
1196     { WM_ERASEBKGND, sent|parent|optional },
1197     { WM_ERASEBKGND, sent|optional },
1198     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1199     { WM_MOVE, sent|defwinproc },
1200     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1201     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1202     { 0 }
1203 };
1204 /* Clicking on inactive button */
1205 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1206     { WM_NCHITTEST, sent },
1207     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1208     { WM_MOUSEACTIVATE, sent },
1209     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1210     { WM_SETCURSOR, sent },
1211     { WM_SETCURSOR, sent|parent|defwinproc },
1212     { WM_LBUTTONDOWN, posted },
1213     { WM_KILLFOCUS, posted|parent },
1214     { WM_SETFOCUS, posted },
1215     { WM_CTLCOLORBTN, posted|parent },
1216     { BM_SETSTATE, posted },
1217     { WM_CTLCOLORBTN, posted|parent },
1218     { WM_LBUTTONUP, posted },
1219     { BM_SETSTATE, posted },
1220     { WM_CTLCOLORBTN, posted|parent },
1221     { WM_COMMAND, posted|parent },
1222     { 0 }
1223 };
1224 /* Reparenting a button (16/32) */
1225 /* The last child (button) reparented gets topmost for its new parent. */
1226 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1227     { WM_SHOWWINDOW, sent|wparam, 0 },
1228     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1229     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1230     { WM_ERASEBKGND, sent|parent },
1231     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1232     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1233     { WM_CHILDACTIVATE, sent },
1234     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1235     { WM_MOVE, sent|defwinproc },
1236     { WM_SHOWWINDOW, sent|wparam, 1 },
1237     { 0 }
1238 };
1239 /* Creation of a custom dialog (32) */
1240 static const struct message WmCreateCustomDialogSeq[] = {
1241     { HCBT_CREATEWND, hook },
1242     { WM_GETMINMAXINFO, sent },
1243     { WM_NCCREATE, sent },
1244     { WM_NCCALCSIZE, sent|wparam, 0 },
1245     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1246     { WM_CREATE, sent },
1247     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1248     { WM_NOTIFYFORMAT, sent|optional },
1249     { WM_QUERYUISTATE, sent|optional },
1250     { WM_WINDOWPOSCHANGING, sent|optional },
1251     { WM_GETMINMAXINFO, sent|optional },
1252     { WM_NCCALCSIZE, sent|optional },
1253     { WM_WINDOWPOSCHANGED, sent|optional },
1254     { WM_SHOWWINDOW, sent|wparam, 1 },
1255     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1256     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1257     { HCBT_ACTIVATE, hook },
1258     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1259
1260
1261     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1262
1263     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1264
1265     { WM_NCACTIVATE, sent },
1266     { WM_GETTEXT, sent|optional|defwinproc },
1267     { WM_GETTEXT, sent|optional|defwinproc },
1268     { WM_GETTEXT, sent|optional|defwinproc },
1269     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1270     { WM_ACTIVATE, sent|wparam, 1 },
1271     { WM_GETTEXT, sent|optional },
1272     { WM_KILLFOCUS, sent|parent },
1273     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1274     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1275     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1276     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1277     { WM_SETFOCUS, sent },
1278     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1279     { WM_NCPAINT, sent|wparam, 1 },
1280     { WM_GETTEXT, sent|optional|defwinproc },
1281     { WM_GETTEXT, sent|optional|defwinproc },
1282     { WM_ERASEBKGND, sent },
1283     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1284     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1285     { WM_GETTEXT, sent|optional },
1286     { WM_GETTEXT, sent|optional },
1287     { WM_NCCALCSIZE, sent|optional },
1288     { WM_NCPAINT, sent|optional },
1289     { WM_GETTEXT, sent|optional|defwinproc },
1290     { WM_GETTEXT, sent|optional|defwinproc },
1291     { WM_ERASEBKGND, sent|optional },
1292     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1293     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1294     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1295     { WM_MOVE, sent },
1296     { 0 }
1297 };
1298 /* Calling EndDialog for a custom dialog (32) */
1299 static const struct message WmEndCustomDialogSeq[] = {
1300     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1301     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1302     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1303     { WM_GETTEXT, sent|optional },
1304     { HCBT_ACTIVATE, hook },
1305     { WM_NCACTIVATE, sent|wparam, 0 },
1306     { WM_GETTEXT, sent|optional|defwinproc },
1307     { WM_GETTEXT, sent|optional|defwinproc },
1308     { WM_ACTIVATE, sent|wparam, 0 },
1309     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1310     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1311     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1312     { WM_GETTEXT, sent|optional|defwinproc },
1313     { WM_GETTEXT, sent|optional|defwinproc },
1314     { HCBT_SETFOCUS, hook },
1315     { WM_KILLFOCUS, sent },
1316     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1317     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1318     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1319     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1320     { WM_SETFOCUS, sent|parent|defwinproc },
1321     { 0 }
1322 };
1323 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1324 static const struct message WmShowCustomDialogSeq[] = {
1325     { WM_SHOWWINDOW, sent|wparam, 1 },
1326     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1327     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1328     { HCBT_ACTIVATE, hook },
1329     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1330
1331     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1332
1333     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1334     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1335     { WM_NCACTIVATE, sent },
1336     { WM_ACTIVATE, sent|wparam, 1 },
1337     { WM_GETTEXT, sent|optional },
1338
1339     { WM_KILLFOCUS, sent|parent },
1340     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1341     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1342     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1343     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1344     { WM_SETFOCUS, sent },
1345     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1346     { WM_NCPAINT, sent|wparam, 1 },
1347     { WM_ERASEBKGND, sent },
1348     { WM_CTLCOLORDLG, sent|defwinproc },
1349     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1350     { 0 }
1351 };
1352 /* Creation and destruction of a modal dialog (32) */
1353 static const struct message WmModalDialogSeq[] = {
1354     { WM_CANCELMODE, sent|parent },
1355     { HCBT_SETFOCUS, hook },
1356     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1357     { WM_KILLFOCUS, sent|parent },
1358     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1359     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1360     { WM_ENABLE, sent|parent|wparam, 0 },
1361     { HCBT_CREATEWND, hook },
1362     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1363     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1364     { WM_SETFONT, sent },
1365     { WM_INITDIALOG, sent },
1366     { WM_CHANGEUISTATE, sent|optional },
1367     { WM_UPDATEUISTATE, sent|optional },
1368     { WM_SHOWWINDOW, sent },
1369     { HCBT_ACTIVATE, hook },
1370     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1371     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1372     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1373     { WM_NCACTIVATE, sent },
1374     { WM_GETTEXT, sent|optional },
1375     { WM_ACTIVATE, sent|wparam, 1 },
1376     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1377     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1378     { WM_NCPAINT, sent|optional },
1379     { WM_GETTEXT, sent|optional },
1380     { WM_ERASEBKGND, sent|optional },
1381     { WM_CTLCOLORDLG, sent|optional },
1382     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1383     { WM_GETTEXT, sent|optional },
1384     { WM_NCCALCSIZE, sent|optional },
1385     { WM_NCPAINT, sent|optional },
1386     { WM_GETTEXT, sent|optional },
1387     { WM_ERASEBKGND, sent|optional },
1388     { WM_CTLCOLORDLG, sent|optional },
1389     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1390     { WM_PAINT, sent|optional },
1391     { WM_CTLCOLORBTN, sent|optional },
1392     { WM_GETTITLEBARINFOEX, sent|optional },
1393     { WM_ENTERIDLE, sent|parent|optional },
1394     { WM_ENTERIDLE, sent|parent|optional },
1395     { WM_ENTERIDLE, sent|parent|optional },
1396     { WM_ENTERIDLE, sent|parent|optional },
1397     { WM_ENTERIDLE, sent|parent|optional },
1398     { WM_ENTERIDLE, sent|parent|optional },
1399     { WM_ENTERIDLE, sent|parent|optional },
1400     { WM_ENTERIDLE, sent|parent|optional },
1401     { WM_ENTERIDLE, sent|parent|optional },
1402     { WM_ENTERIDLE, sent|parent|optional },
1403     { WM_ENTERIDLE, sent|parent|optional },
1404     { WM_ENTERIDLE, sent|parent|optional },
1405     { WM_ENTERIDLE, sent|parent|optional },
1406     { WM_ENTERIDLE, sent|parent|optional },
1407     { WM_ENTERIDLE, sent|parent|optional },
1408     { WM_ENTERIDLE, sent|parent|optional },
1409     { WM_ENTERIDLE, sent|parent|optional },
1410     { WM_ENTERIDLE, sent|parent|optional },
1411     { WM_ENTERIDLE, sent|parent|optional },
1412     { WM_ENTERIDLE, sent|parent|optional },
1413     { WM_TIMER, sent },
1414     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1415     { WM_ENABLE, sent|parent|wparam, 1 },
1416     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1417     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1418     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1419     { WM_GETTEXT, sent|optional },
1420     { HCBT_ACTIVATE, hook },
1421     { WM_NCACTIVATE, sent|wparam, 0 },
1422     { WM_GETTEXT, sent|optional },
1423     { WM_ACTIVATE, sent|wparam, 0 },
1424     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1425     { WM_WINDOWPOSCHANGING, sent|optional },
1426     { WM_WINDOWPOSCHANGED, sent|optional },
1427     { HCBT_SETFOCUS, hook },
1428     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1429     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1430     { WM_SETFOCUS, sent|parent|defwinproc },
1431     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1432     { HCBT_DESTROYWND, hook },
1433     { 0x0090, sent|optional },
1434     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1435     { WM_DESTROY, sent },
1436     { WM_NCDESTROY, sent },
1437     { 0 }
1438 };
1439 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1440 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1441     /* (inside dialog proc, handling WM_INITDIALOG) */
1442     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1443     { WM_NCCALCSIZE, sent },
1444     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1445     { WM_GETTEXT, sent|defwinproc },
1446     { WM_ACTIVATE, sent|parent|wparam, 0 },
1447     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1448     { WM_WINDOWPOSCHANGING, sent|parent },
1449     { WM_NCACTIVATE, sent|wparam, 1 },
1450     { WM_ACTIVATE, sent|wparam, 1 },
1451     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1452     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1453     /* (setting focus) */
1454     { WM_SHOWWINDOW, sent|wparam, 1 },
1455     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1456     { WM_NCPAINT, sent },
1457     { WM_GETTEXT, sent|defwinproc },
1458     { WM_ERASEBKGND, sent },
1459     { WM_CTLCOLORDLG, sent|defwinproc },
1460     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1461     { WM_PAINT, sent },
1462     /* (bunch of WM_CTLCOLOR* for each control) */
1463     { WM_PAINT, sent|parent },
1464     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1465     { WM_SETCURSOR, sent|parent },
1466     { 0 }
1467 };
1468 /* SetMenu for NonVisible windows with size change*/
1469 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1470     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1471     { WM_NCCALCSIZE, sent|wparam, 1 },
1472     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1473     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1474     { WM_MOVE, sent|defwinproc },
1475     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1476     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1477     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1478     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1479     { WM_GETTEXT, sent|optional },
1480     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1481     { 0 }
1482 };
1483 /* SetMenu for NonVisible windows with no size change */
1484 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1485     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1486     { WM_NCCALCSIZE, sent|wparam, 1 },
1487     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1488     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1489     { 0 }
1490 };
1491 /* SetMenu for Visible windows with size change */
1492 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1493     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1494     { WM_NCCALCSIZE, sent|wparam, 1 },
1495     { 0x0093, sent|defwinproc|optional },
1496     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1497     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1498     { 0x0093, sent|defwinproc|optional },
1499     { 0x0093, sent|defwinproc|optional },
1500     { 0x0091, sent|defwinproc|optional },
1501     { 0x0092, sent|defwinproc|optional },
1502     { WM_GETTEXT, sent|defwinproc|optional },
1503     { WM_ERASEBKGND, sent|optional },
1504     { WM_ACTIVATE, sent|optional },
1505     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1506     { WM_MOVE, sent|defwinproc },
1507     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1508     { 0x0093, sent|optional },
1509     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1510     { 0x0093, sent|defwinproc|optional },
1511     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1512     { 0x0093, sent|defwinproc|optional },
1513     { 0x0093, sent|defwinproc|optional },
1514     { 0x0091, sent|defwinproc|optional },
1515     { 0x0092, sent|defwinproc|optional },
1516     { WM_ERASEBKGND, sent|optional },
1517     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1518     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1519     { 0 }
1520 };
1521 /* SetMenu for Visible windows with no size change */
1522 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1523     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1524     { WM_NCCALCSIZE, sent|wparam, 1 },
1525     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1526     { WM_GETTEXT, sent|defwinproc|optional },
1527     { WM_ERASEBKGND, sent|optional },
1528     { WM_ACTIVATE, sent|optional },
1529     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1530     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1531     { 0 }
1532 };
1533 /* DrawMenuBar for a visible window */
1534 static const struct message WmDrawMenuBarSeq[] =
1535 {
1536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1537     { WM_NCCALCSIZE, sent|wparam, 1 },
1538     { 0x0093, sent|defwinproc|optional },
1539     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1540     { 0x0093, sent|defwinproc|optional },
1541     { 0x0093, sent|defwinproc|optional },
1542     { 0x0091, sent|defwinproc|optional },
1543     { 0x0092, sent|defwinproc|optional },
1544     { WM_GETTEXT, sent|defwinproc|optional },
1545     { WM_ERASEBKGND, sent|optional },
1546     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1547     { 0x0093, sent|optional },
1548     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1549     { 0 }
1550 };
1551
1552 static const struct message WmSetRedrawFalseSeq[] =
1553 {
1554     { WM_SETREDRAW, sent|wparam, 0 },
1555     { 0 }
1556 };
1557
1558 static const struct message WmSetRedrawTrueSeq[] =
1559 {
1560     { WM_SETREDRAW, sent|wparam, 1 },
1561     { 0 }
1562 };
1563
1564 static const struct message WmEnableWindowSeq_1[] =
1565 {
1566     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1567     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1568     { HCBT_SETFOCUS, hook|optional },
1569     { WM_KILLFOCUS, sent|optional },
1570     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1571     { 0 }
1572 };
1573
1574 static const struct message WmEnableWindowSeq_2[] =
1575 {
1576     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1577     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1578     { 0 }
1579 };
1580
1581 static const struct message WmGetScrollRangeSeq[] =
1582 {
1583     { SBM_GETRANGE, sent },
1584     { 0 }
1585 };
1586 static const struct message WmGetScrollInfoSeq[] =
1587 {
1588     { SBM_GETSCROLLINFO, sent },
1589     { 0 }
1590 };
1591 static const struct message WmSetScrollRangeSeq[] =
1592 {
1593     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1594        sends SBM_SETSCROLLINFO.
1595      */
1596     { SBM_SETSCROLLINFO, sent },
1597     { 0 }
1598 };
1599 /* SetScrollRange for a window without a non-client area */
1600 static const struct message WmSetScrollRangeHSeq_empty[] =
1601 {
1602     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1603     { 0 }
1604 };
1605 static const struct message WmSetScrollRangeVSeq_empty[] =
1606 {
1607     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1608     { 0 }
1609 };
1610 static const struct message WmSetScrollRangeHVSeq[] =
1611 {
1612     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1613     { WM_NCCALCSIZE, sent|wparam, 1 },
1614     { WM_GETTEXT, sent|defwinproc|optional },
1615     { WM_ERASEBKGND, sent|optional },
1616     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1617     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1618     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1619     { 0 }
1620 };
1621 /* SetScrollRange for a window with a non-client area */
1622 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1623 {
1624     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1625     { WM_NCCALCSIZE, sent|wparam, 1 },
1626     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1627     { WM_NCPAINT, sent|optional },
1628     { WM_STYLECHANGING, sent|defwinproc|optional },
1629     { WM_STYLECHANGED, sent|defwinproc|optional },
1630     { WM_STYLECHANGING, sent|defwinproc|optional },
1631     { WM_STYLECHANGED, sent|defwinproc|optional },
1632     { WM_STYLECHANGING, sent|defwinproc|optional },
1633     { WM_STYLECHANGED, sent|defwinproc|optional },
1634     { WM_STYLECHANGING, sent|defwinproc|optional },
1635     { WM_STYLECHANGED, sent|defwinproc|optional },
1636     { WM_GETTEXT, sent|defwinproc|optional },
1637     { WM_GETTEXT, sent|defwinproc|optional },
1638     { WM_ERASEBKGND, sent|optional },
1639     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1640     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1641     { WM_SIZE, sent|defwinproc|optional },
1642     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1643     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1644     { WM_GETTEXT, sent|optional },
1645     { WM_GETTEXT, sent|optional },
1646     { WM_GETTEXT, sent|optional },
1647     { WM_GETTEXT, sent|optional },
1648     { 0 }
1649 };
1650 /* test if we receive the right sequence of messages */
1651 /* after calling ShowWindow( SW_SHOWNA) */
1652 static const struct message WmSHOWNAChildInvisParInvis[] = {
1653     { WM_SHOWWINDOW, sent|wparam, 1 },
1654     { 0 }
1655 };
1656 static const struct message WmSHOWNAChildVisParInvis[] = {
1657     { WM_SHOWWINDOW, sent|wparam, 1 },
1658     { 0 }
1659 };
1660 static const struct message WmSHOWNAChildVisParVis[] = {
1661     { WM_SHOWWINDOW, sent|wparam, 1 },
1662     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1663     { 0 }
1664 };
1665 static const struct message WmSHOWNAChildInvisParVis[] = {
1666     { WM_SHOWWINDOW, sent|wparam, 1 },
1667     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1668     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1669     { WM_ERASEBKGND, sent|optional },
1670     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1671     { 0 }
1672 };
1673 static const struct message WmSHOWNATopVisible[] = {
1674     { WM_SHOWWINDOW, sent|wparam, 1 },
1675     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1676     { WM_NCPAINT, sent|wparam|optional, 1 },
1677     { WM_GETTEXT, sent|defwinproc|optional },
1678     { WM_ERASEBKGND, sent|optional },
1679     { WM_WINDOWPOSCHANGED, sent|optional },
1680     { 0 }
1681 };
1682 static const struct message WmSHOWNATopInvisible[] = {
1683     { WM_NOTIFYFORMAT, sent|optional },
1684     { WM_QUERYUISTATE, sent|optional },
1685     { WM_WINDOWPOSCHANGING, sent|optional },
1686     { WM_GETMINMAXINFO, sent|optional },
1687     { WM_NCCALCSIZE, sent|optional },
1688     { WM_WINDOWPOSCHANGED, sent|optional },
1689     { WM_SHOWWINDOW, sent|wparam, 1 },
1690     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1691     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1692     { WM_NCPAINT, sent|wparam|optional, 1 },
1693     { WM_GETTEXT, sent|defwinproc|optional },
1694     { WM_ERASEBKGND, sent|optional },
1695     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1696     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1697     { WM_NCPAINT, sent|wparam|optional, 1 },
1698     { WM_ERASEBKGND, sent|optional },
1699     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1700     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1701     { WM_MOVE, sent },
1702     { 0 }
1703 };
1704
1705 static int after_end_dialog, test_def_id;
1706 static int sequence_cnt, sequence_size;
1707 static struct recvd_message* sequence;
1708 static int log_all_parent_messages;
1709 static int paint_loop_done;
1710
1711 /* user32 functions */
1712 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1713 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1714 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1715 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1716 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1717 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1718 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1719 /* kernel32 functions */
1720 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1721
1722 static void init_procs(void)
1723 {
1724     HMODULE user32 = GetModuleHandleA("user32.dll");
1725     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1726
1727 #define GET_PROC(dll, func) \
1728     p ## func = (void*)GetProcAddress(dll, #func); \
1729     if(!p ## func) { \
1730       trace("GetProcAddress(%s) failed\n", #func); \
1731     }
1732
1733     GET_PROC(user32, GetAncestor)
1734     GET_PROC(user32, GetMenuInfo)
1735     GET_PROC(user32, NotifyWinEvent)
1736     GET_PROC(user32, SetMenuInfo)
1737     GET_PROC(user32, SetWinEventHook)
1738     GET_PROC(user32, TrackMouseEvent)
1739     GET_PROC(user32, UnhookWinEvent)
1740
1741     GET_PROC(kernel32, GetCPInfoExA)
1742
1743 #undef GET_PROC
1744 }
1745
1746 static const char *get_winpos_flags(UINT flags)
1747 {
1748     static char buffer[300];
1749
1750     buffer[0] = 0;
1751 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1752     DUMP( SWP_SHOWWINDOW );
1753     DUMP( SWP_HIDEWINDOW );
1754     DUMP( SWP_NOACTIVATE );
1755     DUMP( SWP_FRAMECHANGED );
1756     DUMP( SWP_NOCOPYBITS );
1757     DUMP( SWP_NOOWNERZORDER );
1758     DUMP( SWP_NOSENDCHANGING );
1759     DUMP( SWP_DEFERERASE );
1760     DUMP( SWP_ASYNCWINDOWPOS );
1761     DUMP( SWP_NOZORDER );
1762     DUMP( SWP_NOREDRAW );
1763     DUMP( SWP_NOSIZE );
1764     DUMP( SWP_NOMOVE );
1765     DUMP( SWP_NOCLIENTSIZE );
1766     DUMP( SWP_NOCLIENTMOVE );
1767     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1768     return buffer + 1;
1769 #undef DUMP
1770 }
1771
1772 static BOOL ignore_message( UINT message )
1773 {
1774     /* these are always ignored */
1775     return (message >= 0xc000 ||
1776             message == WM_GETICON ||
1777             message == WM_GETOBJECT ||
1778             message == WM_TIMECHANGE ||
1779             message == WM_DISPLAYCHANGE ||
1780             message == WM_DEVICECHANGE ||
1781             message == WM_DWMNCRENDERINGCHANGED);
1782 }
1783
1784
1785 #define add_message(msg) add_message_(__LINE__,msg);
1786 static void add_message_(int line, const struct recvd_message *msg)
1787 {
1788     struct recvd_message *seq;
1789
1790     if (!sequence) 
1791     {
1792         sequence_size = 10;
1793         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1794     }
1795     if (sequence_cnt == sequence_size) 
1796     {
1797         sequence_size *= 2;
1798         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1799     }
1800     assert(sequence);
1801
1802     seq = &sequence[sequence_cnt];
1803     seq->hwnd = msg->hwnd;
1804     seq->message = msg->message;
1805     seq->flags = msg->flags;
1806     seq->wParam = msg->wParam;
1807     seq->lParam = msg->lParam;
1808     seq->line   = line;
1809     seq->descr  = msg->descr;
1810     seq->output[0] = 0;
1811
1812     if (msg->descr)
1813     {
1814         if (msg->flags & hook)
1815         {
1816             static const char * const CBT_code_name[10] =
1817             {
1818                 "HCBT_MOVESIZE",
1819                 "HCBT_MINMAX",
1820                 "HCBT_QS",
1821                 "HCBT_CREATEWND",
1822                 "HCBT_DESTROYWND",
1823                 "HCBT_ACTIVATE",
1824                 "HCBT_CLICKSKIPPED",
1825                 "HCBT_KEYSKIPPED",
1826                 "HCBT_SYSCOMMAND",
1827                 "HCBT_SETFOCUS"
1828             };
1829             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1830
1831             sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1832                      msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1833         }
1834         else if (msg->flags & winevent_hook)
1835         {
1836             sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1837                      msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1838         }
1839         else
1840         {
1841             switch (msg->message)
1842             {
1843             case WM_WINDOWPOSCHANGING:
1844             case WM_WINDOWPOSCHANGED:
1845             {
1846                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1847
1848                 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1849                           msg->descr, msg->hwnd,
1850                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1851                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1852                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1853                           get_winpos_flags(winpos->flags) );
1854
1855                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1856                  * in the high word for internal purposes
1857                  */
1858                 seq->wParam = winpos->flags & 0xffff;
1859                 /* We are not interested in the flags that don't match under XP and Win9x */
1860                 seq->wParam &= ~SWP_NOZORDER;
1861                 break;
1862             }
1863
1864             case WM_DRAWITEM:
1865             {
1866                 DRAW_ITEM_STRUCT di;
1867                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1868
1869                 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1870                          msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1871                          dis->itemID, dis->itemAction, dis->itemState);
1872
1873                 di.u.lp = 0;
1874                 di.u.item.type = dis->CtlType;
1875                 di.u.item.ctl_id = dis->CtlID;
1876                 if (dis->CtlType == ODT_LISTBOX ||
1877                     dis->CtlType == ODT_COMBOBOX ||
1878                     dis->CtlType == ODT_MENU)
1879                     di.u.item.item_id = dis->itemID;
1880                 di.u.item.action = dis->itemAction;
1881                 di.u.item.state = dis->itemState;
1882
1883                 seq->lParam = di.u.lp;
1884                 break;
1885             }
1886             default:
1887                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1888                 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1889                          msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1890             }
1891             if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1892                 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1893         }
1894     }
1895
1896     sequence_cnt++;
1897 }
1898
1899 /* try to make sure pending X events have been processed before continuing */
1900 static void flush_events(void)
1901 {
1902     MSG msg;
1903     int diff = 200;
1904     int min_timeout = 100;
1905     DWORD time = GetTickCount() + diff;
1906
1907     while (diff > 0)
1908     {
1909         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1910         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1911         diff = time - GetTickCount();
1912     }
1913 }
1914
1915 static void flush_sequence(void)
1916 {
1917     HeapFree(GetProcessHeap(), 0, sequence);
1918     sequence = 0;
1919     sequence_cnt = sequence_size = 0;
1920 }
1921
1922 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1923 {
1924     const struct recvd_message *actual = sequence;
1925     unsigned int count = 0;
1926
1927     trace_(file, line)("Failed sequence %s:\n", context );
1928     while (expected->message && actual->message)
1929     {
1930         if (actual->output[0])
1931         {
1932             if (expected->flags & hook)
1933             {
1934                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1935                                     count, expected->message, actual->output );
1936             }
1937             else if (expected->flags & winevent_hook)
1938             {
1939                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1940                                     count, expected->message, actual->output );
1941             }
1942             else
1943             {
1944                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1945                                     count, expected->message, actual->output );
1946             }
1947         }
1948
1949         if (expected->message == actual->message)
1950         {
1951             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1952                 (expected->flags & optional))
1953             {
1954                 /* don't match messages if their defwinproc status differs */
1955                 expected++;
1956             }
1957             else
1958             {
1959                 expected++;
1960                 actual++;
1961             }
1962         }
1963         /* silently drop winevent messages if there is no support for them */
1964         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1965             expected++;
1966         else
1967         {
1968             expected++;
1969             actual++;
1970         }
1971         count++;
1972     }
1973
1974     /* optional trailing messages */
1975     while (expected->message && ((expected->flags & optional) ||
1976             ((expected->flags & winevent_hook) && !hEvent_hook)))
1977     {
1978         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1979         expected++;
1980         count++;
1981     }
1982
1983     if (expected->message)
1984     {
1985         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1986         return;
1987     }
1988
1989     while (actual->message && actual->output[0])
1990     {
1991         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1992         actual++;
1993         count++;
1994     }
1995 }
1996
1997 #define ok_sequence( exp, contx, todo) \
1998         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1999
2000
2001 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2002                          const char *file, int line)
2003 {
2004     static const struct recvd_message end_of_sequence;
2005     const struct message *expected = expected_list;
2006     const struct recvd_message *actual;
2007     int failcount = 0, dump = 0;
2008     unsigned int count = 0;
2009
2010     add_message(&end_of_sequence);
2011
2012     actual = sequence;
2013
2014     while (expected->message && actual->message)
2015     {
2016         if (expected->message == actual->message)
2017         {
2018             if (expected->flags & wparam)
2019             {
2020                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2021                 {
2022                     todo_wine {
2023                         failcount ++;
2024                         if (strcmp(winetest_platform, "wine")) dump++;
2025                         ok_( file, line) (FALSE,
2026                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2027                             context, count, expected->message, expected->wParam, actual->wParam);
2028                     }
2029                 }
2030                 else
2031                 {
2032                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2033                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2034                                      context, count, expected->message, expected->wParam, actual->wParam);
2035                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2036                 }
2037
2038             }
2039             if (expected->flags & lparam)
2040             {
2041                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2042                 {
2043                     todo_wine {
2044                         failcount ++;
2045                         if (strcmp(winetest_platform, "wine")) dump++;
2046                         ok_( file, line) (FALSE,
2047                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2048                             context, count, expected->message, expected->lParam, actual->lParam);
2049                     }
2050                 }
2051                 else
2052                 {
2053                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2054                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2055                                      context, count, expected->message, expected->lParam, actual->lParam);
2056                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2057                 }
2058             }
2059             if ((expected->flags & optional) &&
2060                 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2061             {
2062                 /* don't match optional messages if their defwinproc or parent status differs */
2063                 expected++;
2064                 count++;
2065                 continue;
2066             }
2067             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2068             {
2069                     todo_wine {
2070                         failcount ++;
2071                         if (strcmp(winetest_platform, "wine")) dump++;
2072                         ok_( file, line) (FALSE,
2073                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2074                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2075                     }
2076             }
2077             else
2078             {
2079                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2080                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2081                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2082                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2083             }
2084
2085             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2086                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2087                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2088             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2089
2090             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2091                 "%s: %u: the msg 0x%04x should have been %s\n",
2092                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2093             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2094
2095             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2096                 "%s: %u: the msg 0x%04x was expected in %s\n",
2097                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2098             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2099
2100             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2101                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2102                 context, count, expected->message);
2103             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2104
2105             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2106                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2107                 context, count, expected->message);
2108             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2109
2110             expected++;
2111             actual++;
2112         }
2113         /* silently drop hook messages if there is no support for them */
2114         else if ((expected->flags & optional) ||
2115                  ((expected->flags & hook) && !hCBT_hook) ||
2116                  ((expected->flags & winevent_hook) && !hEvent_hook))
2117             expected++;
2118         else if (todo)
2119         {
2120             failcount++;
2121             todo_wine {
2122                 if (strcmp(winetest_platform, "wine")) dump++;
2123                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2124                                   context, count, expected->message, actual->message);
2125             }
2126             goto done;
2127         }
2128         else
2129         {
2130             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2131                               context, count, expected->message, actual->message);
2132             dump++;
2133             expected++;
2134             actual++;
2135         }
2136         count++;
2137     }
2138
2139     /* skip all optional trailing messages */
2140     while (expected->message && ((expected->flags & optional) ||
2141                                  ((expected->flags & hook) && !hCBT_hook) ||
2142                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2143         expected++;
2144
2145     if (todo)
2146     {
2147         todo_wine {
2148             if (expected->message || actual->message) {
2149                 failcount++;
2150                 if (strcmp(winetest_platform, "wine")) dump++;
2151                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2152                                   context, count, expected->message, actual->message);
2153             }
2154         }
2155     }
2156     else
2157     {
2158         if (expected->message || actual->message)
2159         {
2160             dump++;
2161             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2162                               context, count, expected->message, actual->message);
2163         }
2164     }
2165     if( todo && !failcount) /* succeeded yet marked todo */
2166         todo_wine {
2167             if (!strcmp(winetest_platform, "wine")) dump++;
2168             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2169         }
2170
2171 done:
2172     if (dump) dump_sequence(expected_list, context, file, line);
2173     flush_sequence();
2174 }
2175
2176 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2177
2178 /******************************** MDI test **********************************/
2179
2180 /* CreateWindow for MDI frame window, initially visible */
2181 static const struct message WmCreateMDIframeSeq[] = {
2182     { HCBT_CREATEWND, hook },
2183     { WM_GETMINMAXINFO, sent },
2184     { WM_NCCREATE, sent },
2185     { WM_NCCALCSIZE, sent|wparam, 0 },
2186     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2187     { WM_CREATE, sent },
2188     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2189     { WM_NOTIFYFORMAT, sent|optional },
2190     { WM_QUERYUISTATE, sent|optional },
2191     { WM_WINDOWPOSCHANGING, sent|optional },
2192     { WM_GETMINMAXINFO, sent|optional },
2193     { WM_NCCALCSIZE, sent|optional },
2194     { WM_WINDOWPOSCHANGED, sent|optional },
2195     { WM_SHOWWINDOW, sent|wparam, 1 },
2196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2197     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2198     { HCBT_ACTIVATE, hook },
2199     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2200     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2201     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2202     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2203     { WM_NCACTIVATE, sent },
2204     { WM_GETTEXT, sent|defwinproc|optional },
2205     { WM_ACTIVATE, sent|wparam, 1 },
2206     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2207     { HCBT_SETFOCUS, hook },
2208     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2209     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2210     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2211     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2212     /* Win9x adds SWP_NOZORDER below */
2213     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2214     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2215     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2216     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2217     { WM_MOVE, sent },
2218     { 0 }
2219 };
2220 /* DestroyWindow for MDI frame window, initially visible */
2221 static const struct message WmDestroyMDIframeSeq[] = {
2222     { HCBT_DESTROYWND, hook },
2223     { 0x0090, sent|optional },
2224     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2225     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2226     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2227     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2228     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2229     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2230     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2231     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2232     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2233     { WM_DESTROY, sent },
2234     { WM_NCDESTROY, sent },
2235     { 0 }
2236 };
2237 /* CreateWindow for MDI client window, initially visible */
2238 static const struct message WmCreateMDIclientSeq[] = {
2239     { HCBT_CREATEWND, hook },
2240     { WM_NCCREATE, sent },
2241     { WM_NCCALCSIZE, sent|wparam, 0 },
2242     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2243     { WM_CREATE, sent },
2244     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2245     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2246     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2247     { WM_MOVE, sent },
2248     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2249     { WM_SHOWWINDOW, sent|wparam, 1 },
2250     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2251     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2252     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2253     { 0 }
2254 };
2255 /* ShowWindow(SW_SHOW) for MDI client window */
2256 static const struct message WmShowMDIclientSeq[] = {
2257     { WM_SHOWWINDOW, sent|wparam, 1 },
2258     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2259     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2260     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2261     { 0 }
2262 };
2263 /* ShowWindow(SW_HIDE) for MDI client window */
2264 static const struct message WmHideMDIclientSeq[] = {
2265     { WM_SHOWWINDOW, sent|wparam, 0 },
2266     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2267     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2268     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2269     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2270     { 0 }
2271 };
2272 /* DestroyWindow for MDI client window, initially visible */
2273 static const struct message WmDestroyMDIclientSeq[] = {
2274     { HCBT_DESTROYWND, hook },
2275     { 0x0090, sent|optional },
2276     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2277     { WM_SHOWWINDOW, sent|wparam, 0 },
2278     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2279     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2280     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2281     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2282     { WM_DESTROY, sent },
2283     { WM_NCDESTROY, sent },
2284     { 0 }
2285 };
2286 /* CreateWindow for MDI child window, initially visible */
2287 static const struct message WmCreateMDIchildVisibleSeq[] = {
2288     { HCBT_CREATEWND, hook },
2289     { WM_NCCREATE, sent }, 
2290     { WM_NCCALCSIZE, sent|wparam, 0 },
2291     { WM_CREATE, sent },
2292     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2293     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2294     { WM_MOVE, sent },
2295     /* Win2k sends wparam set to
2296      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2297      * while Win9x doesn't bother to set child window id according to
2298      * CLIENTCREATESTRUCT.idFirstChild
2299      */
2300     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2301     { WM_SHOWWINDOW, sent|wparam, 1 },
2302     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2303     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2304     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2305     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2306     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2307     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2308     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2309
2310     /* Win9x: message sequence terminates here. */
2311
2312     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2313     { HCBT_SETFOCUS, hook }, /* in MDI client */
2314     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2315     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2316     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2317     { WM_SETFOCUS, sent }, /* in MDI client */
2318     { HCBT_SETFOCUS, hook },
2319     { WM_KILLFOCUS, sent }, /* in MDI client */
2320     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2321     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2322     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2323     { WM_SETFOCUS, sent|defwinproc },
2324     { WM_MDIACTIVATE, sent|defwinproc },
2325     { 0 }
2326 };
2327 /* CreateWindow for MDI child window with invisible parent */
2328 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2329     { HCBT_CREATEWND, hook },
2330     { WM_GETMINMAXINFO, sent },
2331     { WM_NCCREATE, sent }, 
2332     { WM_NCCALCSIZE, sent|wparam, 0 },
2333     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2334     { WM_CREATE, sent },
2335     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2336     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2337     { WM_MOVE, sent },
2338     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2339     { WM_SHOWWINDOW, sent|wparam, 1 },
2340     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2341     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2342     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2343     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2344
2345     /* Win9x: message sequence terminates here. */
2346
2347     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2348     { HCBT_SETFOCUS, hook }, /* in MDI client */
2349     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2350     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2351     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2352     { WM_SETFOCUS, sent }, /* in MDI client */
2353     { HCBT_SETFOCUS, hook },
2354     { WM_KILLFOCUS, sent }, /* in MDI client */
2355     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2356     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2357     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2358     { WM_SETFOCUS, sent|defwinproc },
2359     { WM_MDIACTIVATE, sent|defwinproc },
2360     { 0 }
2361 };
2362 /* DestroyWindow for MDI child window, initially visible */
2363 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2364     { HCBT_DESTROYWND, hook },
2365     /* Win2k sends wparam set to
2366      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2367      * while Win9x doesn't bother to set child window id according to
2368      * CLIENTCREATESTRUCT.idFirstChild
2369      */
2370     { 0x0090, sent|optional },
2371     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2372     { WM_SHOWWINDOW, sent|wparam, 0 },
2373     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2374     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2375     { WM_ERASEBKGND, sent|parent|optional },
2376     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2377
2378     /* { WM_DESTROY, sent }
2379      * Win9x: message sequence terminates here.
2380      */
2381
2382     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2383     { WM_KILLFOCUS, sent },
2384     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2385     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2386     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2387     { WM_SETFOCUS, sent }, /* in MDI client */
2388
2389     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2390     { WM_KILLFOCUS, sent }, /* in MDI client */
2391     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2392     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2393     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2394     { WM_SETFOCUS, sent }, /* in MDI client */
2395
2396     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2397
2398     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2399     { WM_KILLFOCUS, sent },
2400     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2401     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2402     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2403     { WM_SETFOCUS, sent }, /* in MDI client */
2404
2405     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2406     { WM_KILLFOCUS, sent }, /* in MDI client */
2407     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2408     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2409     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2410     { WM_SETFOCUS, sent }, /* in MDI client */
2411
2412     { WM_DESTROY, sent },
2413
2414     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2415     { WM_KILLFOCUS, sent },
2416     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2417     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2418     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2419     { WM_SETFOCUS, sent }, /* in MDI client */
2420
2421     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2422     { WM_KILLFOCUS, sent }, /* in MDI client */
2423     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2424     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2425     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2426     { WM_SETFOCUS, sent }, /* in MDI client */
2427
2428     { WM_NCDESTROY, sent },
2429     { 0 }
2430 };
2431 /* CreateWindow for MDI child window, initially invisible */
2432 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2433     { HCBT_CREATEWND, hook },
2434     { WM_NCCREATE, sent }, 
2435     { WM_NCCALCSIZE, sent|wparam, 0 },
2436     { WM_CREATE, sent },
2437     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2438     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2439     { WM_MOVE, sent },
2440     /* Win2k sends wparam set to
2441      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2442      * while Win9x doesn't bother to set child window id according to
2443      * CLIENTCREATESTRUCT.idFirstChild
2444      */
2445     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2446     { 0 }
2447 };
2448 /* DestroyWindow for MDI child window, initially invisible */
2449 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2450     { HCBT_DESTROYWND, hook },
2451     /* Win2k sends wparam set to
2452      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2453      * while Win9x doesn't bother to set child window id according to
2454      * CLIENTCREATESTRUCT.idFirstChild
2455      */
2456     { 0x0090, sent|optional },
2457     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2458     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2459     { WM_DESTROY, sent },
2460     { WM_NCDESTROY, sent },
2461     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2462     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2463     { 0 }
2464 };
2465 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2466 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2467     { HCBT_CREATEWND, hook },
2468     { WM_NCCREATE, sent }, 
2469     { WM_NCCALCSIZE, sent|wparam, 0 },
2470     { WM_CREATE, sent },
2471     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2472     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2473     { WM_MOVE, sent },
2474     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2475     { WM_GETMINMAXINFO, sent },
2476     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2477     { WM_NCCALCSIZE, sent|wparam, 1 },
2478     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2479     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2480      /* in MDI frame */
2481     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2482     { WM_NCCALCSIZE, sent|wparam, 1 },
2483     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2484     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2485     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2486     /* Win2k sends wparam set to
2487      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2488      * while Win9x doesn't bother to set child window id according to
2489      * CLIENTCREATESTRUCT.idFirstChild
2490      */
2491     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2492     { WM_SHOWWINDOW, sent|wparam, 1 },
2493     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2494     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2495     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2496     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2497     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2498     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2499     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2500
2501     /* Win9x: message sequence terminates here. */
2502
2503     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2504     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2505     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2506     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2507     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2508     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2509     { HCBT_SETFOCUS, hook|optional },
2510     { WM_KILLFOCUS, sent|optional }, /* 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|optional },
2515     { WM_MDIACTIVATE, sent|defwinproc|optional },
2516      /* in MDI frame */
2517     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2518     { WM_NCCALCSIZE, sent|wparam, 1 },
2519     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2520     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2521     { 0 }
2522 };
2523 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2524 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2525     /* restore the 1st MDI child */
2526     { WM_SETREDRAW, sent|wparam, 0 },
2527     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2528     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2529     { WM_NCCALCSIZE, sent|wparam, 1 },
2530     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2531     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2532     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2533      /* in MDI frame */
2534     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2535     { WM_NCCALCSIZE, sent|wparam, 1 },
2536     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2537     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2538     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2539     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2540     /* create the 2nd MDI child */
2541     { HCBT_CREATEWND, hook },
2542     { WM_NCCREATE, sent }, 
2543     { WM_NCCALCSIZE, sent|wparam, 0 },
2544     { WM_CREATE, sent },
2545     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2546     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2547     { WM_MOVE, sent },
2548     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2549     { WM_GETMINMAXINFO, sent },
2550     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2551     { WM_NCCALCSIZE, sent|wparam, 1 },
2552     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2553     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2554     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2555      /* in MDI frame */
2556     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2557     { WM_NCCALCSIZE, sent|wparam, 1 },
2558     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2559     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2560     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2561     /* Win2k sends wparam set to
2562      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2563      * while Win9x doesn't bother to set child window id according to
2564      * CLIENTCREATESTRUCT.idFirstChild
2565      */
2566     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2567     { WM_SHOWWINDOW, sent|wparam, 1 },
2568     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2569     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2570     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2571     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2572     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2573     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2574
2575     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2576     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2577
2578     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2579
2580     /* Win9x: message sequence terminates here. */
2581
2582     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2583     { HCBT_SETFOCUS, hook },
2584     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2585     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2586     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2587     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2588     { WM_SETFOCUS, sent }, /* in MDI client */
2589     { HCBT_SETFOCUS, hook },
2590     { WM_KILLFOCUS, sent }, /* in MDI client */
2591     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2592     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2593     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2594     { WM_SETFOCUS, sent|defwinproc },
2595
2596     { WM_MDIACTIVATE, sent|defwinproc },
2597      /* in MDI frame */
2598     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2599     { WM_NCCALCSIZE, sent|wparam, 1 },
2600     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2601     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2602     { 0 }
2603 };
2604 /* WM_MDICREATE MDI child window, initially visible and maximized */
2605 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2606     { WM_MDICREATE, sent },
2607     { HCBT_CREATEWND, hook },
2608     { WM_NCCREATE, sent }, 
2609     { WM_NCCALCSIZE, sent|wparam, 0 },
2610     { WM_CREATE, sent },
2611     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2612     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2613     { WM_MOVE, sent },
2614     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2615     { WM_GETMINMAXINFO, sent },
2616     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2617     { WM_NCCALCSIZE, sent|wparam, 1 },
2618     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2619     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2620
2621      /* in MDI frame */
2622     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2623     { WM_NCCALCSIZE, sent|wparam, 1 },
2624     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2625     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2626     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2627
2628     /* Win2k sends wparam set to
2629      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2630      * while Win9x doesn't bother to set child window id according to
2631      * CLIENTCREATESTRUCT.idFirstChild
2632      */
2633     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2634     { WM_SHOWWINDOW, sent|wparam, 1 },
2635     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2636
2637     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2638
2639     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2640     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2641     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2642
2643     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2644     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2645
2646     /* Win9x: message sequence terminates here. */
2647
2648     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2649     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2650     { HCBT_SETFOCUS, hook }, /* in MDI client */
2651     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2652     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2653     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2654     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2655     { HCBT_SETFOCUS, hook|optional },
2656     { WM_KILLFOCUS, sent }, /* in MDI client */
2657     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2658     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2659     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2660     { WM_SETFOCUS, sent|defwinproc },
2661
2662     { WM_MDIACTIVATE, sent|defwinproc },
2663
2664      /* in MDI child */
2665     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2666     { WM_NCCALCSIZE, sent|wparam, 1 },
2667     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2668     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2669
2670      /* in MDI frame */
2671     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2672     { WM_NCCALCSIZE, sent|wparam, 1 },
2673     { 0x0093, sent|defwinproc|optional },
2674     { 0x0093, sent|defwinproc|optional },
2675     { 0x0093, sent|defwinproc|optional },
2676     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2677     { WM_MOVE, sent|defwinproc },
2678     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2679
2680      /* in MDI client */
2681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2682     { WM_NCCALCSIZE, sent|wparam, 1 },
2683     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2684     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2685
2686      /* in MDI child */
2687     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2688     { WM_NCCALCSIZE, sent|wparam, 1 },
2689     { 0x0093, sent|optional },
2690     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2691     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2692
2693     { 0x0093, sent|optional },
2694     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2695     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2696     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2697     { 0x0093, sent|defwinproc|optional },
2698     { 0x0093, sent|defwinproc|optional },
2699     { 0x0093, sent|defwinproc|optional },
2700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2701     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2702
2703     { 0 }
2704 };
2705 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2706 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2707     { HCBT_CREATEWND, hook },
2708     { WM_GETMINMAXINFO, sent },
2709     { WM_NCCREATE, sent }, 
2710     { WM_NCCALCSIZE, sent|wparam, 0 },
2711     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2712     { WM_CREATE, sent },
2713     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2714     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2715     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2716     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2717     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2718     { WM_MOVE, sent },
2719     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2720     { WM_GETMINMAXINFO, sent },
2721     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2722     { WM_GETMINMAXINFO, sent|defwinproc },
2723     { WM_NCCALCSIZE, sent|wparam, 1 },
2724     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2725     { WM_MOVE, sent|defwinproc },
2726     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2727      /* in MDI frame */
2728     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2729     { WM_NCCALCSIZE, sent|wparam, 1 },
2730     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2731     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2732     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2733     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2734     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2735     /* Win2k sends wparam set to
2736      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2737      * while Win9x doesn't bother to set child window id according to
2738      * CLIENTCREATESTRUCT.idFirstChild
2739      */
2740     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2741     { 0 }
2742 };
2743 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2744 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2745     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2746     { HCBT_SYSCOMMAND, hook },
2747     { WM_CLOSE, sent|defwinproc },
2748     { WM_MDIDESTROY, sent }, /* in MDI client */
2749
2750     /* bring the 1st MDI child to top */
2751     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2752     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2753
2754     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2755
2756     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2757     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2758     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2759
2760     /* maximize the 1st MDI child */
2761     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2762     { WM_GETMINMAXINFO, sent|defwinproc },
2763     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2764     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2765     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2766     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2767     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2768
2769     /* restore the 2nd MDI child */
2770     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2771     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2772     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2773     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2774
2775     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2776
2777     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2778     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2779
2780     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2781
2782     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2783      /* in MDI frame */
2784     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2785     { WM_NCCALCSIZE, sent|wparam, 1 },
2786     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2787     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2788     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2789
2790     /* bring the 1st MDI child to top */
2791     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2792     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2793     { HCBT_SETFOCUS, hook },
2794     { WM_KILLFOCUS, sent|defwinproc },
2795     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2796     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2797     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2798     { WM_SETFOCUS, sent }, /* in MDI client */
2799     { HCBT_SETFOCUS, hook },
2800     { WM_KILLFOCUS, sent }, /* in MDI client */
2801     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2802     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2803     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2804     { WM_SETFOCUS, sent|defwinproc },
2805     { WM_MDIACTIVATE, sent|defwinproc },
2806     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2807
2808     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2809     { WM_SHOWWINDOW, sent|wparam, 1 },
2810     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2812     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2813     { WM_MDIREFRESHMENU, sent },
2814
2815     { HCBT_DESTROYWND, hook },
2816     /* Win2k sends wparam set to
2817      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2818      * while Win9x doesn't bother to set child window id according to
2819      * CLIENTCREATESTRUCT.idFirstChild
2820      */
2821     { 0x0090, sent|defwinproc|optional },
2822     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2823     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2824     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2825     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2826     { WM_ERASEBKGND, sent|parent|optional },
2827     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2828
2829     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2830     { WM_DESTROY, sent|defwinproc },
2831     { WM_NCDESTROY, sent|defwinproc },
2832     { 0 }
2833 };
2834 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2835 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2836     { WM_MDIDESTROY, sent }, /* in MDI client */
2837     { WM_SHOWWINDOW, sent|wparam, 0 },
2838     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2839     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2840     { WM_ERASEBKGND, sent|parent|optional },
2841     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2842
2843     { HCBT_SETFOCUS, hook },
2844     { WM_KILLFOCUS, sent },
2845     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2846     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2847     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2848     { WM_SETFOCUS, sent }, /* in MDI client */
2849     { HCBT_SETFOCUS, hook },
2850     { WM_KILLFOCUS, sent }, /* in MDI client */
2851     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2852     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2853     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2854     { WM_SETFOCUS, sent },
2855
2856      /* in MDI child */
2857     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2858     { WM_NCCALCSIZE, sent|wparam, 1 },
2859     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2860     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2861
2862      /* in MDI frame */
2863     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2864     { WM_NCCALCSIZE, sent|wparam, 1 },
2865     { 0x0093, sent|defwinproc|optional },
2866     { 0x0093, sent|defwinproc|optional },
2867     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2868     { WM_MOVE, sent|defwinproc },
2869     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2870
2871      /* in MDI client */
2872     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2873     { WM_NCCALCSIZE, sent|wparam, 1 },
2874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2875     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2876
2877      /* in MDI child */
2878     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2879     { WM_NCCALCSIZE, sent|wparam, 1 },
2880     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2881     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2882
2883      /* in MDI child */
2884     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2885     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2886     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2887     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2888
2889      /* in MDI frame */
2890     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2891     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2892     { 0x0093, sent|defwinproc|optional },
2893     { 0x0093, sent|defwinproc|optional },
2894     { 0x0093, sent|defwinproc|optional },
2895     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2896     { WM_MOVE, sent|defwinproc },
2897     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2898
2899      /* in MDI client */
2900     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2901     { WM_NCCALCSIZE, sent|wparam, 1 },
2902     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2903     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2904
2905      /* in MDI child */
2906     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2907     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2908     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2909     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2910     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2911     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2912
2913     { 0x0093, sent|defwinproc|optional },
2914     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2915     { 0x0093, sent|defwinproc|optional },
2916     { 0x0093, sent|defwinproc|optional },
2917     { 0x0093, sent|defwinproc|optional },
2918     { 0x0093, sent|optional },
2919
2920     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2921     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2922     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2923     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2924     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2925
2926      /* in MDI frame */
2927     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2928     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2929     { 0x0093, sent|defwinproc|optional },
2930     { 0x0093, sent|defwinproc|optional },
2931     { 0x0093, sent|defwinproc|optional },
2932     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2933     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2934     { 0x0093, sent|optional },
2935
2936     { WM_NCACTIVATE, sent|wparam, 0 },
2937     { WM_MDIACTIVATE, sent },
2938
2939     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2940     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2941     { WM_NCCALCSIZE, sent|wparam, 1 },
2942
2943     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2944
2945     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2946     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2947     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2948
2949      /* in MDI child */
2950     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2951     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2952     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2953     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2954
2955      /* in MDI frame */
2956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2957     { WM_NCCALCSIZE, sent|wparam, 1 },
2958     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2959     { WM_MOVE, sent|defwinproc },
2960     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2961
2962      /* in MDI client */
2963     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2964     { WM_NCCALCSIZE, sent|wparam, 1 },
2965     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2966     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2967     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2968     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2969     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2970     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2971     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2972
2973     { HCBT_SETFOCUS, hook },
2974     { WM_KILLFOCUS, sent },
2975     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2976     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2977     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2978     { WM_SETFOCUS, sent }, /* in MDI client */
2979
2980     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2981
2982     { HCBT_DESTROYWND, hook },
2983     /* Win2k sends wparam set to
2984      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2985      * while Win9x doesn't bother to set child window id according to
2986      * CLIENTCREATESTRUCT.idFirstChild
2987      */
2988     { 0x0090, sent|optional },
2989     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2990
2991     { WM_SHOWWINDOW, sent|wparam, 0 },
2992     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2993     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2994     { WM_ERASEBKGND, sent|parent|optional },
2995     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2996
2997     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2998     { WM_DESTROY, sent },
2999     { WM_NCDESTROY, sent },
3000     { 0 }
3001 };
3002 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3003 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3004     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3005     { WM_GETMINMAXINFO, sent },
3006     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3007     { WM_NCCALCSIZE, sent|wparam, 1 },
3008     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3009     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3010
3011     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3012     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3013     { HCBT_SETFOCUS, hook|optional },
3014     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3015     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3016     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3017     { HCBT_SETFOCUS, hook|optional },
3018     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3019     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3020     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3021     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3022     { WM_SETFOCUS, sent|optional|defwinproc },
3023     { WM_MDIACTIVATE, sent|optional|defwinproc },
3024     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3025     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3026      /* in MDI frame */
3027     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3028     { WM_NCCALCSIZE, sent|wparam, 1 },
3029     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3030     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3032     { 0 }
3033 };
3034 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3035 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3036     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3037     { WM_GETMINMAXINFO, sent },
3038     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3039     { WM_GETMINMAXINFO, sent|defwinproc },
3040     { WM_NCCALCSIZE, sent|wparam, 1 },
3041     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3042     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3043
3044     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3045     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3046     { HCBT_SETFOCUS, hook|optional },
3047     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3048     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3049     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3050     { HCBT_SETFOCUS, hook|optional },
3051     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3052     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3053     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3054     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3055     { WM_SETFOCUS, sent|defwinproc|optional },
3056     { WM_MDIACTIVATE, sent|defwinproc|optional },
3057     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3058     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3059     { 0 }
3060 };
3061 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3062 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3063     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3064     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3065     { WM_GETMINMAXINFO, sent },
3066     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3067     { WM_GETMINMAXINFO, sent|defwinproc },
3068     { WM_NCCALCSIZE, sent|wparam, 1 },
3069     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3070     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3071     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3072     { WM_MOVE, sent|defwinproc },
3073     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3074
3075     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3076     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3077     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3078     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3079     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3080     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3081      /* in MDI frame */
3082     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3083     { WM_NCCALCSIZE, sent|wparam, 1 },
3084     { 0x0093, sent|defwinproc|optional },
3085     { 0x0094, sent|defwinproc|optional },
3086     { 0x0094, sent|defwinproc|optional },
3087     { 0x0094, sent|defwinproc|optional },
3088     { 0x0094, sent|defwinproc|optional },
3089     { 0x0093, sent|defwinproc|optional },
3090     { 0x0093, sent|defwinproc|optional },
3091     { 0x0091, sent|defwinproc|optional },
3092     { 0x0092, sent|defwinproc|optional },
3093     { 0x0092, sent|defwinproc|optional },
3094     { 0x0092, sent|defwinproc|optional },
3095     { 0x0092, sent|defwinproc|optional },
3096     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3097     { WM_MOVE, sent|defwinproc },
3098     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3099     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3100      /* in MDI client */
3101     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3102     { WM_NCCALCSIZE, sent|wparam, 1 },
3103     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3104     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3105      /* in MDI child */
3106     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3107     { WM_GETMINMAXINFO, sent|defwinproc },
3108     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3109     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3110     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3111     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3112     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3113     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3114     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3115     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3116      /* in MDI frame */
3117     { 0x0093, sent|optional },
3118     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3119     { 0x0093, sent|defwinproc|optional },
3120     { 0x0093, sent|defwinproc|optional },
3121     { 0x0093, sent|defwinproc|optional },
3122     { 0x0091, sent|defwinproc|optional },
3123     { 0x0092, sent|defwinproc|optional },
3124     { 0x0092, sent|defwinproc|optional },
3125     { 0x0092, sent|defwinproc|optional },
3126     { 0x0092, sent|defwinproc|optional },
3127     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3128     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3129     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3130     { 0 }
3131 };
3132 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3133 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3134     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3135     { WM_GETMINMAXINFO, sent },
3136     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3137     { WM_NCCALCSIZE, sent|wparam, 1 },
3138     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3139     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3140     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3141      /* in MDI frame */
3142     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3143     { WM_NCCALCSIZE, sent|wparam, 1 },
3144     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3145     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3146     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3147     { 0 }
3148 };
3149 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3150 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3151     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3152     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3153     { WM_NCCALCSIZE, sent|wparam, 1 },
3154     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3155     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3156     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3157      /* in MDI frame */
3158     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3159     { WM_NCCALCSIZE, sent|wparam, 1 },
3160     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3161     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3162     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3163     { 0 }
3164 };
3165 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3166 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3167     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3168     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3169     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3170     { WM_NCCALCSIZE, sent|wparam, 1 },
3171     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3172     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3173     { WM_MOVE, sent|defwinproc },
3174     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3175     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3176     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3177     { HCBT_SETFOCUS, hook },
3178     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3179     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3180     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3181     { WM_SETFOCUS, sent },
3182     { 0 }
3183 };
3184 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3185 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3186     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3187     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3188     { WM_NCCALCSIZE, sent|wparam, 1 },
3189     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3190     { WM_MOVE, sent|defwinproc },
3191     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3192     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3193     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3194     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3195     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3196     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3197     { 0 }
3198 };
3199 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3200 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3201     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3203     { WM_NCCALCSIZE, sent|wparam, 1 },
3204     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3205     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3206     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3207     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3208      /* in MDI frame */
3209     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3210     { WM_NCCALCSIZE, sent|wparam, 1 },
3211     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3212     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3213     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3214     { 0 }
3215 };
3216
3217 static HWND mdi_client;
3218 static WNDPROC old_mdi_client_proc;
3219
3220 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3221 {
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_MDIGETACTIVE &&
3232         !ignore_message( message ))
3233     {
3234         msg.hwnd = hwnd;
3235         msg.message = message;
3236         msg.flags = sent|wparam|lparam;
3237         msg.wParam = wParam;
3238         msg.lParam = lParam;
3239         msg.descr = "mdi client";
3240         add_message(&msg);
3241     }
3242
3243     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3244 }
3245
3246 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3247 {
3248     static LONG defwndproc_counter = 0;
3249     LRESULT ret;
3250     struct recvd_message msg;
3251
3252     /* do not log painting messages */
3253     if (message != WM_PAINT &&
3254         message != WM_NCPAINT &&
3255         message != WM_SYNCPAINT &&
3256         message != WM_ERASEBKGND &&
3257         message != WM_NCHITTEST &&
3258         message != WM_GETTEXT &&
3259         !ignore_message( message ))
3260     {
3261         switch (message)
3262         {
3263             case WM_MDIACTIVATE:
3264             {
3265                 HWND active, client = GetParent(hwnd);
3266
3267                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3268
3269                 if (hwnd == (HWND)lParam) /* if we are being activated */
3270                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3271                 else
3272                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3273                 break;
3274             }
3275         }
3276
3277         msg.hwnd = hwnd;
3278         msg.message = message;
3279         msg.flags = sent|wparam|lparam;
3280         if (defwndproc_counter) msg.flags |= defwinproc;
3281         msg.wParam = wParam;
3282         msg.lParam = lParam;
3283         msg.descr = "mdi child";
3284         add_message(&msg);
3285     }
3286
3287     defwndproc_counter++;
3288     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3289     defwndproc_counter--;
3290
3291     return ret;
3292 }
3293
3294 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3295 {
3296     static LONG defwndproc_counter = 0;
3297     LRESULT ret;
3298     struct recvd_message msg;
3299
3300     /* do not log painting messages */
3301     if (message != WM_PAINT &&
3302         message != WM_NCPAINT &&
3303         message != WM_SYNCPAINT &&
3304         message != WM_ERASEBKGND &&
3305         message != WM_NCHITTEST &&
3306         message != WM_GETTEXT &&
3307         !ignore_message( message ))
3308     {
3309         msg.hwnd = hwnd;
3310         msg.message = message;
3311         msg.flags = sent|wparam|lparam;
3312         if (defwndproc_counter) msg.flags |= defwinproc;
3313         msg.wParam = wParam;
3314         msg.lParam = lParam;
3315         msg.descr = "mdi frame";
3316         add_message(&msg);
3317     }
3318
3319     defwndproc_counter++;
3320     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3321     defwndproc_counter--;
3322
3323     return ret;
3324 }
3325
3326 static BOOL mdi_RegisterWindowClasses(void)
3327 {
3328     WNDCLASSA cls;
3329
3330     cls.style = 0;
3331     cls.lpfnWndProc = mdi_frame_wnd_proc;
3332     cls.cbClsExtra = 0;
3333     cls.cbWndExtra = 0;
3334     cls.hInstance = GetModuleHandleA(0);
3335     cls.hIcon = 0;
3336     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3337     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3338     cls.lpszMenuName = NULL;
3339     cls.lpszClassName = "MDI_frame_class";
3340     if (!RegisterClassA(&cls)) return FALSE;
3341
3342     cls.lpfnWndProc = mdi_child_wnd_proc;
3343     cls.lpszClassName = "MDI_child_class";
3344     if (!RegisterClassA(&cls)) return FALSE;
3345
3346     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3347     old_mdi_client_proc = cls.lpfnWndProc;
3348     cls.hInstance = GetModuleHandleA(0);
3349     cls.lpfnWndProc = mdi_client_hook_proc;
3350     cls.lpszClassName = "MDI_client_class";
3351     if (!RegisterClassA(&cls)) assert(0);
3352
3353     return TRUE;
3354 }
3355
3356 static void test_mdi_messages(void)
3357 {
3358     MDICREATESTRUCTA mdi_cs;
3359     CLIENTCREATESTRUCT client_cs;
3360     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3361     BOOL zoomed;
3362     HMENU hMenu = CreateMenu();
3363
3364     assert(mdi_RegisterWindowClasses());
3365
3366     flush_sequence();
3367
3368     trace("creating MDI frame window\n");
3369     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3370                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3371                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3372                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3373                                 GetDesktopWindow(), hMenu,
3374                                 GetModuleHandleA(0), NULL);
3375     assert(mdi_frame);
3376     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3377
3378     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3379     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3380
3381     trace("creating MDI client window\n");
3382     client_cs.hWindowMenu = 0;
3383     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3384     mdi_client = CreateWindowExA(0, "MDI_client_class",
3385                                  NULL,
3386                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3387                                  0, 0, 0, 0,
3388                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3389     assert(mdi_client);
3390     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3391
3392     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3393     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3394
3395     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3396     ok(!active_child, "wrong active MDI child %p\n", active_child);
3397     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3398
3399     SetFocus(0);
3400     flush_sequence();
3401
3402     trace("creating invisible MDI child window\n");
3403     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3404                                 WS_CHILD,
3405                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3406                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3407     assert(mdi_child);
3408
3409     flush_sequence();
3410     ShowWindow(mdi_child, SW_SHOWNORMAL);
3411     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3412
3413     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3414     ok(IsWindowVisible(mdi_child), "MDI child should 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     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3420     ok(!active_child, "wrong active MDI child %p\n", active_child);
3421     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3422
3423     ShowWindow(mdi_child, SW_HIDE);
3424     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3425     flush_sequence();
3426
3427     ShowWindow(mdi_child, SW_SHOW);
3428     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3429
3430     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3431     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3432
3433     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3434     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3435
3436     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3437     ok(!active_child, "wrong active MDI child %p\n", active_child);
3438     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3439
3440     DestroyWindow(mdi_child);
3441     flush_sequence();
3442
3443     trace("creating visible MDI child window\n");
3444     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3445                                 WS_CHILD | WS_VISIBLE,
3446                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3447                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3448     assert(mdi_child);
3449     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3450
3451     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3452     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3453
3454     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3455     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3456
3457     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3458     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3459     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3460     flush_sequence();
3461
3462     DestroyWindow(mdi_child);
3463     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3464
3465     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3466     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3467
3468     /* Win2k: MDI client still returns a just destroyed child as active
3469      * Win9x: MDI client returns 0
3470      */
3471     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3472     ok(active_child == mdi_child || /* win2k */
3473        !active_child, /* win9x */
3474        "wrong active MDI child %p\n", active_child);
3475     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3476
3477     flush_sequence();
3478
3479     trace("creating invisible MDI child window\n");
3480     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3481                                 WS_CHILD,
3482                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3483                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3484     assert(mdi_child2);
3485     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3486
3487     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3488     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3489
3490     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3491     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3492
3493     /* Win2k: MDI client still returns a just destroyed child as active
3494      * Win9x: MDI client returns mdi_child2
3495      */
3496     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3497     ok(active_child == mdi_child || /* win2k */
3498        active_child == mdi_child2, /* win9x */
3499        "wrong active MDI child %p\n", active_child);
3500     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3501     flush_sequence();
3502
3503     ShowWindow(mdi_child2, SW_MAXIMIZE);
3504     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3505
3506     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3507     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3508
3509     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3510     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3511     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3512     flush_sequence();
3513
3514     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3515     ok(GetFocus() == mdi_child2 || /* win2k */
3516        GetFocus() == 0, /* win9x */
3517        "wrong focus window %p\n", GetFocus());
3518
3519     SetFocus(0);
3520     flush_sequence();
3521
3522     ShowWindow(mdi_child2, SW_HIDE);
3523     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3524
3525     ShowWindow(mdi_child2, SW_RESTORE);
3526     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3527     flush_sequence();
3528
3529     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3530     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3531
3532     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3533     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3534     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3535     flush_sequence();
3536
3537     SetFocus(0);
3538     flush_sequence();
3539
3540     ShowWindow(mdi_child2, SW_HIDE);
3541     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3542
3543     ShowWindow(mdi_child2, SW_SHOW);
3544     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3545
3546     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3547     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3548
3549     ShowWindow(mdi_child2, SW_MAXIMIZE);
3550     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3551
3552     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3553     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3554
3555     ShowWindow(mdi_child2, SW_RESTORE);
3556     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3557
3558     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3559     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3560
3561     ShowWindow(mdi_child2, SW_MINIMIZE);
3562     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3563
3564     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3565     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3566
3567     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3568     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3569     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3570     flush_sequence();
3571
3572     ShowWindow(mdi_child2, SW_RESTORE);
3573     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3574
3575     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3576     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3577
3578     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3579     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3580     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3581     flush_sequence();
3582
3583     SetFocus(0);
3584     flush_sequence();
3585
3586     ShowWindow(mdi_child2, SW_HIDE);
3587     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3588
3589     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3590     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3591
3592     DestroyWindow(mdi_child2);
3593     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3594
3595     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3596     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3597
3598     /* test for maximized MDI children */
3599     trace("creating maximized visible MDI child window 1\n");
3600     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3601                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3602                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3603                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3604     assert(mdi_child);
3605     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3606     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3607
3608     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3609     ok(GetFocus() == mdi_child || /* win2k */
3610        GetFocus() == 0, /* win9x */
3611        "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     trace("creating maximized visible MDI child window 2\n");
3619     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3620                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3621                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3622                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3623     assert(mdi_child2);
3624     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3625     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3626     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3627
3628     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3629     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3630
3631     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3632     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3633     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3634     flush_sequence();
3635
3636     trace("destroying maximized visible MDI child window 2\n");
3637     DestroyWindow(mdi_child2);
3638     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3639
3640     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3641
3642     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3643     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3644
3645     /* Win2k: MDI client still returns a just destroyed child as active
3646      * Win9x: MDI client returns 0
3647      */
3648     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3649     ok(active_child == mdi_child2 || /* win2k */
3650        !active_child, /* win9x */
3651        "wrong active MDI child %p\n", active_child);
3652     flush_sequence();
3653
3654     ShowWindow(mdi_child, SW_MAXIMIZE);
3655     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3656     flush_sequence();
3657
3658     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3659     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3660
3661     trace("re-creating maximized visible MDI child window 2\n");
3662     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3663                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3664                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3665                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3666     assert(mdi_child2);
3667     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3668     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3669     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3670
3671     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3672     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3673
3674     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3675     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3676     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3677     flush_sequence();
3678
3679     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3680     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3681     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3682
3683     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3684     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3685     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3686
3687     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3688     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3689     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3690     flush_sequence();
3691
3692     DestroyWindow(mdi_child);
3693     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3694
3695     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3696     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3697
3698     /* Win2k: MDI client still returns a just destroyed child as active
3699      * Win9x: MDI client returns 0
3700      */
3701     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3702     ok(active_child == mdi_child || /* win2k */
3703        !active_child, /* win9x */
3704        "wrong active MDI child %p\n", active_child);
3705     flush_sequence();
3706
3707     trace("creating maximized invisible MDI child window\n");
3708     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3709                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3710                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3711                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3712     assert(mdi_child2);
3713     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3714     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3715     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3716     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3717
3718     /* Win2k: MDI client still returns a just destroyed child as active
3719      * Win9x: MDI client returns 0
3720      */
3721     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3722     ok(active_child == mdi_child || /* win2k */
3723        !active_child || active_child == mdi_child2, /* win9x */
3724        "wrong active MDI child %p\n", active_child);
3725     flush_sequence();
3726
3727     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3728     ShowWindow(mdi_child2, SW_MAXIMIZE);
3729     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3730     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3731     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3732     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3733
3734     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3735     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3736     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3737     flush_sequence();
3738
3739     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3740     flush_sequence();
3741
3742     /* end of test for maximized MDI children */
3743     SetFocus(0);
3744     flush_sequence();
3745     trace("creating maximized visible MDI child window 1(Switch test)\n");
3746     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3747                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3748                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3749                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3750     assert(mdi_child);
3751     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3752     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3753
3754     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3755     ok(GetFocus() == mdi_child || /* win2k */
3756        GetFocus() == 0, /* win9x */
3757        "wrong focus window %p(Switch test)\n", GetFocus());
3758
3759     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3760     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3761     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3762     flush_sequence();
3763
3764     trace("creating maximized visible MDI child window 2(Switch test)\n");
3765     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3766                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3767                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3768                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3769     assert(mdi_child2);
3770     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3771
3772     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3773     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3774
3775     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3776     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3777
3778     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3779     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3780     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3781     flush_sequence();
3782
3783     trace("Switch child window.\n");
3784     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3785     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3786     trace("end of test for switch maximized MDI children\n");
3787     flush_sequence();
3788
3789     /* Prepare for switching test of not maximized MDI children  */
3790     ShowWindow( mdi_child, SW_NORMAL );
3791     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3792     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3793     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3794     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3795     flush_sequence();
3796
3797     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3798     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3799     trace("end of test for switch not maximized MDI children\n");
3800     flush_sequence();
3801
3802     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3803     flush_sequence();
3804
3805     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3806     flush_sequence();
3807
3808     SetFocus(0);
3809     flush_sequence();
3810     /* end of tests for switch maximized/not maximized MDI children */
3811
3812     mdi_cs.szClass = "MDI_child_Class";
3813     mdi_cs.szTitle = "MDI child";
3814     mdi_cs.hOwner = GetModuleHandleA(0);
3815     mdi_cs.x = 0;
3816     mdi_cs.y = 0;
3817     mdi_cs.cx = CW_USEDEFAULT;
3818     mdi_cs.cy = CW_USEDEFAULT;
3819     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3820     mdi_cs.lParam = 0;
3821     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3822     ok(mdi_child != 0, "MDI child creation failed\n");
3823     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3824
3825     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3826
3827     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3828     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3829
3830     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3831     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3832     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3833
3834     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3835     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3836     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3837     flush_sequence();
3838
3839     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3840     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3841
3842     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3843     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3844     ok(!active_child, "wrong active MDI child %p\n", active_child);
3845
3846     SetFocus(0);
3847     flush_sequence();
3848
3849     DestroyWindow(mdi_client);
3850     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3851
3852     /* test maximization of MDI child with invisible parent */
3853     client_cs.hWindowMenu = 0;
3854     mdi_client = CreateWindow("MDI_client_class",
3855                                  NULL,
3856                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3857                                  0, 0, 660, 430,
3858                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3859     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3860
3861     ShowWindow(mdi_client, SW_HIDE);
3862     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3863
3864     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3865                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3866                                 0, 0, 650, 440,
3867                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3868     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3869
3870     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3871     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3872     zoomed = IsZoomed(mdi_child);
3873     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3874     
3875     ShowWindow(mdi_client, SW_SHOW);
3876     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3877
3878     DestroyWindow(mdi_child);
3879     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3880
3881     /* end of test for maximization of MDI child with invisible parent */
3882
3883     DestroyWindow(mdi_client);
3884     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3885
3886     DestroyWindow(mdi_frame);
3887     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3888 }
3889 /************************* End of MDI test **********************************/
3890
3891 static void test_WM_SETREDRAW(HWND hwnd)
3892 {
3893     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3894
3895     flush_events();
3896     flush_sequence();
3897
3898     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3899     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3900
3901     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3902     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3903
3904     flush_sequence();
3905     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3906     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3907
3908     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3909     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3910
3911     /* restore original WS_VISIBLE state */
3912     SetWindowLongA(hwnd, GWL_STYLE, style);
3913
3914     flush_events();
3915     flush_sequence();
3916 }
3917
3918 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3919 {
3920     struct recvd_message msg;
3921
3922     if (ignore_message( message )) return 0;
3923
3924     switch (message)
3925     {
3926         /* ignore */
3927         case WM_MOUSEMOVE:
3928         case WM_NCMOUSEMOVE:
3929         case WM_NCMOUSELEAVE:
3930         case WM_SETCURSOR:
3931             return 0;
3932         case WM_NCHITTEST:
3933             return HTCLIENT;
3934     }
3935
3936     msg.hwnd = hwnd;
3937     msg.message = message;
3938     msg.flags = sent|wparam|lparam;
3939     msg.wParam = wParam;
3940     msg.lParam = lParam;
3941     msg.descr = "dialog";
3942     add_message(&msg);
3943
3944     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3945     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3946     return 0;
3947 }
3948
3949 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3950 {
3951     DWORD style, exstyle;
3952     INT xmin, xmax;
3953     BOOL ret;
3954
3955     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3956     style = GetWindowLongA(hwnd, GWL_STYLE);
3957     /* do not be confused by WS_DLGFRAME set */
3958     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3959
3960     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3961     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3962
3963     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3964     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3965     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3966         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3967     else
3968         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3969
3970     style = GetWindowLongA(hwnd, GWL_STYLE);
3971     if (set) ok(style & set, "style %08x should be set\n", set);
3972     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3973
3974     /* a subsequent call should do nothing */
3975     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3976     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3977     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3978
3979     xmin = 0xdeadbeef;
3980     xmax = 0xdeadbeef;
3981     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3982     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3983     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3984     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3985     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3986 }
3987
3988 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3989 {
3990     DWORD style, exstyle;
3991     SCROLLINFO si;
3992     BOOL ret;
3993
3994     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3995     style = GetWindowLongA(hwnd, GWL_STYLE);
3996     /* do not be confused by WS_DLGFRAME set */
3997     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3998
3999     if (clear) ok(style & clear, "style %08x should be set\n", clear);
4000     if (set) ok(!(style & set), "style %08x should not be set\n", set);
4001
4002     si.cbSize = sizeof(si);
4003     si.fMask = SIF_RANGE;
4004     si.nMin = min;
4005     si.nMax = max;
4006     SetScrollInfo(hwnd, ctl, &si, TRUE);
4007     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4008         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4009     else
4010         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4011
4012     style = GetWindowLongA(hwnd, GWL_STYLE);
4013     if (set) ok(style & set, "style %08x should be set\n", set);
4014     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4015
4016     /* a subsequent call should do nothing */
4017     SetScrollInfo(hwnd, ctl, &si, TRUE);
4018     if (style & WS_HSCROLL)
4019         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4020     else if (style & WS_VSCROLL)
4021         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4022     else
4023         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4024
4025     si.fMask = SIF_PAGE;
4026     si.nPage = 5;
4027     SetScrollInfo(hwnd, ctl, &si, FALSE);
4028     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4029
4030     si.fMask = SIF_POS;
4031     si.nPos = max - 1;
4032     SetScrollInfo(hwnd, ctl, &si, FALSE);
4033     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4034
4035     si.fMask = SIF_RANGE;
4036     si.nMin = 0xdeadbeef;
4037     si.nMax = 0xdeadbeef;
4038     ret = GetScrollInfo(hwnd, ctl, &si);
4039     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4040     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4041     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4042     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4043 }
4044
4045 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4046 static void test_scroll_messages(HWND hwnd)
4047 {
4048     SCROLLINFO si;
4049     INT min, max;
4050     BOOL ret;
4051
4052     flush_events();
4053     flush_sequence();
4054
4055     min = 0xdeadbeef;
4056     max = 0xdeadbeef;
4057     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4058     ok( ret, "GetScrollRange error %d\n", GetLastError());
4059     if (sequence->message != WmGetScrollRangeSeq[0].message)
4060         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4061     /* values of min and max are undefined */
4062     flush_sequence();
4063
4064     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4065     ok( ret, "SetScrollRange error %d\n", GetLastError());
4066     if (sequence->message != WmSetScrollRangeSeq[0].message)
4067         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4068     flush_sequence();
4069
4070     min = 0xdeadbeef;
4071     max = 0xdeadbeef;
4072     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4073     ok( ret, "GetScrollRange error %d\n", GetLastError());
4074     if (sequence->message != WmGetScrollRangeSeq[0].message)
4075         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4076     /* values of min and max are undefined */
4077     flush_sequence();
4078
4079     si.cbSize = sizeof(si);
4080     si.fMask = SIF_RANGE;
4081     si.nMin = 20;
4082     si.nMax = 160;
4083     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4084     if (sequence->message != WmSetScrollRangeSeq[0].message)
4085         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4086     flush_sequence();
4087
4088     si.fMask = SIF_PAGE;
4089     si.nPage = 10;
4090     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4091     if (sequence->message != WmSetScrollRangeSeq[0].message)
4092         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4093     flush_sequence();
4094
4095     si.fMask = SIF_POS;
4096     si.nPos = 20;
4097     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4098     if (sequence->message != WmSetScrollRangeSeq[0].message)
4099         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4100     flush_sequence();
4101
4102     si.fMask = SIF_RANGE;
4103     si.nMin = 0xdeadbeef;
4104     si.nMax = 0xdeadbeef;
4105     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4106     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4107     if (sequence->message != WmGetScrollInfoSeq[0].message)
4108         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4109     /* values of min and max are undefined */
4110     flush_sequence();
4111
4112     /* set WS_HSCROLL */
4113     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4114     /* clear WS_HSCROLL */
4115     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4116
4117     /* set WS_HSCROLL */
4118     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4119     /* clear WS_HSCROLL */
4120     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4121
4122     /* set WS_VSCROLL */
4123     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4124     /* clear WS_VSCROLL */
4125     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4126
4127     /* set WS_VSCROLL */
4128     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4129     /* clear WS_VSCROLL */
4130     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4131 }
4132
4133 static void test_showwindow(void)
4134 {
4135     HWND hwnd, hchild;
4136     RECT rc;
4137
4138     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4139                            100, 100, 200, 200, 0, 0, 0, NULL);
4140     ok (hwnd != 0, "Failed to create overlapped window\n");
4141     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4142                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4143     ok (hchild != 0, "Failed to create child\n");
4144     flush_sequence();
4145
4146     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4147     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4148     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4149     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4150
4151     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4152     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4153     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4154     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4155     /* back to invisible */
4156     ShowWindow(hchild, SW_HIDE);
4157     ShowWindow(hwnd, SW_HIDE);
4158     flush_sequence();
4159     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4160     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4161     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4162     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4163     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4164     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4165     flush_sequence();
4166     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4167     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4168     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4169     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4170     ShowWindow( hwnd, SW_SHOW);
4171     flush_sequence();
4172     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4173     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4174     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4175
4176     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4177     ShowWindow( hchild, SW_HIDE);
4178     flush_sequence();
4179     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4180     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4181     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4182
4183     SetCapture(hchild);
4184     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4185     DestroyWindow(hchild);
4186     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4187
4188     DestroyWindow(hwnd);
4189     flush_sequence();
4190
4191     /* Popup windows */
4192     /* Test 1:
4193      * 1. Create invisible maximized popup window.
4194      * 2. Move and resize it.
4195      * 3. Show it maximized.
4196      */
4197     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4198     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4199                            100, 100, 200, 200, 0, 0, 0, NULL);
4200     ok (hwnd != 0, "Failed to create popup window\n");
4201     ok(IsZoomed(hwnd), "window should be maximized\n");
4202     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4203
4204     GetWindowRect(hwnd, &rc);
4205     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4206         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4207         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4208         rc.left, rc.top, rc.right, rc.bottom);
4209     /* Reset window's size & position */
4210     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4211     ok(IsZoomed(hwnd), "window should be maximized\n");
4212     flush_sequence();
4213
4214     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4215     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4216     ok(IsZoomed(hwnd), "window should be maximized\n");
4217     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4218
4219     GetWindowRect(hwnd, &rc);
4220     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4221         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4222         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4223         rc.left, rc.top, rc.right, rc.bottom);
4224     DestroyWindow(hwnd);
4225     flush_sequence();
4226
4227     /* Test 2:
4228      * 1. Create invisible maximized popup window.
4229      * 2. Show it maximized.
4230      */
4231     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4232     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4233                            100, 100, 200, 200, 0, 0, 0, NULL);
4234     ok (hwnd != 0, "Failed to create popup window\n");
4235     ok(IsZoomed(hwnd), "window should be maximized\n");
4236     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4237
4238     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4239     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4240     ok(IsZoomed(hwnd), "window should be maximized\n");
4241     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4242     DestroyWindow(hwnd);
4243     flush_sequence();
4244
4245     /* Test 3:
4246      * 1. Create visible maximized popup window.
4247      */
4248     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4249     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4250                            100, 100, 200, 200, 0, 0, 0, NULL);
4251     ok (hwnd != 0, "Failed to create popup window\n");
4252     ok(IsZoomed(hwnd), "window should be maximized\n");
4253     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4254     DestroyWindow(hwnd);
4255     flush_sequence();
4256
4257     /* Test 4:
4258      * 1. Create visible popup window.
4259      * 2. Maximize it.
4260      */
4261     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4262     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4263                            100, 100, 200, 200, 0, 0, 0, NULL);
4264     ok (hwnd != 0, "Failed to create popup window\n");
4265     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4266     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4267
4268     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4269     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4270     ok(IsZoomed(hwnd), "window should be maximized\n");
4271     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4272     DestroyWindow(hwnd);
4273     flush_sequence();
4274 }
4275
4276 static void test_sys_menu(void)
4277 {
4278     HWND hwnd;
4279     HMENU hmenu;
4280     UINT state;
4281
4282     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4283                            100, 100, 200, 200, 0, 0, 0, NULL);
4284     ok (hwnd != 0, "Failed to create overlapped window\n");
4285
4286     flush_sequence();
4287
4288     /* test existing window without CS_NOCLOSE style */
4289     hmenu = GetSystemMenu(hwnd, FALSE);
4290     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4291
4292     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4293     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4294     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4295
4296     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4297     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4298
4299     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4300     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4301     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4302
4303     EnableMenuItem(hmenu, SC_CLOSE, 0);
4304     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4305
4306     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4307     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4308     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4309
4310     /* test whether removing WS_SYSMENU destroys a system menu */
4311     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4312     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4313     flush_sequence();
4314     hmenu = GetSystemMenu(hwnd, FALSE);
4315     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4316
4317     DestroyWindow(hwnd);
4318
4319     /* test new window with CS_NOCLOSE style */
4320     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4321                            100, 100, 200, 200, 0, 0, 0, NULL);
4322     ok (hwnd != 0, "Failed to create overlapped window\n");
4323
4324     hmenu = GetSystemMenu(hwnd, FALSE);
4325     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4326
4327     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4328     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4329
4330     DestroyWindow(hwnd);
4331
4332     /* test new window without WS_SYSMENU style */
4333     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4334                            100, 100, 200, 200, 0, 0, 0, NULL);
4335     ok(hwnd != 0, "Failed to create overlapped window\n");
4336
4337     hmenu = GetSystemMenu(hwnd, FALSE);
4338     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4339
4340     DestroyWindow(hwnd);
4341 }
4342
4343 /* For shown WS_OVERLAPPEDWINDOW */
4344 static const struct message WmSetIcon_1[] = {
4345     { WM_SETICON, sent },
4346     { 0x00AE, sent|defwinproc|optional }, /* XP */
4347     { WM_GETTEXT, sent|defwinproc|optional },
4348     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4349     { 0 }
4350 };
4351
4352 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4353 static const struct message WmSetIcon_2[] = {
4354     { WM_SETICON, sent },
4355     { 0 }
4356 };
4357
4358 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4359 static const struct message WmInitEndSession[] = {
4360     { 0x003B, sent },
4361     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4362     { 0 }
4363 };
4364
4365 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4366 static const struct message WmInitEndSession_2[] = {
4367     { 0x003B, sent },
4368     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4369     { 0 }
4370 };
4371
4372 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4373 static const struct message WmInitEndSession_3[] = {
4374     { 0x003B, sent },
4375     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4376     { 0 }
4377 };
4378
4379 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4380 static const struct message WmInitEndSession_4[] = {
4381     { 0x003B, sent },
4382     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4383     { 0 }
4384 };
4385
4386 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4387 static const struct message WmInitEndSession_5[] = {
4388     { 0x003B, sent },
4389     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4390     { 0 }
4391 };
4392
4393 static const struct message WmOptionalPaint[] = {
4394     { WM_PAINT, sent|optional },
4395     { WM_NCPAINT, sent|beginpaint|optional },
4396     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4397     { WM_ERASEBKGND, sent|beginpaint|optional },
4398     { 0 }
4399 };
4400
4401 static const struct message WmZOrder[] = {
4402     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4403     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4404     { HCBT_ACTIVATE, hook },
4405     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4406     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4407     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4408     { WM_GETTEXT, sent|optional },
4409     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4410     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4411     { WM_NCACTIVATE, sent|lparam, 1, 0 },
4412     { WM_GETTEXT, sent|defwinproc|optional },
4413     { WM_GETTEXT, sent|defwinproc|optional },
4414     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4415     { HCBT_SETFOCUS, hook },
4416     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4417     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4418     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4419     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4420     { WM_GETTEXT, sent|optional },
4421     { WM_NCCALCSIZE, sent|optional },
4422     { 0 }
4423 };
4424
4425 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4426 {
4427     DWORD ret;
4428     MSG msg;
4429
4430     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4431     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4432
4433     PostMessageA(hwnd, WM_USER, 0, 0);
4434
4435     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4436     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4437
4438     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4439     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4440
4441     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4442     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4443
4444     PostMessageA(hwnd, WM_USER, 0, 0);
4445
4446     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4447     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4448
4449     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4450     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4451
4452     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4453     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4454     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4455
4456     PostMessageA(hwnd, WM_USER, 0, 0);
4457
4458     /* new incoming message causes it to become signaled again */
4459     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4460     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4461
4462     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4463     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4464     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4465     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4466 }
4467
4468 /* test if we receive the right sequence of messages */
4469 static void test_messages(void)
4470 {
4471     HWND hwnd, hparent, hchild;
4472     HWND hchild2, hbutton;
4473     HMENU hmenu;
4474     MSG msg;
4475     LRESULT res;
4476
4477     flush_sequence();
4478
4479     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4480                            100, 100, 200, 200, 0, 0, 0, NULL);
4481     ok (hwnd != 0, "Failed to create overlapped window\n");
4482     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4483
4484     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4485     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4486     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4487
4488     /* test WM_SETREDRAW on a not visible top level window */
4489     test_WM_SETREDRAW(hwnd);
4490
4491     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4492     flush_events();
4493     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4494     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4495
4496     ok(GetActiveWindow() == hwnd, "window should be active\n");
4497     ok(GetFocus() == hwnd, "window should have input focus\n");
4498     ShowWindow(hwnd, SW_HIDE);
4499     flush_events();
4500     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4501
4502     ShowWindow(hwnd, SW_SHOW);
4503     flush_events();
4504     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4505
4506     ShowWindow(hwnd, SW_HIDE);
4507     flush_events();
4508     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4509
4510     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4511     flush_events();
4512     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4513     flush_sequence();
4514
4515     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4516     {
4517         ShowWindow(hwnd, SW_RESTORE);
4518         flush_events();
4519         ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4520         flush_sequence();
4521     }
4522
4523     ShowWindow(hwnd, SW_MINIMIZE);
4524     flush_events();
4525     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4526     flush_sequence();
4527
4528     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4529     {
4530         ShowWindow(hwnd, SW_RESTORE);
4531         flush_events();
4532         ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4533         flush_sequence();
4534     }
4535
4536     ShowWindow(hwnd, SW_SHOW);
4537     flush_events();
4538     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4539
4540     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4541     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4542     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4543     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4544
4545     /* test WM_SETREDRAW on a visible top level window */
4546     ShowWindow(hwnd, SW_SHOW);
4547     flush_events();
4548     test_WM_SETREDRAW(hwnd);
4549
4550     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4551     test_scroll_messages(hwnd);
4552
4553     /* test resizing and moving */
4554     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4555     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4556     flush_events();
4557     flush_sequence();
4558     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4559     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4560     flush_events();
4561     flush_sequence();
4562     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4563     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4564     flush_events();
4565     flush_sequence();
4566
4567     /* popups don't get WM_GETMINMAXINFO */
4568     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4569     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4570     flush_sequence();
4571     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4572     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4573
4574     DestroyWindow(hwnd);
4575     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4576
4577     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4578                               100, 100, 200, 200, 0, 0, 0, NULL);
4579     ok (hparent != 0, "Failed to create parent window\n");
4580     flush_sequence();
4581
4582     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4583                              0, 0, 10, 10, hparent, 0, 0, NULL);
4584     ok (hchild != 0, "Failed to create child window\n");
4585     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4586     DestroyWindow(hchild);
4587     flush_sequence();
4588
4589     /* visible child window with a caption */
4590     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4591                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4592                              0, 0, 10, 10, hparent, 0, 0, NULL);
4593     ok (hchild != 0, "Failed to create child window\n");
4594     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4595
4596     trace("testing scroll APIs on a visible child window %p\n", hchild);
4597     test_scroll_messages(hchild);
4598
4599     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4600     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4601
4602     DestroyWindow(hchild);
4603     flush_sequence();
4604
4605     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4606                              0, 0, 10, 10, hparent, 0, 0, NULL);
4607     ok (hchild != 0, "Failed to create child window\n");
4608     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4609     
4610     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4611                                100, 100, 50, 50, hparent, 0, 0, NULL);
4612     ok (hchild2 != 0, "Failed to create child2 window\n");
4613     flush_sequence();
4614
4615     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4616                               0, 100, 50, 50, hchild, 0, 0, NULL);
4617     ok (hbutton != 0, "Failed to create button window\n");
4618
4619     /* test WM_SETREDRAW on a not visible child window */
4620     test_WM_SETREDRAW(hchild);
4621
4622     ShowWindow(hchild, SW_SHOW);
4623     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4624
4625     /* check parent messages too */
4626     log_all_parent_messages++;
4627     ShowWindow(hchild, SW_HIDE);
4628     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4629     log_all_parent_messages--;
4630
4631     ShowWindow(hchild, SW_SHOW);
4632     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4633
4634     ShowWindow(hchild, SW_HIDE);
4635     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4636
4637     ShowWindow(hchild, SW_SHOW);
4638     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4639
4640     /* test WM_SETREDRAW on a visible child window */
4641     test_WM_SETREDRAW(hchild);
4642
4643     log_all_parent_messages++;
4644     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4645     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4646     log_all_parent_messages--;
4647
4648     ShowWindow(hchild, SW_HIDE);
4649     flush_sequence();
4650     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4651     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4652
4653     ShowWindow(hchild, SW_HIDE);
4654     flush_sequence();
4655     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4656     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4657
4658     /* DestroyWindow sequence below expects that a child has focus */
4659     SetFocus(hchild);
4660     flush_sequence();
4661
4662     DestroyWindow(hchild);
4663     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4664     DestroyWindow(hchild2);
4665     DestroyWindow(hbutton);
4666
4667     flush_sequence();
4668     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4669                              0, 0, 100, 100, hparent, 0, 0, NULL);
4670     ok (hchild != 0, "Failed to create child popup window\n");
4671     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4672     DestroyWindow(hchild);
4673
4674     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4675     flush_sequence();
4676     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4677                              0, 0, 100, 100, hparent, 0, 0, NULL);
4678     ok (hchild != 0, "Failed to create popup window\n");
4679     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4680     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4681     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4682     flush_sequence();
4683     ShowWindow(hchild, SW_SHOW);
4684     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4685     flush_sequence();
4686     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4687     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4688     flush_sequence();
4689     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4690     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4691     DestroyWindow(hchild);
4692
4693     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4694      * changes nothing in message sequences.
4695      */
4696     flush_sequence();
4697     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4698                              0, 0, 100, 100, hparent, 0, 0, NULL);
4699     ok (hchild != 0, "Failed to create popup window\n");
4700     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4701     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4702     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4703     flush_sequence();
4704     ShowWindow(hchild, SW_SHOW);
4705     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4706     flush_sequence();
4707     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4708     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4709     DestroyWindow(hchild);
4710
4711     flush_sequence();
4712     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4713                            0, 0, 100, 100, hparent, 0, 0, NULL);
4714     ok(hwnd != 0, "Failed to create custom dialog window\n");
4715     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4716
4717     /*
4718     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4719     test_scroll_messages(hwnd);
4720     */
4721
4722     flush_sequence();
4723
4724     test_def_id = 1;
4725     SendMessage(hwnd, WM_NULL, 0, 0);
4726
4727     flush_sequence();
4728     after_end_dialog = 1;
4729     EndDialog( hwnd, 0 );
4730     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4731
4732     DestroyWindow(hwnd);
4733     after_end_dialog = 0;
4734     test_def_id = 0;
4735
4736     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4737                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4738     ok(hwnd != 0, "Failed to create custom dialog window\n");
4739     flush_sequence();
4740     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4741     ShowWindow(hwnd, SW_SHOW);
4742     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4743     DestroyWindow(hwnd);
4744
4745     flush_sequence();
4746     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4747     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4748
4749     DestroyWindow(hparent);
4750     flush_sequence();
4751
4752     /* Message sequence for SetMenu */
4753     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4754     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4755
4756     hmenu = CreateMenu();
4757     ok (hmenu != 0, "Failed to create menu\n");
4758     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4759     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4760                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4761     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4762     ok (SetMenu(hwnd, 0), "SetMenu\n");
4763     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4764     ok (SetMenu(hwnd, 0), "SetMenu\n");
4765     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4766     ShowWindow(hwnd, SW_SHOW);
4767     UpdateWindow( hwnd );
4768     flush_events();
4769     flush_sequence();
4770     ok (SetMenu(hwnd, 0), "SetMenu\n");
4771     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4772     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4773     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4774
4775     UpdateWindow( hwnd );
4776     flush_events();
4777     flush_sequence();
4778     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4779     flush_events();
4780     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4781
4782     DestroyWindow(hwnd);
4783     flush_sequence();
4784
4785     /* Message sequence for EnableWindow */
4786     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4787                               100, 100, 200, 200, 0, 0, 0, NULL);
4788     ok (hparent != 0, "Failed to create parent window\n");
4789     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4790                              0, 0, 10, 10, hparent, 0, 0, NULL);
4791     ok (hchild != 0, "Failed to create child window\n");
4792
4793     SetFocus(hchild);
4794     flush_events();
4795     flush_sequence();
4796
4797     EnableWindow(hparent, FALSE);
4798     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4799
4800     EnableWindow(hparent, TRUE);
4801     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4802
4803     flush_events();
4804     flush_sequence();
4805
4806     test_MsgWaitForMultipleObjects(hparent);
4807
4808     /* the following test causes an exception in user.exe under win9x */
4809     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4810     {
4811         DestroyWindow(hparent);
4812         flush_sequence();
4813         return;
4814     }
4815     PostMessageW( hparent, WM_USER+1, 0, 0 );
4816     /* PeekMessage(NULL) fails, but still removes the message */
4817     SetLastError(0xdeadbeef);
4818     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4819     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4820         GetLastError() == 0xdeadbeef, /* NT4 */
4821         "last error is %d\n", GetLastError() );
4822     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4823     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4824
4825     DestroyWindow(hchild);
4826     DestroyWindow(hparent);
4827     flush_sequence();
4828
4829     /* Message sequences for WM_SETICON */
4830     trace("testing WM_SETICON\n");
4831     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4832                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4833                            NULL, NULL, 0);
4834     ShowWindow(hwnd, SW_SHOW);
4835     UpdateWindow(hwnd);
4836     flush_events();
4837     flush_sequence();
4838     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4839     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4840
4841     ShowWindow(hwnd, SW_HIDE);
4842     flush_events();
4843     flush_sequence();
4844     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4845     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4846     DestroyWindow(hwnd);
4847     flush_sequence();
4848
4849     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4850                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4851                            NULL, NULL, 0);
4852     ShowWindow(hwnd, SW_SHOW);
4853     UpdateWindow(hwnd);
4854     flush_events();
4855     flush_sequence();
4856     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4857     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4858
4859     ShowWindow(hwnd, SW_HIDE);
4860     flush_events();
4861     flush_sequence();
4862     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4863     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4864
4865     flush_sequence();
4866     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4867     if (!res)
4868     {
4869         todo_wine win_skip( "Message 0x3b not supported\n" );
4870         goto done;
4871     }
4872     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4873     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4874     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4875     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4876     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4877     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4878     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4879     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4880
4881     flush_sequence();
4882     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4883     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4884     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4885     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4886     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4887     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4888
4889     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4890     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4891     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4892
4893     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4894     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4895     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4896
4897 done:
4898     DestroyWindow(hwnd);
4899     flush_sequence();
4900 }
4901
4902 static void test_setwindowpos(void)
4903 {
4904     HWND hwnd;
4905     RECT rc;
4906     LRESULT res;
4907     const INT winX = 100;
4908     const INT winY = 100;
4909     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4910
4911     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4912                            0, 0, winX, winY, 0,
4913                            NULL, NULL, 0);
4914
4915     GetWindowRect(hwnd, &rc);
4916     expect(sysX, rc.right);
4917     expect(winY, rc.bottom);
4918
4919     flush_events();
4920     flush_sequence();
4921     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4922     ok_sequence(WmZOrder, "Z-Order", TRUE);
4923     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4924
4925     GetWindowRect(hwnd, &rc);
4926     expect(sysX, rc.right);
4927     expect(winY, rc.bottom);
4928     DestroyWindow(hwnd);
4929 }
4930
4931 static void invisible_parent_tests(void)
4932 {
4933     HWND hparent, hchild;
4934
4935     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4936                               100, 100, 200, 200, 0, 0, 0, NULL);
4937     ok (hparent != 0, "Failed to create parent window\n");
4938     flush_sequence();
4939
4940     /* test showing child with hidden parent */
4941
4942     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4943                              0, 0, 10, 10, hparent, 0, 0, NULL);
4944     ok (hchild != 0, "Failed to create child window\n");
4945     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4946
4947     ShowWindow( hchild, SW_MINIMIZE );
4948     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4949     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4950     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4951
4952     /* repeat */
4953     flush_events();
4954     flush_sequence();
4955     ShowWindow( hchild, SW_MINIMIZE );
4956     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4957
4958     DestroyWindow(hchild);
4959     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4960                              0, 0, 10, 10, hparent, 0, 0, NULL);
4961     flush_sequence();
4962
4963     ShowWindow( hchild, SW_MAXIMIZE );
4964     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4965     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4966     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4967
4968     /* repeat */
4969     flush_events();
4970     flush_sequence();
4971     ShowWindow( hchild, SW_MAXIMIZE );
4972     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4973
4974     DestroyWindow(hchild);
4975     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4976                              0, 0, 10, 10, hparent, 0, 0, NULL);
4977     flush_sequence();
4978
4979     ShowWindow( hchild, SW_RESTORE );
4980     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4981     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4982     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4983
4984     DestroyWindow(hchild);
4985     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4986                              0, 0, 10, 10, hparent, 0, 0, NULL);
4987     flush_sequence();
4988
4989     ShowWindow( hchild, SW_SHOWMINIMIZED );
4990     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4991     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4992     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4993
4994     /* repeat */
4995     flush_events();
4996     flush_sequence();
4997     ShowWindow( hchild, SW_SHOWMINIMIZED );
4998     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4999
5000     DestroyWindow(hchild);
5001     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5002                              0, 0, 10, 10, hparent, 0, 0, NULL);
5003     flush_sequence();
5004
5005     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5006     ShowWindow( hchild, SW_SHOWMAXIMIZED );
5007     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5008     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5009     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5010
5011     DestroyWindow(hchild);
5012     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5013                              0, 0, 10, 10, hparent, 0, 0, NULL);
5014     flush_sequence();
5015
5016     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5017     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5018     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5019     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5020
5021     /* repeat */
5022     flush_events();
5023     flush_sequence();
5024     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5025     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5026
5027     DestroyWindow(hchild);
5028     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5029                              0, 0, 10, 10, hparent, 0, 0, NULL);
5030     flush_sequence();
5031
5032     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5033     ShowWindow( hchild, SW_FORCEMINIMIZE );
5034     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5035 todo_wine {
5036     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5037 }
5038     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5039
5040     DestroyWindow(hchild);
5041     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5042                              0, 0, 10, 10, hparent, 0, 0, NULL);
5043     flush_sequence();
5044
5045     ShowWindow( hchild, SW_SHOWNA );
5046     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5047     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5048     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5049
5050     /* repeat */
5051     flush_events();
5052     flush_sequence();
5053     ShowWindow( hchild, SW_SHOWNA );
5054     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5055
5056     DestroyWindow(hchild);
5057     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5058                              0, 0, 10, 10, hparent, 0, 0, NULL);
5059     flush_sequence();
5060
5061     ShowWindow( hchild, SW_SHOW );
5062     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5063     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5064     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5065
5066     /* repeat */
5067     flush_events();
5068     flush_sequence();
5069     ShowWindow( hchild, SW_SHOW );
5070     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5071
5072     ShowWindow( hchild, SW_HIDE );
5073     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5074     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5075     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5076
5077     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5078     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5079     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5080     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5081
5082     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5083     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5084     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5085     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5086
5087     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5088     flush_sequence();
5089     DestroyWindow(hchild);
5090     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5091
5092     DestroyWindow(hparent);
5093     flush_sequence();
5094 }
5095
5096 /****************** button message test *************************/
5097 #define ID_BUTTON 0x000e
5098
5099 static const struct message WmSetFocusButtonSeq[] =
5100 {
5101     { HCBT_SETFOCUS, hook },
5102     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5103     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5104     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5105     { WM_SETFOCUS, sent|wparam, 0 },
5106     { WM_CTLCOLORBTN, sent|parent },
5107     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5108     { WM_APP, sent|wparam|lparam, 0, 0 },
5109     { 0 }
5110 };
5111 static const struct message WmKillFocusButtonSeq[] =
5112 {
5113     { HCBT_SETFOCUS, hook },
5114     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5115     { WM_KILLFOCUS, sent|wparam, 0 },
5116     { WM_CTLCOLORBTN, sent|parent },
5117     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5118     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5119     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5120     { WM_APP, sent|wparam|lparam, 0, 0 },
5121     { WM_PAINT, sent },
5122     { WM_CTLCOLORBTN, sent|parent },
5123     { 0 }
5124 };
5125 static const struct message WmSetFocusStaticSeq[] =
5126 {
5127     { HCBT_SETFOCUS, hook },
5128     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5129     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5130     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5131     { WM_SETFOCUS, sent|wparam, 0 },
5132     { WM_CTLCOLORSTATIC, sent|parent },
5133     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5134     { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5135     { WM_APP, sent|wparam|lparam, 0, 0 },
5136     { 0 }
5137 };
5138 static const struct message WmKillFocusStaticSeq[] =
5139 {
5140     { HCBT_SETFOCUS, hook },
5141     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5142     { WM_KILLFOCUS, sent|wparam, 0 },
5143     { WM_CTLCOLORSTATIC, sent|parent },
5144     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5145     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5146     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5147     { WM_APP, sent|wparam|lparam, 0, 0 },
5148     { WM_PAINT, sent },
5149     { WM_CTLCOLORSTATIC, sent|parent },
5150     { 0 }
5151 };
5152 static const struct message WmSetFocusOwnerdrawSeq[] =
5153 {
5154     { HCBT_SETFOCUS, hook },
5155     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5156     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5157     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5158     { WM_SETFOCUS, sent|wparam, 0 },
5159     { WM_CTLCOLORBTN, sent|parent },
5160     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5161     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5162     { WM_APP, sent|wparam|lparam, 0, 0 },
5163     { 0 }
5164 };
5165 static const struct message WmKillFocusOwnerdrawSeq[] =
5166 {
5167     { HCBT_SETFOCUS, hook },
5168     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5169     { WM_KILLFOCUS, sent|wparam, 0 },
5170     { WM_CTLCOLORBTN, sent|parent },
5171     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5172     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5173     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5174     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5175     { WM_APP, sent|wparam|lparam, 0, 0 },
5176     { WM_PAINT, sent },
5177     { WM_CTLCOLORBTN, sent|parent },
5178     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5179     { 0 }
5180 };
5181 static const struct message WmLButtonDownSeq[] =
5182 {
5183     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5184     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5185     { HCBT_SETFOCUS, hook },
5186     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5187     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5188     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5189     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5190     { WM_CTLCOLORBTN, sent|defwinproc },
5191     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5192     { WM_CTLCOLORBTN, sent|defwinproc },
5193     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5194     { 0 }
5195 };
5196 static const struct message WmLButtonUpSeq[] =
5197 {
5198     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5199     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5200     { WM_CTLCOLORBTN, sent|defwinproc },
5201     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5202     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5203     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5204     { 0 }
5205 };
5206 static const struct message WmSetFontButtonSeq[] =
5207 {
5208     { WM_SETFONT, sent },
5209     { WM_PAINT, sent },
5210     { WM_ERASEBKGND, sent|defwinproc|optional },
5211     { WM_CTLCOLORBTN, sent|defwinproc },
5212     { 0 }
5213 };
5214 static const struct message WmSetStyleButtonSeq[] =
5215 {
5216     { BM_SETSTYLE, sent },
5217     { WM_APP, sent|wparam|lparam, 0, 0 },
5218     { WM_PAINT, sent },
5219     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5220     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5221     { WM_CTLCOLORBTN, sent|parent },
5222     { 0 }
5223 };
5224 static const struct message WmSetStyleStaticSeq[] =
5225 {
5226     { BM_SETSTYLE, sent },
5227     { WM_APP, sent|wparam|lparam, 0, 0 },
5228     { WM_PAINT, sent },
5229     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5230     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5231     { WM_CTLCOLORSTATIC, sent|parent },
5232     { 0 }
5233 };
5234 static const struct message WmSetStyleUserSeq[] =
5235 {
5236     { BM_SETSTYLE, sent },
5237     { WM_APP, sent|wparam|lparam, 0, 0 },
5238     { WM_PAINT, sent },
5239     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5240     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5241     { WM_CTLCOLORBTN, sent|parent },
5242     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5243     { 0 }
5244 };
5245 static const struct message WmSetStyleOwnerdrawSeq[] =
5246 {
5247     { BM_SETSTYLE, sent },
5248     { WM_APP, sent|wparam|lparam, 0, 0 },
5249     { WM_PAINT, sent },
5250     { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5251     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5252     { WM_CTLCOLORBTN, sent|parent },
5253     { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5254     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5255     { 0 }
5256 };
5257
5258 static WNDPROC old_button_proc;
5259
5260 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5261 {
5262     static LONG defwndproc_counter = 0;
5263     LRESULT ret;
5264     struct recvd_message msg;
5265
5266     if (ignore_message( message )) return 0;
5267
5268     switch (message)
5269     {
5270     case WM_SYNCPAINT:
5271         break;
5272     case BM_SETSTATE:
5273         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5274         /* fall through */
5275     default:
5276         msg.hwnd = hwnd;
5277         msg.message = message;
5278         msg.flags = sent|wparam|lparam;
5279         if (defwndproc_counter) msg.flags |= defwinproc;
5280         msg.wParam = wParam;
5281         msg.lParam = lParam;
5282         msg.descr = "button";
5283         add_message(&msg);
5284     }
5285
5286     defwndproc_counter++;
5287     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5288     defwndproc_counter--;
5289
5290     return ret;
5291 }
5292
5293 static void subclass_button(void)
5294 {
5295     WNDCLASSA cls;
5296
5297     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5298
5299     old_button_proc = cls.lpfnWndProc;
5300
5301     cls.hInstance = GetModuleHandle(0);
5302     cls.lpfnWndProc = button_hook_proc;
5303     cls.lpszClassName = "my_button_class";
5304     UnregisterClass(cls.lpszClassName, cls.hInstance);
5305     if (!RegisterClassA(&cls)) assert(0);
5306 }
5307
5308 static void test_button_messages(void)
5309 {
5310     static const struct
5311     {
5312         DWORD style;
5313         DWORD dlg_code;
5314         const struct message *setfocus;
5315         const struct message *killfocus;
5316         const struct message *setstyle;
5317     } button[] = {
5318         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5319           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5320         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5321           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5322         { BS_CHECKBOX, DLGC_BUTTON,
5323           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5324         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5325           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5326         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5327           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5328         { BS_3STATE, DLGC_BUTTON,
5329           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5330         { BS_AUTO3STATE, DLGC_BUTTON,
5331           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5332         { BS_GROUPBOX, DLGC_STATIC,
5333           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5334         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5335           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq },
5336         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5337           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5338         { BS_OWNERDRAW, DLGC_BUTTON,
5339           WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq }
5340     };
5341     unsigned int i;
5342     HWND hwnd, parent;
5343     DWORD dlg_code;
5344     HFONT zfont;
5345
5346     /* selection with VK_SPACE should capture button window */
5347     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5348                            0, 0, 50, 14, 0, 0, 0, NULL);
5349     ok(hwnd != 0, "Failed to create button window\n");
5350     ReleaseCapture();
5351     SetFocus(hwnd);
5352     SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5353     ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5354     SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5355     DestroyWindow(hwnd);
5356
5357     subclass_button();
5358
5359     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5360                              100, 100, 200, 200, 0, 0, 0, NULL);
5361     ok(parent != 0, "Failed to create parent window\n");
5362
5363     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5364     {
5365         MSG msg;
5366         DWORD style;
5367
5368         trace("button style %08x\n", button[i].style);
5369
5370         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5371                                0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5372         ok(hwnd != 0, "Failed to create button window\n");
5373
5374         style = GetWindowLongA(hwnd, GWL_STYLE);
5375         style &= ~(WS_CHILD | BS_NOTIFY);
5376         /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5377         if (button[i].style == BS_USERBUTTON)
5378             ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5379         else
5380             ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5381
5382         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5383         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5384
5385         ShowWindow(hwnd, SW_SHOW);
5386         UpdateWindow(hwnd);
5387         SetFocus(0);
5388         flush_events();
5389         SetFocus(0);
5390         flush_sequence();
5391
5392         log_all_parent_messages++;
5393
5394         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5395         SetFocus(hwnd);
5396         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5397         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5398         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5399
5400         SetFocus(0);
5401         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5402         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5403         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5404
5405         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5406
5407         SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5408         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5409         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5410         ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5411
5412         style = GetWindowLongA(hwnd, GWL_STYLE);
5413         style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5414         /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5415         ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5416
5417         log_all_parent_messages--;
5418
5419         DestroyWindow(hwnd);
5420     }
5421
5422     DestroyWindow(parent);
5423
5424     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5425                            0, 0, 50, 14, 0, 0, 0, NULL);
5426     ok(hwnd != 0, "Failed to create button window\n");
5427
5428     SetForegroundWindow(hwnd);
5429     flush_events();
5430
5431     SetActiveWindow(hwnd);
5432     SetFocus(0);
5433     flush_sequence();
5434
5435     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5436     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5437
5438     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5439     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5440
5441     flush_sequence();
5442     zfont = GetStockObject(SYSTEM_FONT);
5443     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5444     UpdateWindow(hwnd);
5445     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5446
5447     DestroyWindow(hwnd);
5448 }
5449
5450 /****************** static message test *************************/
5451 static const struct message WmSetFontStaticSeq[] =
5452 {
5453     { WM_SETFONT, sent },
5454     { WM_PAINT, sent|defwinproc|optional },
5455     { WM_ERASEBKGND, sent|defwinproc|optional },
5456     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5457     { 0 }
5458 };
5459
5460 static WNDPROC old_static_proc;
5461
5462 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5463 {
5464     static LONG defwndproc_counter = 0;
5465     LRESULT ret;
5466     struct recvd_message msg;
5467
5468     if (ignore_message( message )) return 0;
5469
5470     msg.hwnd = hwnd;
5471     msg.message = message;
5472     msg.flags = sent|wparam|lparam;
5473     if (defwndproc_counter) msg.flags |= defwinproc;
5474     msg.wParam = wParam;
5475     msg.lParam = lParam;
5476     msg.descr = "static";
5477     add_message(&msg);
5478
5479     defwndproc_counter++;
5480     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5481     defwndproc_counter--;
5482
5483     return ret;
5484 }
5485
5486 static void subclass_static(void)
5487 {
5488     WNDCLASSA cls;
5489
5490     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5491
5492     old_static_proc = cls.lpfnWndProc;
5493
5494     cls.hInstance = GetModuleHandle(0);
5495     cls.lpfnWndProc = static_hook_proc;
5496     cls.lpszClassName = "my_static_class";
5497     UnregisterClass(cls.lpszClassName, cls.hInstance);
5498     if (!RegisterClassA(&cls)) assert(0);
5499 }
5500
5501 static void test_static_messages(void)
5502 {
5503     /* FIXME: make as comprehensive as the button message test */
5504     static const struct
5505     {
5506         DWORD style;
5507         DWORD dlg_code;
5508         const struct message *setfont;
5509     } static_ctrl[] = {
5510         { SS_LEFT, DLGC_STATIC,
5511           WmSetFontStaticSeq }
5512     };
5513     unsigned int i;
5514     HWND hwnd;
5515     DWORD dlg_code;
5516
5517     subclass_static();
5518
5519     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5520     {
5521         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5522                                0, 0, 50, 14, 0, 0, 0, NULL);
5523         ok(hwnd != 0, "Failed to create static window\n");
5524
5525         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5526         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5527
5528         ShowWindow(hwnd, SW_SHOW);
5529         UpdateWindow(hwnd);
5530         SetFocus(0);
5531         flush_sequence();
5532
5533         trace("static style %08x\n", static_ctrl[i].style);
5534         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5535         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5536
5537         DestroyWindow(hwnd);
5538     }
5539 }
5540
5541 /****************** ComboBox message test *************************/
5542 #define ID_COMBOBOX 0x000f
5543
5544 static const struct message WmKeyDownComboSeq[] =
5545 {
5546     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5547     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5548     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5549     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5550     { WM_CTLCOLOREDIT, sent|parent },
5551     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5552     { 0 }
5553 };
5554
5555 static WNDPROC old_combobox_proc;
5556
5557 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5558 {
5559     static LONG defwndproc_counter = 0;
5560     LRESULT ret;
5561     struct recvd_message msg;
5562
5563     /* do not log painting messages */
5564     if (message != WM_PAINT &&
5565         message != WM_NCPAINT &&
5566         message != WM_SYNCPAINT &&
5567         message != WM_ERASEBKGND &&
5568         message != WM_NCHITTEST &&
5569         message != WM_GETTEXT &&
5570         !ignore_message( message ))
5571     {
5572         msg.hwnd = hwnd;
5573         msg.message = message;
5574         msg.flags = sent|wparam|lparam;
5575         if (defwndproc_counter) msg.flags |= defwinproc;
5576         msg.wParam = wParam;
5577         msg.lParam = lParam;
5578         msg.descr = "combo";
5579         add_message(&msg);
5580     }
5581
5582     defwndproc_counter++;
5583     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5584     defwndproc_counter--;
5585
5586     return ret;
5587 }
5588
5589 static void subclass_combobox(void)
5590 {
5591     WNDCLASSA cls;
5592
5593     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5594
5595     old_combobox_proc = cls.lpfnWndProc;
5596
5597     cls.hInstance = GetModuleHandle(0);
5598     cls.lpfnWndProc = combobox_hook_proc;
5599     cls.lpszClassName = "my_combobox_class";
5600     UnregisterClass(cls.lpszClassName, cls.hInstance);
5601     if (!RegisterClassA(&cls)) assert(0);
5602 }
5603
5604 static void test_combobox_messages(void)
5605 {
5606     HWND parent, combo;
5607     LRESULT ret;
5608
5609     subclass_combobox();
5610
5611     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5612                              100, 100, 200, 200, 0, 0, 0, NULL);
5613     ok(parent != 0, "Failed to create parent window\n");
5614     flush_sequence();
5615
5616     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5617                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5618     ok(combo != 0, "Failed to create combobox window\n");
5619
5620     UpdateWindow(combo);
5621
5622     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5623     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5624
5625     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5626     ok(ret == 0, "expected 0, got %ld\n", ret);
5627     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5628     ok(ret == 1, "expected 1, got %ld\n", ret);
5629     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5630     ok(ret == 2, "expected 2, got %ld\n", ret);
5631
5632     SendMessage(combo, CB_SETCURSEL, 0, 0);
5633     SetFocus(combo);
5634     flush_sequence();
5635
5636     log_all_parent_messages++;
5637     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5638     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5639     log_all_parent_messages--;
5640     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5641
5642     DestroyWindow(combo);
5643     DestroyWindow(parent);
5644 }
5645
5646 /****************** WM_IME_KEYDOWN message test *******************/
5647
5648 static const struct message WmImeKeydownMsgSeq_0[] =
5649 {
5650     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5651     { WM_CHAR, wparam, 'A' },
5652     { 0 }
5653 };
5654
5655 static const struct message WmImeKeydownMsgSeq_1[] =
5656 {
5657     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5658     { WM_CHAR,    optional|wparam, VK_RETURN },
5659     { 0 }
5660 };
5661
5662 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5663 {
5664     struct recvd_message msg;
5665
5666     msg.hwnd = hwnd;
5667     msg.message = message;
5668     msg.flags = wparam|lparam;
5669     msg.wParam = wParam;
5670     msg.lParam = lParam;
5671     msg.descr = "wmime_keydown";
5672     add_message(&msg);
5673
5674     return DefWindowProcA(hwnd, message, wParam, lParam);
5675 }
5676
5677 static void register_wmime_keydown_class(void)
5678 {
5679     WNDCLASSA cls;
5680
5681     ZeroMemory(&cls, sizeof(WNDCLASSA));
5682     cls.lpfnWndProc = wmime_keydown_procA;
5683     cls.hInstance = GetModuleHandleA(0);
5684     cls.lpszClassName = "wmime_keydown_class";
5685     if (!RegisterClassA(&cls)) assert(0);
5686 }
5687
5688 static void test_wmime_keydown_message(void)
5689 {
5690     HWND hwnd;
5691     MSG msg;
5692
5693     trace("Message sequences by WM_IME_KEYDOWN\n");
5694
5695     register_wmime_keydown_class();
5696     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5697                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5698                            NULL, NULL, 0);
5699     flush_events();
5700     flush_sequence();
5701
5702     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5703     SendMessage(hwnd, WM_CHAR, 'A', 1);
5704     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5705
5706     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5707     {
5708         TranslateMessage(&msg);
5709         DispatchMessage(&msg);
5710     }
5711     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5712
5713     DestroyWindow(hwnd);
5714 }
5715
5716 /************* painting message test ********************/
5717
5718 void dump_region(HRGN hrgn)
5719 {
5720     DWORD i, size;
5721     RGNDATA *data = NULL;
5722     RECT *rect;
5723
5724     if (!hrgn)
5725     {
5726         printf( "null region\n" );
5727         return;
5728     }
5729     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5730     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5731     GetRegionData( hrgn, size, data );
5732     printf("%d rects:", data->rdh.nCount );
5733     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5734         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5735     printf("\n");
5736     HeapFree( GetProcessHeap(), 0, data );
5737 }
5738
5739 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5740 {
5741     INT ret;
5742     RECT r1, r2;
5743     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5744     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5745
5746     ret = GetUpdateRgn( hwnd, update, FALSE );
5747     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5748     if (ret == NULLREGION)
5749     {
5750         ok( !hrgn, "Update region shouldn't be empty\n" );
5751     }
5752     else
5753     {
5754         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5755         {
5756             ok( 0, "Regions are different\n" );
5757             if (winetest_debug > 0)
5758             {
5759                 printf( "Update region: " );
5760                 dump_region( update );
5761                 printf( "Wanted region: " );
5762                 dump_region( hrgn );
5763             }
5764         }
5765     }
5766     GetRgnBox( update, &r1 );
5767     GetUpdateRect( hwnd, &r2, FALSE );
5768     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5769         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5770         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5771
5772     DeleteObject( tmp );
5773     DeleteObject( update );
5774 }
5775
5776 static const struct message WmInvalidateRgn[] = {
5777     { WM_NCPAINT, sent },
5778     { WM_GETTEXT, sent|defwinproc|optional },
5779     { 0 }
5780 };
5781
5782 static const struct message WmGetUpdateRect[] = {
5783     { WM_NCPAINT, sent },
5784     { WM_GETTEXT, sent|defwinproc|optional },
5785     { WM_PAINT, sent },
5786     { 0 }
5787 };
5788
5789 static const struct message WmInvalidateFull[] = {
5790     { WM_NCPAINT, sent|wparam, 1 },
5791     { WM_GETTEXT, sent|defwinproc|optional },
5792     { 0 }
5793 };
5794
5795 static const struct message WmInvalidateErase[] = {
5796     { WM_NCPAINT, sent|wparam, 1 },
5797     { WM_GETTEXT, sent|defwinproc|optional },
5798     { WM_ERASEBKGND, sent },
5799     { 0 }
5800 };
5801
5802 static const struct message WmInvalidatePaint[] = {
5803     { WM_PAINT, sent },
5804     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5805     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5806     { 0 }
5807 };
5808
5809 static const struct message WmInvalidateErasePaint[] = {
5810     { WM_PAINT, sent },
5811     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5812     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5813     { WM_ERASEBKGND, sent|beginpaint|optional },
5814     { 0 }
5815 };
5816
5817 static const struct message WmInvalidateErasePaint2[] = {
5818     { WM_PAINT, sent },
5819     { WM_NCPAINT, sent|beginpaint },
5820     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5821     { WM_ERASEBKGND, sent|beginpaint|optional },
5822     { 0 }
5823 };
5824
5825 static const struct message WmErase[] = {
5826     { WM_ERASEBKGND, sent },
5827     { 0 }
5828 };
5829
5830 static const struct message WmPaint[] = {
5831     { WM_PAINT, sent },
5832     { 0 }
5833 };
5834
5835 static const struct message WmParentOnlyPaint[] = {
5836     { WM_PAINT, sent|parent },
5837     { 0 }
5838 };
5839
5840 static const struct message WmInvalidateParent[] = {
5841     { WM_NCPAINT, sent|parent },
5842     { WM_GETTEXT, sent|defwinproc|parent|optional },
5843     { WM_ERASEBKGND, sent|parent },
5844     { 0 }
5845 };
5846
5847 static const struct message WmInvalidateParentChild[] = {
5848     { WM_NCPAINT, sent|parent },
5849     { WM_GETTEXT, sent|defwinproc|parent|optional },
5850     { WM_ERASEBKGND, sent|parent },
5851     { WM_NCPAINT, sent },
5852     { WM_GETTEXT, sent|defwinproc|optional },
5853     { WM_ERASEBKGND, sent },
5854     { 0 }
5855 };
5856
5857 static const struct message WmInvalidateParentChild2[] = {
5858     { WM_ERASEBKGND, sent|parent },
5859     { WM_NCPAINT, sent },
5860     { WM_GETTEXT, sent|defwinproc|optional },
5861     { WM_ERASEBKGND, sent },
5862     { 0 }
5863 };
5864
5865 static const struct message WmParentPaint[] = {
5866     { WM_PAINT, sent|parent },
5867     { WM_PAINT, sent },
5868     { 0 }
5869 };
5870
5871 static const struct message WmParentPaintNc[] = {
5872     { WM_PAINT, sent|parent },
5873     { WM_PAINT, sent },
5874     { WM_NCPAINT, sent|beginpaint },
5875     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5876     { WM_ERASEBKGND, sent|beginpaint|optional },
5877     { 0 }
5878 };
5879
5880 static const struct message WmChildPaintNc[] = {
5881     { WM_PAINT, sent },
5882     { WM_NCPAINT, sent|beginpaint },
5883     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5884     { WM_ERASEBKGND, sent|beginpaint|optional },
5885     { 0 }
5886 };
5887
5888 static const struct message WmParentErasePaint[] = {
5889     { WM_PAINT, sent|parent },
5890     { WM_NCPAINT, sent|parent|beginpaint },
5891     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5892     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5893     { WM_PAINT, sent },
5894     { WM_NCPAINT, sent|beginpaint },
5895     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5896     { WM_ERASEBKGND, sent|beginpaint|optional },
5897     { 0 }
5898 };
5899
5900 static const struct message WmParentOnlyNcPaint[] = {
5901     { WM_PAINT, sent|parent },
5902     { WM_NCPAINT, sent|parent|beginpaint },
5903     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5904     { 0 }
5905 };
5906
5907 static const struct message WmSetParentStyle[] = {
5908     { WM_STYLECHANGING, sent|parent },
5909     { WM_STYLECHANGED, sent|parent },
5910     { 0 }
5911 };
5912
5913 static void test_paint_messages(void)
5914 {
5915     BOOL ret;
5916     RECT rect;
5917     POINT pt;
5918     MSG msg;
5919     HWND hparent, hchild;
5920     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5921     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5922     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5923                                 100, 100, 200, 200, 0, 0, 0, NULL);
5924     ok (hwnd != 0, "Failed to create overlapped window\n");
5925
5926     ShowWindow( hwnd, SW_SHOW );
5927     UpdateWindow( hwnd );
5928     flush_events();
5929     flush_sequence();
5930
5931     check_update_rgn( hwnd, 0 );
5932     SetRectRgn( hrgn, 10, 10, 20, 20 );
5933     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5934     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5935     check_update_rgn( hwnd, hrgn );
5936     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5937     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5938     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5939     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5940     check_update_rgn( hwnd, hrgn );
5941     /* validate everything */
5942     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5943     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5944     check_update_rgn( hwnd, 0 );
5945
5946     /* test empty region */
5947     SetRectRgn( hrgn, 10, 10, 10, 15 );
5948     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5949     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5950     check_update_rgn( hwnd, 0 );
5951     /* test empty rect */
5952     SetRect( &rect, 10, 10, 10, 15 );
5953     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5954     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5955     check_update_rgn( hwnd, 0 );
5956
5957     /* flush pending messages */
5958     flush_events();
5959     flush_sequence();
5960
5961     GetClientRect( hwnd, &rect );
5962     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5963     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5964      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5965      */
5966     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5967     SetRectEmpty( &rect );
5968     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5969     check_update_rgn( hwnd, hrgn );
5970     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5971     flush_events();
5972     ok_sequence( WmPaint, "Paint", FALSE );
5973     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5974     check_update_rgn( hwnd, 0 );
5975
5976     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5977      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5978      */
5979     trace("testing ValidateRect(0, NULL)\n");
5980     SetRectEmpty( &rect );
5981     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5982     {
5983         check_update_rgn( hwnd, hrgn );
5984         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5985         flush_events();
5986         ok_sequence( WmPaint, "Paint", FALSE );
5987         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5988         check_update_rgn( hwnd, 0 );
5989     }
5990
5991     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5992     SetLastError(0xdeadbeef);
5993     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5994     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5995        "wrong error code %d\n", GetLastError());
5996     check_update_rgn( hwnd, 0 );
5997     flush_events();
5998     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5999
6000     trace("testing ValidateRgn(0, NULL)\n");
6001     SetLastError(0xdeadbeef);
6002     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6003     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6004        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6005        "wrong error code %d\n", GetLastError());
6006     check_update_rgn( hwnd, 0 );
6007     flush_events();
6008     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6009
6010     /* now with frame */
6011     SetRectRgn( hrgn, -5, -5, 20, 20 );
6012
6013     /* flush pending messages */
6014     flush_events();
6015     flush_sequence();
6016     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6017     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6018
6019     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
6020     check_update_rgn( hwnd, hrgn );
6021
6022     flush_sequence();
6023     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6024     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6025
6026     flush_sequence();
6027     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6028     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6029
6030     GetClientRect( hwnd, &rect );
6031     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6032     check_update_rgn( hwnd, hrgn );
6033
6034     flush_sequence();
6035     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6036     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6037
6038     flush_sequence();
6039     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6040     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6041     check_update_rgn( hwnd, 0 );
6042
6043     flush_sequence();
6044     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6045     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6046     check_update_rgn( hwnd, 0 );
6047
6048     flush_sequence();
6049     SetRectRgn( hrgn, 0, 0, 100, 100 );
6050     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6051     SetRectRgn( hrgn, 0, 0, 50, 100 );
6052     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6053     SetRectRgn( hrgn, 50, 0, 100, 100 );
6054     check_update_rgn( hwnd, hrgn );
6055     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6056     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
6057     check_update_rgn( hwnd, 0 );
6058
6059     flush_sequence();
6060     SetRectRgn( hrgn, 0, 0, 100, 100 );
6061     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6062     SetRectRgn( hrgn, 0, 0, 100, 50 );
6063     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6064     ok_sequence( WmErase, "Erase", FALSE );
6065     SetRectRgn( hrgn, 0, 50, 100, 100 );
6066     check_update_rgn( hwnd, hrgn );
6067
6068     flush_sequence();
6069     SetRectRgn( hrgn, 0, 0, 100, 100 );
6070     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6071     SetRectRgn( hrgn, 0, 0, 50, 50 );
6072     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6073     ok_sequence( WmPaint, "Paint", FALSE );
6074
6075     flush_sequence();
6076     SetRectRgn( hrgn, -4, -4, -2, -2 );
6077     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6078     SetRectRgn( hrgn, -200, -200, -198, -198 );
6079     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6080     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6081
6082     flush_sequence();
6083     SetRectRgn( hrgn, -4, -4, -2, -2 );
6084     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6085     SetRectRgn( hrgn, -4, -4, -3, -3 );
6086     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6087     SetRectRgn( hrgn, 0, 0, 1, 1 );
6088     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6089     ok_sequence( WmPaint, "Paint", FALSE );
6090
6091     flush_sequence();
6092     SetRectRgn( hrgn, -4, -4, -1, -1 );
6093     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6094     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6095     /* make sure no WM_PAINT was generated */
6096     flush_events();
6097     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6098
6099     flush_sequence();
6100     SetRectRgn( hrgn, -4, -4, -1, -1 );
6101     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6102     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6103     {
6104         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6105         {
6106             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6107             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6108             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6109             ret = GetUpdateRect( hwnd, &rect, FALSE );
6110             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6111             /* this will send WM_NCPAINT and validate the non client area */
6112             ret = GetUpdateRect( hwnd, &rect, TRUE );
6113             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6114         }
6115         DispatchMessage( &msg );
6116     }
6117     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6118
6119     DestroyWindow( hwnd );
6120
6121     /* now test with a child window */
6122
6123     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6124                               100, 100, 200, 200, 0, 0, 0, NULL);
6125     ok (hparent != 0, "Failed to create parent window\n");
6126
6127     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6128                            10, 10, 100, 100, hparent, 0, 0, NULL);
6129     ok (hchild != 0, "Failed to create child window\n");
6130
6131     ShowWindow( hparent, SW_SHOW );
6132     UpdateWindow( hparent );
6133     UpdateWindow( hchild );
6134     flush_events();
6135     flush_sequence();
6136     log_all_parent_messages++;
6137
6138     SetRect( &rect, 0, 0, 50, 50 );
6139     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6140     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6141     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6142
6143     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6144     pt.x = pt.y = 0;
6145     MapWindowPoints( hchild, hparent, &pt, 1 );
6146     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6147     check_update_rgn( hchild, hrgn );
6148     SetRectRgn( hrgn, 0, 0, 50, 50 );
6149     check_update_rgn( hparent, hrgn );
6150     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6151     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6152     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6153     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6154
6155     flush_events();
6156     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6157
6158     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6159     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6160     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6161     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6162     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6163
6164     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6165     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6166     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6167
6168     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6169     flush_sequence();
6170     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6171     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6172     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6173
6174     /* flush all paint messages */
6175     flush_events();
6176     flush_sequence();
6177
6178     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6179     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6180     SetRectRgn( hrgn, 0, 0, 50, 50 );
6181     check_update_rgn( hparent, hrgn );
6182     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6183     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6184     SetRectRgn( hrgn, 0, 0, 50, 50 );
6185     check_update_rgn( hparent, hrgn );
6186
6187     /* flush all paint messages */
6188     flush_events();
6189     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6190     flush_sequence();
6191
6192     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6193     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6194     SetRectRgn( hrgn, 0, 0, 50, 50 );
6195     check_update_rgn( hparent, hrgn );
6196     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6197     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6198     SetRectRgn( hrgn2, 10, 10, 50, 50 );
6199     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6200     check_update_rgn( hparent, hrgn );
6201     /* flush all paint messages */
6202     flush_events();
6203     flush_sequence();
6204
6205     /* same as above but parent gets completely validated */
6206     SetRect( &rect, 20, 20, 30, 30 );
6207     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6208     SetRectRgn( hrgn, 20, 20, 30, 30 );
6209     check_update_rgn( hparent, hrgn );
6210     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6211     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6212     check_update_rgn( hparent, 0 );  /* no update region */
6213     flush_events();
6214     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
6215
6216     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6217     flush_sequence();
6218     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6219     SetRectRgn( hrgn, 20, 20, 30, 30 );
6220     check_update_rgn( hparent, hrgn );
6221     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6222     SetRectRgn( hrgn, 20, 20, 30, 30 );
6223     check_update_rgn( hparent, hrgn );
6224
6225     /* same as above but normal WM_PAINT doesn't validate parent */
6226     flush_sequence();
6227     SetRect( &rect, 20, 20, 30, 30 );
6228     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6229     SetRectRgn( hrgn, 20, 20, 30, 30 );
6230     check_update_rgn( hparent, hrgn );
6231     /* no WM_PAINT in child while parent still pending */
6232     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6233     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6234     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6235     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6236
6237     flush_sequence();
6238     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6239     /* no WM_PAINT in child while parent still pending */
6240     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6241     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6242     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6243     /* now that parent is valid child should get WM_PAINT */
6244     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6245     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6246     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6247     ok_sequence( WmEmptySeq, "No other message", FALSE );
6248
6249     /* same thing with WS_CLIPCHILDREN in parent */
6250     flush_sequence();
6251     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6252     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6253     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6254     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6255     ok_sequence( WmEmptySeq, "No message", FALSE );
6256     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6257     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6258
6259     flush_sequence();
6260     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6261     SetRectRgn( hrgn, 20, 20, 30, 30 );
6262     check_update_rgn( hparent, hrgn );
6263     /* no WM_PAINT in child while parent still pending */
6264     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6265     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6266     /* WM_PAINT in parent first */
6267     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6268     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6269
6270     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6271     flush_sequence();
6272     SetRect( &rect, 0, 0, 30, 30 );
6273     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6274     SetRectRgn( hrgn, 0, 0, 30, 30 );
6275     check_update_rgn( hparent, hrgn );
6276     flush_events();
6277     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6278
6279     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6280     flush_sequence();
6281     SetRect( &rect, -10, 0, 30, 30 );
6282     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6283     SetRect( &rect, 0, 0, 20, 20 );
6284     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6285     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6286     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6287
6288     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6289     flush_sequence();
6290     SetRect( &rect, -10, 0, 30, 30 );
6291     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6292     SetRect( &rect, 0, 0, 100, 100 );
6293     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6294     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6295     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6296     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6297     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6298
6299     /* test RDW_INTERNALPAINT behavior */
6300
6301     flush_sequence();
6302     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6303     flush_events();
6304     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6305
6306     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6307     flush_events();
6308     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6309
6310     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6311     flush_events();
6312     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6313
6314     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6315     UpdateWindow( hparent );
6316     flush_events();
6317     flush_sequence();
6318     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6319     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6320     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6321                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6322     flush_events();
6323     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6324
6325     UpdateWindow( hparent );
6326     flush_events();
6327     flush_sequence();
6328     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6329     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6330     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6331                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6332     flush_events();
6333     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6334
6335     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6336     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6337     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6338     flush_events();
6339     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6340
6341     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6342     UpdateWindow( hparent );
6343     flush_events();
6344     flush_sequence();
6345     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6346     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6347     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6348                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6349     flush_events();
6350     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6351
6352     UpdateWindow( hparent );
6353     flush_events();
6354     flush_sequence();
6355     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6356     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6357     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6358                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6359     flush_events();
6360     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6361
6362     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6363     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6364
6365     UpdateWindow( hparent );
6366     flush_events();
6367     flush_sequence();
6368     trace("testing SetWindowPos(-10000, -10000) on child\n");
6369     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6370     check_update_rgn( hchild, 0 );
6371     flush_events();
6372
6373 #if 0 /* this one doesn't pass under Wine yet */
6374     UpdateWindow( hparent );
6375     flush_events();
6376     flush_sequence();
6377     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6378     ShowWindow( hchild, SW_MINIMIZE );
6379     check_update_rgn( hchild, 0 );
6380     flush_events();
6381 #endif
6382
6383     UpdateWindow( hparent );
6384     flush_events();
6385     flush_sequence();
6386     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6387     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6388     check_update_rgn( hparent, 0 );
6389     flush_events();
6390
6391     log_all_parent_messages--;
6392     DestroyWindow( hparent );
6393     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6394
6395     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6396
6397     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6398                               100, 100, 200, 200, 0, 0, 0, NULL);
6399     ok (hparent != 0, "Failed to create parent window\n");
6400
6401     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6402                            10, 10, 100, 100, hparent, 0, 0, NULL);
6403     ok (hchild != 0, "Failed to create child window\n");
6404
6405     ShowWindow( hparent, SW_SHOW );
6406     UpdateWindow( hparent );
6407     UpdateWindow( hchild );
6408     flush_events();
6409     flush_sequence();
6410
6411     /* moving child outside of parent boundaries changes update region */
6412     SetRect( &rect, 0, 0, 40, 40 );
6413     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6414     SetRectRgn( hrgn, 0, 0, 40, 40 );
6415     check_update_rgn( hchild, hrgn );
6416     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6417     SetRectRgn( hrgn, 10, 0, 40, 40 );
6418     check_update_rgn( hchild, hrgn );
6419     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6420     SetRectRgn( hrgn, 10, 10, 40, 40 );
6421     check_update_rgn( hchild, hrgn );
6422
6423     /* moving parent off-screen does too */
6424     SetRect( &rect, 0, 0, 100, 100 );
6425     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6426     SetRectRgn( hrgn, 0, 0, 100, 100 );
6427     check_update_rgn( hparent, hrgn );
6428     SetRectRgn( hrgn, 10, 10, 40, 40 );
6429     check_update_rgn( hchild, hrgn );
6430     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6431     SetRectRgn( hrgn, 20, 20, 100, 100 );
6432     check_update_rgn( hparent, hrgn );
6433     SetRectRgn( hrgn, 30, 30, 40, 40 );
6434     check_update_rgn( hchild, hrgn );
6435
6436     /* invalidated region is cropped by the parent rects */
6437     SetRect( &rect, 0, 0, 50, 50 );
6438     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6439     SetRectRgn( hrgn, 30, 30, 50, 50 );
6440     check_update_rgn( hchild, hrgn );
6441
6442     DestroyWindow( hparent );
6443     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6444     flush_sequence();
6445
6446     DeleteObject( hrgn );
6447     DeleteObject( hrgn2 );
6448 }
6449
6450 struct wnd_event
6451 {
6452     HWND hwnd;
6453     HANDLE grand_child;
6454     HANDLE start_event;
6455     HANDLE stop_event;
6456 };
6457
6458 static DWORD WINAPI thread_proc(void *param)
6459 {
6460     MSG msg;
6461     struct wnd_event *wnd_event = param;
6462
6463     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6464                                       100, 100, 200, 200, 0, 0, 0, NULL);
6465     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6466
6467     SetEvent(wnd_event->start_event);
6468
6469     while (GetMessage(&msg, 0, 0, 0))
6470     {
6471         TranslateMessage(&msg);
6472         DispatchMessage(&msg);
6473     }
6474
6475     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6476
6477     return 0;
6478 }
6479
6480 static DWORD CALLBACK create_grand_child_thread( void *param )
6481 {
6482     struct wnd_event *wnd_event = param;
6483     HWND hchild;
6484     MSG msg;
6485
6486     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6487                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6488     ok (hchild != 0, "Failed to create child window\n");
6489     flush_events();
6490     flush_sequence();
6491     SetEvent( wnd_event->start_event );
6492
6493     for (;;)
6494     {
6495         MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6496         if (!IsWindow( hchild )) break;  /* will be destroyed when parent thread exits */
6497         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6498     }
6499     return 0;
6500 }
6501
6502 static DWORD CALLBACK create_child_thread( void *param )
6503 {
6504     struct wnd_event *wnd_event = param;
6505     struct wnd_event child_event;
6506     DWORD ret, tid;
6507     MSG msg;
6508
6509     child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6510                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6511     ok (child_event.hwnd != 0, "Failed to create child window\n");
6512     SetFocus( child_event.hwnd );
6513     flush_events();
6514     flush_sequence();
6515     child_event.start_event = wnd_event->start_event;
6516     wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6517     for (;;)
6518     {
6519         DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6520         if (ret != 1) break;
6521         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6522     }
6523     ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6524     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6525     return 0;
6526 }
6527
6528 static void test_interthread_messages(void)
6529 {
6530     HANDLE hThread;
6531     DWORD tid;
6532     WNDPROC proc;
6533     MSG msg;
6534     char buf[256];
6535     int len, expected_len;
6536     struct wnd_event wnd_event;
6537     BOOL ret;
6538
6539     wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6540     if (!wnd_event.start_event)
6541     {
6542         win_skip("skipping interthread message test under win9x\n");
6543         return;
6544     }
6545
6546     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6547     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6548
6549     ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6550
6551     CloseHandle(wnd_event.start_event);
6552
6553     SetLastError(0xdeadbeef);
6554     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6555     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6556        "wrong error code %d\n", GetLastError());
6557
6558     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6559     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6560
6561     expected_len = lstrlenA("window caption text");
6562     memset(buf, 0, sizeof(buf));
6563     SetLastError(0xdeadbeef);
6564     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6565     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6566     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6567
6568     msg.hwnd = wnd_event.hwnd;
6569     msg.message = WM_GETTEXT;
6570     msg.wParam = sizeof(buf);
6571     msg.lParam = (LPARAM)buf;
6572     memset(buf, 0, sizeof(buf));
6573     SetLastError(0xdeadbeef);
6574     len = DispatchMessageA(&msg);
6575     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6576        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6577
6578     /* the following test causes an exception in user.exe under win9x */
6579     msg.hwnd = wnd_event.hwnd;
6580     msg.message = WM_TIMER;
6581     msg.wParam = 0;
6582     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6583     SetLastError(0xdeadbeef);
6584     len = DispatchMessageA(&msg);
6585     ok(!len && GetLastError() == 0xdeadbeef,
6586        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6587
6588     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6589     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6590
6591     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6592     CloseHandle(hThread);
6593
6594     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6595
6596     wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6597                               100, 100, 200, 200, 0, 0, 0, NULL);
6598     ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6599     flush_sequence();
6600     log_all_parent_messages++;
6601     wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6602     wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6603     hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6604     for (;;)
6605     {
6606         ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6607         if (ret != 1) break;
6608         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6609     }
6610     ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6611     /* now wait for the thread without processing messages; this shouldn't deadlock */
6612     SetEvent( wnd_event.stop_event );
6613     ret = WaitForSingleObject( hThread, 5000 );
6614     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6615     CloseHandle( hThread );
6616
6617     ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6618     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6619     CloseHandle( wnd_event.grand_child );
6620
6621     CloseHandle( wnd_event.start_event );
6622     CloseHandle( wnd_event.stop_event );
6623     flush_events();
6624     ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6625     log_all_parent_messages--;
6626     DestroyWindow( wnd_event.hwnd );
6627 }
6628
6629
6630 static const struct message WmVkN[] = {
6631     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6632     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6633     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6634     { WM_CHAR, wparam|lparam, 'n', 1 },
6635     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6636     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6637     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6638     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6639     { 0 }
6640 };
6641 static const struct message WmShiftVkN[] = {
6642     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6643     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6644     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6645     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6646     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6647     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6648     { WM_CHAR, wparam|lparam, 'N', 1 },
6649     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6650     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6651     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6652     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6653     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6654     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6655     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6656     { 0 }
6657 };
6658 static const struct message WmCtrlVkN[] = {
6659     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6660     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6661     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6662     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6663     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6664     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6665     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6666     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6667     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6668     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6669     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6670     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6671     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6672     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6673     { 0 }
6674 };
6675 static const struct message WmCtrlVkN_2[] = {
6676     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6677     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6678     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6679     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6680     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6681     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6682     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6683     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6684     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6685     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6686     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6687     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6688     { 0 }
6689 };
6690 static const struct message WmAltVkN[] = {
6691     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6692     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6693     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6694     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6695     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6696     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6697     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6698     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6699     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6700     { HCBT_SYSCOMMAND, hook },
6701     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6702     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6703     { 0x00AE, sent|defwinproc|optional }, /* XP */
6704     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6705     { WM_INITMENU, sent|defwinproc },
6706     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6707     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6708     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6709     { WM_CAPTURECHANGED, sent|defwinproc },
6710     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6711     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6712     { WM_EXITMENULOOP, sent|defwinproc },
6713     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6714     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6715     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6716     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6717     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6718     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6719     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6720     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6721     { 0 }
6722 };
6723 static const struct message WmAltVkN_2[] = {
6724     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6725     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6726     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6727     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6728     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6729     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6730     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6731     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6732     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6733     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6734     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6735     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6736     { 0 }
6737 };
6738 static const struct message WmCtrlAltVkN[] = {
6739     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6740     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6741     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6742     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6743     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6744     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6745     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6746     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6747     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6748     { WM_CHAR, optional },
6749     { WM_CHAR, sent|optional },
6750     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6751     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6752     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6753     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6754     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6755     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6756     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6757     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6758     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6759     { 0 }
6760 };
6761 static const struct message WmCtrlShiftVkN[] = {
6762     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6763     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6764     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6765     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6766     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6767     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6768     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6769     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6770     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6771     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6772     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6773     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6774     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6775     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6776     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6777     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6778     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6779     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6780     { 0 }
6781 };
6782 static const struct message WmCtrlAltShiftVkN[] = {
6783     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6784     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6785     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6786     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6787     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6788     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6789     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6790     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6791     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6792     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6793     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6794     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6795     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6796     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6797     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6798     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6799     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6800     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6801     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6802     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6803     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6804     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6805     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6806     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6807     { 0 }
6808 };
6809 static const struct message WmAltPressRelease[] = {
6810     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6811     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6812     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6813     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6814     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6815     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6816     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6817     { HCBT_SYSCOMMAND, hook },
6818     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6819     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6820     { WM_INITMENU, sent|defwinproc },
6821     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6822     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6823     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6824
6825     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6826
6827     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6828     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6829     { WM_CAPTURECHANGED, sent|defwinproc },
6830     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6831     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6832     { WM_EXITMENULOOP, sent|defwinproc },
6833     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6834     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6835     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6836     { 0 }
6837 };
6838 static const struct message WmShiftMouseButton[] = {
6839     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6840     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6841     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6842     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6843     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6844     { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6845     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6846     { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6847     { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6848     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6849     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6850     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6851     { 0 }
6852 };
6853 static const struct message WmF1Seq[] = {
6854     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6855     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6856     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6857     { WM_KEYF1, wparam|lparam, 0, 0 },
6858     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6859     { WM_HELP, sent|defwinproc },
6860     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6861     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6862     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6863     { 0 }
6864 };
6865 static const struct message WmVkAppsSeq[] = {
6866     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6867     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6868     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6869     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6870     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6871     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6872     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6873     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6874     { 0 }
6875 };
6876 static const struct message WmVkF10Seq[] = {
6877     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6878     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
6879     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
6880     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6881     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6882     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6883     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
6884     { HCBT_SYSCOMMAND, hook },
6885     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6886     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6887     { WM_INITMENU, sent|defwinproc },
6888     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6889     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6890     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6891
6892     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
6893
6894     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6895     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6896     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6897     { WM_CAPTURECHANGED, sent|defwinproc },
6898     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6899     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6900     { WM_EXITMENULOOP, sent|defwinproc },
6901     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6902     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6903     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6904     { 0 }
6905 };
6906
6907 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6908 {
6909     MSG msg;
6910
6911     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6912     {
6913         struct recvd_message log_msg;
6914
6915         /* ignore some unwanted messages */
6916         if (msg.message == WM_MOUSEMOVE ||
6917             msg.message == WM_TIMER ||
6918             ignore_message( msg.message ))
6919             continue;
6920
6921         log_msg.hwnd = msg.hwnd;
6922         log_msg.message = msg.message;
6923         log_msg.flags = wparam|lparam;
6924         log_msg.wParam = msg.wParam;
6925         log_msg.lParam = msg.lParam;
6926         log_msg.descr = "accel";
6927         add_message(&log_msg);
6928
6929         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6930         {
6931             TranslateMessage(&msg);
6932             DispatchMessage(&msg);
6933         }
6934     }
6935 }
6936
6937 static void test_accelerators(void)
6938 {
6939     RECT rc;
6940     POINT pt;
6941     SHORT state;
6942     HACCEL hAccel;
6943     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6944                                 100, 100, 200, 200, 0, 0, 0, NULL);
6945     BOOL ret;
6946
6947     assert(hwnd != 0);
6948     UpdateWindow(hwnd);
6949     flush_events();
6950     flush_sequence();
6951
6952     SetFocus(hwnd);
6953     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6954
6955     state = GetKeyState(VK_SHIFT);
6956     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6957     state = GetKeyState(VK_CAPITAL);
6958     ok(state == 0, "wrong CapsLock state %04x\n", state);
6959
6960     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6961     assert(hAccel != 0);
6962
6963     flush_events();
6964     pump_msg_loop(hwnd, 0);
6965     flush_sequence();
6966
6967     trace("testing VK_N press/release\n");
6968     flush_sequence();
6969     keybd_event('N', 0, 0, 0);
6970     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6971     pump_msg_loop(hwnd, hAccel);
6972     if (!sequence_cnt)  /* we didn't get any message */
6973     {
6974         skip( "queuing key events not supported\n" );
6975         goto done;
6976     }
6977     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6978
6979     trace("testing Shift+VK_N press/release\n");
6980     flush_sequence();
6981     keybd_event(VK_SHIFT, 0, 0, 0);
6982     keybd_event('N', 0, 0, 0);
6983     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6984     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6985     pump_msg_loop(hwnd, hAccel);
6986     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6987
6988     trace("testing Ctrl+VK_N press/release\n");
6989     flush_sequence();
6990     keybd_event(VK_CONTROL, 0, 0, 0);
6991     keybd_event('N', 0, 0, 0);
6992     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6993     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6994     pump_msg_loop(hwnd, hAccel);
6995     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6996
6997     trace("testing Alt+VK_N press/release\n");
6998     flush_sequence();
6999     keybd_event(VK_MENU, 0, 0, 0);
7000     keybd_event('N', 0, 0, 0);
7001     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7002     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7003     pump_msg_loop(hwnd, hAccel);
7004     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7005
7006     trace("testing Ctrl+Alt+VK_N press/release 1\n");
7007     flush_sequence();
7008     keybd_event(VK_CONTROL, 0, 0, 0);
7009     keybd_event(VK_MENU, 0, 0, 0);
7010     keybd_event('N', 0, 0, 0);
7011     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7012     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7013     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7014     pump_msg_loop(hwnd, hAccel);
7015     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7016
7017     ret = DestroyAcceleratorTable(hAccel);
7018     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7019
7020     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7021     assert(hAccel != 0);
7022
7023     trace("testing VK_N press/release\n");
7024     flush_sequence();
7025     keybd_event('N', 0, 0, 0);
7026     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7027     pump_msg_loop(hwnd, hAccel);
7028     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7029
7030     trace("testing Shift+VK_N press/release\n");
7031     flush_sequence();
7032     keybd_event(VK_SHIFT, 0, 0, 0);
7033     keybd_event('N', 0, 0, 0);
7034     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7035     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7036     pump_msg_loop(hwnd, hAccel);
7037     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7038
7039     trace("testing Ctrl+VK_N press/release 2\n");
7040     flush_sequence();
7041     keybd_event(VK_CONTROL, 0, 0, 0);
7042     keybd_event('N', 0, 0, 0);
7043     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7044     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7045     pump_msg_loop(hwnd, hAccel);
7046     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7047
7048     trace("testing Alt+VK_N press/release 2\n");
7049     flush_sequence();
7050     keybd_event(VK_MENU, 0, 0, 0);
7051     keybd_event('N', 0, 0, 0);
7052     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7053     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7054     pump_msg_loop(hwnd, hAccel);
7055     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7056
7057     trace("testing Ctrl+Alt+VK_N press/release 2\n");
7058     flush_sequence();
7059     keybd_event(VK_CONTROL, 0, 0, 0);
7060     keybd_event(VK_MENU, 0, 0, 0);
7061     keybd_event('N', 0, 0, 0);
7062     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7063     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7064     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7065     pump_msg_loop(hwnd, hAccel);
7066     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7067
7068     trace("testing Ctrl+Shift+VK_N press/release\n");
7069     flush_sequence();
7070     keybd_event(VK_CONTROL, 0, 0, 0);
7071     keybd_event(VK_SHIFT, 0, 0, 0);
7072     keybd_event('N', 0, 0, 0);
7073     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7074     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7075     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7076     pump_msg_loop(hwnd, hAccel);
7077     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7078
7079     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7080     flush_sequence();
7081     keybd_event(VK_CONTROL, 0, 0, 0);
7082     keybd_event(VK_MENU, 0, 0, 0);
7083     keybd_event(VK_SHIFT, 0, 0, 0);
7084     keybd_event('N', 0, 0, 0);
7085     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7086     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7087     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7088     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7089     pump_msg_loop(hwnd, hAccel);
7090     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7091
7092     ret = DestroyAcceleratorTable(hAccel);
7093     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7094     hAccel = 0;
7095
7096     trace("testing Alt press/release\n");
7097     flush_sequence();
7098     keybd_event(VK_MENU, 0, 0, 0);
7099     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7100     keybd_event(VK_MENU, 0, 0, 0);
7101     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7102     pump_msg_loop(hwnd, 0);
7103     /* this test doesn't pass in Wine for managed windows */
7104     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7105
7106     trace("testing VK_F1 press/release\n");
7107     keybd_event(VK_F1, 0, 0, 0);
7108     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7109     pump_msg_loop(hwnd, 0);
7110     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7111
7112     trace("testing VK_APPS press/release\n");
7113     keybd_event(VK_APPS, 0, 0, 0);
7114     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7115     pump_msg_loop(hwnd, 0);
7116     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7117
7118     trace("testing VK_F10 press/release\n");
7119     keybd_event(VK_F10, 0, 0, 0);
7120     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7121     keybd_event(VK_F10, 0, 0, 0);
7122     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7123     pump_msg_loop(hwnd, 0);
7124     ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7125
7126     trace("testing Shift+MouseButton press/release\n");
7127     /* first, move mouse pointer inside of the window client area */
7128     GetClientRect(hwnd, &rc);
7129     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7130     rc.left += (rc.right - rc.left)/2;
7131     rc.top += (rc.bottom - rc.top)/2;
7132     SetCursorPos(rc.left, rc.top);
7133     SetActiveWindow(hwnd);
7134
7135     flush_events();
7136     flush_sequence();
7137     GetCursorPos(&pt);
7138     if (pt.x == rc.left && pt.y == rc.top)
7139     {
7140         int i;
7141         keybd_event(VK_SHIFT, 0, 0, 0);
7142         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7143         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7144         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7145         pump_msg_loop(hwnd, 0);
7146         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7147         if (i < sequence_cnt)
7148             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7149         else
7150             skip( "Shift+MouseButton event didn't get to the window\n" );
7151     }
7152
7153 done:
7154     if (hAccel) DestroyAcceleratorTable(hAccel);
7155     DestroyWindow(hwnd);
7156 }
7157
7158 /************* window procedures ********************/
7159
7160 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
7161                              WPARAM wParam, LPARAM lParam)
7162 {
7163     static LONG defwndproc_counter = 0;
7164     static LONG beginpaint_counter = 0;
7165     LRESULT ret;
7166     struct recvd_message msg;
7167
7168     if (ignore_message( message )) return 0;
7169
7170     switch (message)
7171     {
7172         case WM_ENABLE:
7173         {
7174             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7175             ok((BOOL)wParam == !(style & WS_DISABLED),
7176                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7177             break;
7178         }
7179
7180         case WM_CAPTURECHANGED:
7181             if (test_DestroyWindow_flag)
7182             {
7183                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7184                 if (style & WS_CHILD)
7185                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7186                 else if (style & WS_POPUP)
7187                     lParam = WND_POPUP_ID;
7188                 else
7189                     lParam = WND_PARENT_ID;
7190             }
7191             break;
7192
7193         case WM_NCDESTROY:
7194         {
7195             HWND capture;
7196
7197             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7198             capture = GetCapture();
7199             if (capture)
7200             {
7201                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7202                 trace("current capture %p, releasing...\n", capture);
7203                 ReleaseCapture();
7204             }
7205         }
7206         /* fall through */
7207         case WM_DESTROY:
7208             if (pGetAncestor)
7209                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7210             if (test_DestroyWindow_flag)
7211             {
7212                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7213                 if (style & WS_CHILD)
7214                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7215                 else if (style & WS_POPUP)
7216                     lParam = WND_POPUP_ID;
7217                 else
7218                     lParam = WND_PARENT_ID;
7219             }
7220             break;
7221
7222         /* test_accelerators() depends on this */
7223         case WM_NCHITTEST:
7224             return HTCLIENT;
7225
7226         /* ignore */
7227         case WM_MOUSEMOVE:
7228         case WM_MOUSEACTIVATE:
7229         case WM_NCMOUSEMOVE:
7230         case WM_SETCURSOR:
7231         case WM_IME_SELECT:
7232             return 0;
7233     }
7234
7235     msg.hwnd = hwnd;
7236     msg.message = message;
7237     msg.flags = sent|wparam|lparam;
7238     if (defwndproc_counter) msg.flags |= defwinproc;
7239     if (beginpaint_counter) msg.flags |= beginpaint;
7240     msg.wParam = wParam;
7241     msg.lParam = lParam;
7242     msg.descr = "MsgCheckProc";
7243     add_message(&msg);
7244
7245     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7246     {
7247         HWND parent = GetParent(hwnd);
7248         RECT rc;
7249         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7250
7251         GetClientRect(parent, &rc);
7252         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7253         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7254               minmax->ptReserved.x, minmax->ptReserved.y,
7255               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7256               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7257               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7258               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7259
7260         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7261            minmax->ptMaxSize.x, rc.right);
7262         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7263            minmax->ptMaxSize.y, rc.bottom);
7264     }
7265
7266     if (message == WM_PAINT)
7267     {
7268         PAINTSTRUCT ps;
7269         beginpaint_counter++;
7270         BeginPaint( hwnd, &ps );
7271         beginpaint_counter--;
7272         EndPaint( hwnd, &ps );
7273         return 0;
7274     }
7275
7276     defwndproc_counter++;
7277     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
7278                   : DefWindowProcA(hwnd, message, wParam, lParam);
7279     defwndproc_counter--;
7280
7281     return ret;
7282 }
7283
7284 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7285 {
7286     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7287 }
7288
7289 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7290 {
7291     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7292 }
7293
7294 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7295 {
7296     static LONG defwndproc_counter = 0;
7297     LRESULT ret;
7298     struct recvd_message msg;
7299
7300     if (ignore_message( message )) return 0;
7301
7302     switch (message)
7303     {
7304     case WM_QUERYENDSESSION:
7305     case WM_ENDSESSION:
7306         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7307         break;
7308     }
7309
7310     msg.hwnd = hwnd;
7311     msg.message = message;
7312     msg.flags = sent|wparam|lparam;
7313     if (defwndproc_counter) msg.flags |= defwinproc;
7314     msg.wParam = wParam;
7315     msg.lParam = lParam;
7316     msg.descr = "popup";
7317     add_message(&msg);
7318
7319     if (message == WM_CREATE)
7320     {
7321         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7322         SetWindowLongA(hwnd, GWL_STYLE, style);
7323     }
7324
7325     defwndproc_counter++;
7326     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7327     defwndproc_counter--;
7328
7329     return ret;
7330 }
7331
7332 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7333 {
7334     static LONG defwndproc_counter = 0;
7335     static LONG beginpaint_counter = 0;
7336     LRESULT ret;
7337     struct recvd_message msg;
7338
7339     if (ignore_message( message )) return 0;
7340
7341     if (log_all_parent_messages ||
7342         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7343         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7344         message == WM_ENABLE || message == WM_ENTERIDLE ||
7345         message == WM_DRAWITEM || message == WM_COMMAND ||
7346         message == WM_IME_SETCONTEXT)
7347     {
7348         switch (message)
7349         {
7350             /* ignore */
7351             case WM_NCHITTEST:
7352                 return HTCLIENT;
7353             case WM_SETCURSOR:
7354             case WM_MOUSEMOVE:
7355             case WM_NCMOUSEMOVE:
7356                 return 0;
7357
7358             case WM_ERASEBKGND:
7359             {
7360                 RECT rc;
7361                 INT ret = GetClipBox((HDC)wParam, &rc);
7362
7363                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7364                        ret, rc.left, rc.top, rc.right, rc.bottom);
7365                 break;
7366             }
7367         }
7368
7369         msg.hwnd = hwnd;
7370         msg.message = message;
7371         msg.flags = sent|parent|wparam|lparam;
7372         if (defwndproc_counter) msg.flags |= defwinproc;
7373         if (beginpaint_counter) msg.flags |= beginpaint;
7374         msg.wParam = wParam;
7375         msg.lParam = lParam;
7376         msg.descr = "parent";
7377         add_message(&msg);
7378     }
7379
7380     if (message == WM_PAINT)
7381     {
7382         PAINTSTRUCT ps;
7383         beginpaint_counter++;
7384         BeginPaint( hwnd, &ps );
7385         beginpaint_counter--;
7386         EndPaint( hwnd, &ps );
7387         return 0;
7388     }
7389
7390     defwndproc_counter++;
7391     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7392     defwndproc_counter--;
7393
7394     return ret;
7395 }
7396
7397 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7398 {
7399     static LONG defwndproc_counter = 0;
7400     LRESULT ret;
7401     struct recvd_message msg;
7402
7403     if (ignore_message( message )) return 0;
7404
7405     if (test_def_id)
7406     {
7407         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7408         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7409         if (after_end_dialog)
7410             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7411         else
7412             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7413     }
7414
7415     msg.hwnd = hwnd;
7416     msg.message = message;
7417     msg.flags = sent|wparam|lparam;
7418     if (defwndproc_counter) msg.flags |= defwinproc;
7419     msg.wParam = wParam;
7420     msg.lParam = lParam;
7421     msg.descr = "dialog";
7422     add_message(&msg);
7423
7424     defwndproc_counter++;
7425     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7426     defwndproc_counter--;
7427
7428     return ret;
7429 }
7430
7431 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7432 {
7433     static LONG defwndproc_counter = 0;
7434     LRESULT ret;
7435     struct recvd_message msg;
7436
7437     /* log only specific messages we are interested in */
7438     switch (message)
7439     {
7440 #if 0 /* probably log these as well */
7441     case WM_ACTIVATE:
7442     case WM_SETFOCUS:
7443     case WM_KILLFOCUS:
7444 #endif
7445     case WM_SHOWWINDOW:
7446     case WM_SIZE:
7447     case WM_MOVE:
7448     case WM_GETMINMAXINFO:
7449     case WM_WINDOWPOSCHANGING:
7450     case WM_WINDOWPOSCHANGED:
7451         break;
7452
7453     default: /* ignore */
7454         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7455         return DefWindowProcA(hwnd, message, wParam, lParam);
7456     }
7457
7458     msg.hwnd = hwnd;
7459     msg.message = message;
7460     msg.flags = sent|wparam|lparam;
7461     if (defwndproc_counter) msg.flags |= defwinproc;
7462     msg.wParam = wParam;
7463     msg.lParam = lParam;
7464     msg.descr = "show";
7465     add_message(&msg);
7466
7467     defwndproc_counter++;
7468     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7469     defwndproc_counter--;
7470
7471     return ret;
7472 }
7473
7474 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7475 {
7476     switch (msg)
7477     {
7478         case WM_CREATE: return 0;
7479         case WM_PAINT:
7480         {
7481             MSG msg2;
7482             static int i = 0;
7483
7484             if (i < 256)
7485             {
7486                 i++;
7487                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7488                 {
7489                     TranslateMessage(&msg2);
7490                     DispatchMessage(&msg2);
7491                 }
7492                 i--;
7493             }
7494             else ok(broken(1), "infinite loop\n");
7495             if ( i == 0)
7496                 paint_loop_done = 1;
7497             return DefWindowProcA(hWnd,msg,wParam,lParam);
7498         }
7499     }
7500     return DefWindowProcA(hWnd,msg,wParam,lParam);
7501 }
7502
7503 static BOOL RegisterWindowClasses(void)
7504 {
7505     WNDCLASSA cls;
7506     WNDCLASSW clsW;
7507
7508     cls.style = 0;
7509     cls.lpfnWndProc = MsgCheckProcA;
7510     cls.cbClsExtra = 0;
7511     cls.cbWndExtra = 0;
7512     cls.hInstance = GetModuleHandleA(0);
7513     cls.hIcon = 0;
7514     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7515     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7516     cls.lpszMenuName = NULL;
7517     cls.lpszClassName = "TestWindowClass";
7518     if(!RegisterClassA(&cls)) return FALSE;
7519
7520     cls.lpfnWndProc = ShowWindowProcA;
7521     cls.lpszClassName = "ShowWindowClass";
7522     if(!RegisterClassA(&cls)) return FALSE;
7523
7524     cls.lpfnWndProc = PopupMsgCheckProcA;
7525     cls.lpszClassName = "TestPopupClass";
7526     if(!RegisterClassA(&cls)) return FALSE;
7527
7528     cls.lpfnWndProc = ParentMsgCheckProcA;
7529     cls.lpszClassName = "TestParentClass";
7530     if(!RegisterClassA(&cls)) return FALSE;
7531
7532     cls.lpfnWndProc = DefWindowProcA;
7533     cls.lpszClassName = "SimpleWindowClass";
7534     if(!RegisterClassA(&cls)) return FALSE;
7535
7536     cls.lpfnWndProc = PaintLoopProcA;
7537     cls.lpszClassName = "PaintLoopWindowClass";
7538     if(!RegisterClassA(&cls)) return FALSE;
7539
7540     cls.style = CS_NOCLOSE;
7541     cls.lpszClassName = "NoCloseWindowClass";
7542     if(!RegisterClassA(&cls)) return FALSE;
7543
7544     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7545     cls.style = 0;
7546     cls.hInstance = GetModuleHandleA(0);
7547     cls.hbrBackground = 0;
7548     cls.lpfnWndProc = TestDlgProcA;
7549     cls.lpszClassName = "TestDialogClass";
7550     if(!RegisterClassA(&cls)) return FALSE;
7551
7552     clsW.style = 0;
7553     clsW.lpfnWndProc = MsgCheckProcW;
7554     clsW.cbClsExtra = 0;
7555     clsW.cbWndExtra = 0;
7556     clsW.hInstance = GetModuleHandleW(0);
7557     clsW.hIcon = 0;
7558     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7559     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7560     clsW.lpszMenuName = NULL;
7561     clsW.lpszClassName = testWindowClassW;
7562     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7563
7564     return TRUE;
7565 }
7566
7567 static BOOL is_our_logged_class(HWND hwnd)
7568 {
7569     char buf[256];
7570
7571     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7572     {
7573         if (!lstrcmpiA(buf, "TestWindowClass") ||
7574             !lstrcmpiA(buf, "ShowWindowClass") ||
7575             !lstrcmpiA(buf, "TestParentClass") ||
7576             !lstrcmpiA(buf, "TestPopupClass") ||
7577             !lstrcmpiA(buf, "SimpleWindowClass") ||
7578             !lstrcmpiA(buf, "TestDialogClass") ||
7579             !lstrcmpiA(buf, "MDI_frame_class") ||
7580             !lstrcmpiA(buf, "MDI_client_class") ||
7581             !lstrcmpiA(buf, "MDI_child_class") ||
7582             !lstrcmpiA(buf, "my_button_class") ||
7583             !lstrcmpiA(buf, "my_edit_class") ||
7584             !lstrcmpiA(buf, "static") ||
7585             !lstrcmpiA(buf, "ListBox") ||
7586             !lstrcmpiA(buf, "ComboBox") ||
7587             !lstrcmpiA(buf, "MyDialogClass") ||
7588             !lstrcmpiA(buf, "#32770") ||
7589             !lstrcmpiA(buf, "#32768"))
7590         return TRUE;
7591     }
7592     return FALSE;
7593 }
7594
7595 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7596
7597     HWND hwnd;
7598
7599     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7600
7601     if (nCode == HCBT_CLICKSKIPPED)
7602     {
7603         /* ignore this event, XP sends it a lot when switching focus between windows */
7604         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7605     }
7606
7607     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7608     {
7609         struct recvd_message msg;
7610
7611         msg.hwnd = 0;
7612         msg.message = nCode;
7613         msg.flags = hook|wparam|lparam;
7614         msg.wParam = wParam;
7615         msg.lParam = lParam;
7616         msg.descr = "CBT";
7617         add_message(&msg);
7618
7619         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7620     }
7621
7622     if (nCode == HCBT_DESTROYWND)
7623     {
7624         if (test_DestroyWindow_flag)
7625         {
7626             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7627             if (style & WS_CHILD)
7628                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7629             else if (style & WS_POPUP)
7630                 lParam = WND_POPUP_ID;
7631             else
7632                 lParam = WND_PARENT_ID;
7633         }
7634     }
7635
7636     /* Log also SetFocus(0) calls */
7637     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7638
7639     if (is_our_logged_class(hwnd))
7640     {
7641         struct recvd_message msg;
7642
7643         msg.hwnd = hwnd;
7644         msg.message = nCode;
7645         msg.flags = hook|wparam|lparam;
7646         msg.wParam = wParam;
7647         msg.lParam = lParam;
7648         msg.descr = "CBT";
7649         add_message(&msg);
7650     }
7651     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7652 }
7653
7654 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7655                                     DWORD event,
7656                                     HWND hwnd,
7657                                     LONG object_id,
7658                                     LONG child_id,
7659                                     DWORD thread_id,
7660                                     DWORD event_time)
7661 {
7662     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7663
7664     /* ignore mouse cursor events */
7665     if (object_id == OBJID_CURSOR) return;
7666
7667     if (!hwnd || is_our_logged_class(hwnd))
7668     {
7669         struct recvd_message msg;
7670
7671         msg.hwnd = hwnd;
7672         msg.message = event;
7673         msg.flags = winevent_hook|wparam|lparam;
7674         msg.wParam = object_id;
7675         msg.lParam = child_id;
7676         msg.descr = "WEH";
7677         add_message(&msg);
7678     }
7679 }
7680
7681 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7682 static const WCHAR wszAnsi[] = {'U',0};
7683
7684 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7685 {
7686     switch (uMsg)
7687     {
7688     case CB_FINDSTRINGEXACT:
7689         trace("String: %p\n", (LPCWSTR)lParam);
7690         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7691             return 1;
7692         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7693             return 0;
7694         return -1;
7695     }
7696     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7697 }
7698
7699 static const struct message WmGetTextLengthAfromW[] = {
7700     { WM_GETTEXTLENGTH, sent },
7701     { WM_GETTEXT, sent|optional },
7702     { 0 }
7703 };
7704
7705 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7706
7707 /* dummy window proc for WM_GETTEXTLENGTH test */
7708 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7709 {
7710     switch(msg)
7711     {
7712     case WM_GETTEXTLENGTH:
7713         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7714     case WM_GETTEXT:
7715         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7716         return lstrlenW( (LPWSTR)lp );
7717     default:
7718         return DefWindowProcW( hwnd, msg, wp, lp );
7719     }
7720 }
7721
7722 static void test_message_conversion(void)
7723 {
7724     static const WCHAR wszMsgConversionClass[] =
7725         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7726     WNDCLASSW cls;
7727     LRESULT lRes;
7728     HWND hwnd;
7729     WNDPROC wndproc, newproc;
7730     BOOL ret;
7731
7732     cls.style = 0;
7733     cls.lpfnWndProc = MsgConversionProcW;
7734     cls.cbClsExtra = 0;
7735     cls.cbWndExtra = 0;
7736     cls.hInstance = GetModuleHandleW(NULL);
7737     cls.hIcon = NULL;
7738     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7739     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7740     cls.lpszMenuName = NULL;
7741     cls.lpszClassName = wszMsgConversionClass;
7742     /* this call will fail on Win9x, but that doesn't matter as this test is
7743      * meaningless on those platforms */
7744     if(!RegisterClassW(&cls)) return;
7745
7746     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7747                            100, 100, 200, 200, 0, 0, 0, NULL);
7748     ok(hwnd != NULL, "Window creation failed\n");
7749
7750     /* {W, A} -> A */
7751
7752     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7753     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7754     ok(lRes == 0, "String should have been converted\n");
7755     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7756     ok(lRes == 1, "String shouldn't have been converted\n");
7757
7758     /* {W, A} -> W */
7759
7760     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7761     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7762     ok(lRes == 1, "String shouldn't have been converted\n");
7763     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7764     ok(lRes == 1, "String shouldn't have been converted\n");
7765
7766     /* Synchronous messages */
7767
7768     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7769     ok(lRes == 0, "String should have been converted\n");
7770     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7771     ok(lRes == 1, "String shouldn't have been converted\n");
7772
7773     /* Asynchronous messages */
7774
7775     SetLastError(0);
7776     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7777     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7778         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7779     SetLastError(0);
7780     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7781     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7782         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7783     SetLastError(0);
7784     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7785     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7786         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7787     SetLastError(0);
7788     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7789     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7790         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7791     SetLastError(0);
7792     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7793     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7794         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7795     SetLastError(0);
7796     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7797     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7798         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7799     SetLastError(0);
7800     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7801     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7802         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7803     SetLastError(0);
7804     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7805     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7806         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7807
7808     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7809
7810     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7811                           WS_OVERLAPPEDWINDOW,
7812                           100, 100, 200, 200, 0, 0, 0, NULL);
7813     assert(hwnd);
7814     flush_sequence();
7815     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7816     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7817     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7818         "got bad length %ld\n", lRes );
7819
7820     flush_sequence();
7821     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7822                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7823     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7824     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7825         "got bad length %ld\n", lRes );
7826
7827     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7828     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7829     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7830     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7831                                      NULL, 0, NULL, NULL ) ||
7832         broken(lRes == lstrlenW(dummy_window_text) + 37),
7833         "got bad length %ld\n", lRes );
7834
7835     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7836     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7837     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7838                                      NULL, 0, NULL, NULL ) ||
7839         broken(lRes == lstrlenW(dummy_window_text) + 37),
7840         "got bad length %ld\n", lRes );
7841
7842     ret = DestroyWindow(hwnd);
7843     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7844 }
7845
7846 struct timer_info
7847 {
7848     HWND hWnd;
7849     HANDLE handles[2];
7850     DWORD id;
7851 };
7852
7853 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7854 {
7855 }
7856
7857 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7858 {
7859     /* Crash on purpose */
7860     *(volatile int *)0 = 2;
7861 }
7862
7863 #define TIMER_ID  0x19
7864
7865 static DWORD WINAPI timer_thread_proc(LPVOID x)
7866 {
7867     struct timer_info *info = x;
7868     DWORD r;
7869
7870     r = KillTimer(info->hWnd, 0x19);
7871     ok(r,"KillTimer failed in thread\n");
7872     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7873     ok(r,"SetTimer failed in thread\n");
7874     ok(r==TIMER_ID,"SetTimer id different\n");
7875     r = SetEvent(info->handles[0]);
7876     ok(r,"SetEvent failed in thread\n");
7877     return 0;
7878 }
7879
7880 static void test_timers(void)
7881 {
7882     struct timer_info info;
7883     DWORD id;
7884     MSG msg;
7885
7886     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7887        WS_OVERLAPPEDWINDOW ,
7888        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7889        NULL, NULL, 0);
7890
7891     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7892     ok(info.id, "SetTimer failed\n");
7893     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7894     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7895     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7896
7897     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7898
7899     WaitForSingleObject(info.handles[1], INFINITE);
7900
7901     CloseHandle(info.handles[0]);
7902     CloseHandle(info.handles[1]);
7903
7904     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7905
7906     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7907
7908     /* Test timer callback with crash */
7909     SetLastError(0xdeadbeef);
7910     info.hWnd = CreateWindowW(testWindowClassW, NULL,
7911                               WS_OVERLAPPEDWINDOW ,
7912                               CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7913                               NULL, NULL, 0);
7914     if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
7915         (!pGetMenuInfo)) /* Win95/NT4 */
7916     {
7917         win_skip("Test would crash on Win9x/WinMe/NT4\n");
7918         DestroyWindow(info.hWnd);
7919         return;
7920     }
7921     info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
7922     ok(info.id, "SetTimer failed\n");
7923     Sleep(150);
7924     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7925
7926     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7927 }
7928
7929 static int count = 0;
7930 static VOID CALLBACK callback_count(
7931     HWND hwnd,
7932     UINT uMsg,
7933     UINT_PTR idEvent,
7934     DWORD dwTime
7935 )
7936 {
7937     count++;
7938 }
7939
7940 static void test_timers_no_wnd(void)
7941 {
7942     UINT_PTR id, id2;
7943     MSG msg;
7944
7945     count = 0;
7946     id = SetTimer(NULL, 0, 100, callback_count);
7947     ok(id != 0, "did not get id from SetTimer.\n");
7948     id2 = SetTimer(NULL, id, 200, callback_count);
7949     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7950     Sleep(150);
7951     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7952     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7953     Sleep(150);
7954     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7955     ok(count == 1, "did not get one count as expected (%i).\n", count);
7956     KillTimer(NULL, id);
7957     Sleep(250);
7958     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7959     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7960 }
7961
7962 /* Various win events with arbitrary parameters */
7963 static const struct message WmWinEventsSeq[] = {
7964     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7965     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7966     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7967     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7968     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7969     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7970     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7971     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7972     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7973     /* our win event hook ignores OBJID_CURSOR events */
7974     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7975     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7976     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7977     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7978     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7979     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7980     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7981     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7982     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7983     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7984     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7985     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7986     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7987     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7988     { 0 }
7989 };
7990 static const struct message WmWinEventCaretSeq[] = {
7991     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7992     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7993     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7994     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7995     { 0 }
7996 };
7997 static const struct message WmWinEventCaretSeq_2[] = {
7998     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7999     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8000     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8001     { 0 }
8002 };
8003 static const struct message WmWinEventAlertSeq[] = {
8004     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8005     { 0 }
8006 };
8007 static const struct message WmWinEventAlertSeq_2[] = {
8008     /* create window in the thread proc */
8009     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8010     /* our test event */
8011     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8012     { 0 }
8013 };
8014 static const struct message WmGlobalHookSeq_1[] = {
8015     /* create window in the thread proc */
8016     { HCBT_CREATEWND, hook|lparam, 0, 2 },
8017     /* our test events */
8018     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8019     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8020     { 0 }
8021 };
8022 static const struct message WmGlobalHookSeq_2[] = {
8023     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8024     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8025     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8026     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8027     { 0 }
8028 };
8029
8030 static const struct message WmMouseLLHookSeq[] = {
8031     { WM_MOUSEMOVE, hook },
8032     { WM_LBUTTONUP, hook },
8033     { WM_MOUSEMOVE, hook },
8034     { 0 }
8035 };
8036
8037 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8038                                          DWORD event,
8039                                          HWND hwnd,
8040                                          LONG object_id,
8041                                          LONG child_id,
8042                                          DWORD thread_id,
8043                                          DWORD event_time)
8044 {
8045     char buf[256];
8046
8047     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8048     {
8049         if (!lstrcmpiA(buf, "TestWindowClass") ||
8050             !lstrcmpiA(buf, "static"))
8051         {
8052             struct recvd_message msg;
8053
8054             msg.hwnd = hwnd;
8055             msg.message = event;
8056             msg.flags = winevent_hook|wparam|lparam;
8057             msg.wParam = object_id;
8058             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8059             msg.descr = "WEH_2";
8060             add_message(&msg);
8061         }
8062     }
8063 }
8064
8065 static HHOOK hCBT_global_hook;
8066 static DWORD cbt_global_hook_thread_id;
8067
8068 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
8069
8070     HWND hwnd;
8071     char buf[256];
8072
8073     if (nCode == HCBT_SYSCOMMAND)
8074     {
8075         struct recvd_message msg;
8076
8077         msg.hwnd = 0;
8078         msg.message = nCode;
8079         msg.flags = hook|wparam|lparam;
8080         msg.wParam = wParam;
8081         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8082         msg.descr = "CBT_2";
8083         add_message(&msg);
8084
8085         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8086     }
8087     /* WH_MOUSE_LL hook */
8088     if (nCode == HC_ACTION)
8089     {
8090         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8091
8092         /* we can't test for real mouse events */
8093         if (mhll->flags & LLMHF_INJECTED)
8094         {
8095             struct recvd_message msg;
8096
8097             memset (&msg, 0, sizeof (msg));
8098             msg.message = wParam;
8099             msg.flags = hook;
8100             msg.descr = "CBT_2";
8101             add_message(&msg);
8102         }
8103         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8104     }
8105
8106     /* Log also SetFocus(0) calls */
8107     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8108
8109     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8110     {
8111         if (!lstrcmpiA(buf, "TestWindowClass") ||
8112             !lstrcmpiA(buf, "static"))
8113         {
8114             struct recvd_message msg;
8115
8116             msg.hwnd = hwnd;
8117             msg.message = nCode;
8118             msg.flags = hook|wparam|lparam;
8119             msg.wParam = wParam;
8120             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8121             msg.descr = "CBT_2";
8122             add_message(&msg);
8123         }
8124     }
8125     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8126 }
8127
8128 static DWORD WINAPI win_event_global_thread_proc(void *param)
8129 {
8130     HWND hwnd;
8131     MSG msg;
8132     HANDLE hevent = *(HANDLE *)param;
8133
8134     assert(pNotifyWinEvent);
8135
8136     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8137     assert(hwnd);
8138     trace("created thread window %p\n", hwnd);
8139
8140     *(HWND *)param = hwnd;
8141
8142     flush_sequence();
8143     /* this event should be received only by our new hook proc,
8144      * an old one does not expect an event from another thread.
8145      */
8146     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8147     SetEvent(hevent);
8148
8149     while (GetMessage(&msg, 0, 0, 0))
8150     {
8151         TranslateMessage(&msg);
8152         DispatchMessage(&msg);
8153     }
8154     return 0;
8155 }
8156
8157 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8158 {
8159     HWND hwnd;
8160     MSG msg;
8161     HANDLE hevent = *(HANDLE *)param;
8162
8163     flush_sequence();
8164     /* these events should be received only by our new hook proc,
8165      * an old one does not expect an event from another thread.
8166      */
8167
8168     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8169     assert(hwnd);
8170     trace("created thread window %p\n", hwnd);
8171
8172     *(HWND *)param = hwnd;
8173
8174     /* Windows doesn't like when a thread plays games with the focus,
8175        that leads to all kinds of misbehaviours and failures to activate
8176        a window. So, better keep next lines commented out.
8177     SetFocus(0);
8178     SetFocus(hwnd);*/
8179
8180     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8181     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8182
8183     SetEvent(hevent);
8184
8185     while (GetMessage(&msg, 0, 0, 0))
8186     {
8187         TranslateMessage(&msg);
8188         DispatchMessage(&msg);
8189     }
8190     return 0;
8191 }
8192
8193 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8194 {
8195     HWND hwnd;
8196     MSG msg;
8197     HANDLE hevent = *(HANDLE *)param;
8198
8199     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8200     assert(hwnd);
8201     trace("created thread window %p\n", hwnd);
8202
8203     *(HWND *)param = hwnd;
8204
8205     flush_sequence();
8206
8207     /* Windows doesn't like when a thread plays games with the focus,
8208      * that leads to all kinds of misbehaviours and failures to activate
8209      * a window. So, better don't generate a mouse click message below.
8210      */
8211     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8212     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8213     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8214
8215     SetEvent(hevent);
8216     while (GetMessage(&msg, 0, 0, 0))
8217     {
8218         TranslateMessage(&msg);
8219         DispatchMessage(&msg);
8220     }
8221     return 0;
8222 }
8223
8224 static void test_winevents(void)
8225 {
8226     BOOL ret;
8227     MSG msg;
8228     HWND hwnd, hwnd2;
8229     UINT i;
8230     HANDLE hthread, hevent;
8231     DWORD tid;
8232     HWINEVENTHOOK hhook;
8233     const struct message *events = WmWinEventsSeq;
8234
8235     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8236                            WS_OVERLAPPEDWINDOW,
8237                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8238                            NULL, NULL, 0);
8239     assert(hwnd);
8240
8241     /****** start of global hook test *************/
8242     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8243     if (!hCBT_global_hook)
8244     {
8245         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8246         skip( "cannot set global hook\n" );
8247         return;
8248     }
8249
8250     hevent = CreateEventA(NULL, 0, 0, NULL);
8251     assert(hevent);
8252     hwnd2 = hevent;
8253
8254     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8255     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8256
8257     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8258
8259     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8260
8261     flush_sequence();
8262     /* this one should be received only by old hook proc */
8263     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8264     /* this one should be received only by old hook proc */
8265     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8266
8267     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8268
8269     ret = UnhookWindowsHookEx(hCBT_global_hook);
8270     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8271
8272     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8273     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8274     CloseHandle(hthread);
8275     CloseHandle(hevent);
8276     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8277     /****** end of global hook test *************/
8278
8279     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8280     {
8281         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8282         return;
8283     }
8284
8285     flush_sequence();
8286
8287     if (0)
8288     {
8289     /* this test doesn't pass under Win9x */
8290     /* win2k ignores events with hwnd == 0 */
8291     SetLastError(0xdeadbeef);
8292     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8293     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8294        GetLastError() == 0xdeadbeef, /* Win9x */
8295        "unexpected error %d\n", GetLastError());
8296     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8297     }
8298
8299     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8300         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8301
8302     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8303
8304     /****** start of event filtering test *************/
8305     hhook = pSetWinEventHook(
8306         EVENT_OBJECT_SHOW, /* 0x8002 */
8307         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8308         GetModuleHandleA(0), win_event_global_hook_proc,
8309         GetCurrentProcessId(), 0,
8310         WINEVENT_INCONTEXT);
8311     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8312
8313     hevent = CreateEventA(NULL, 0, 0, NULL);
8314     assert(hevent);
8315     hwnd2 = hevent;
8316
8317     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8318     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8319
8320     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8321
8322     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8323
8324     flush_sequence();
8325     /* this one should be received only by old hook proc */
8326     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8327     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8328     /* this one should be received only by old hook proc */
8329     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8330
8331     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8332
8333     ret = pUnhookWinEvent(hhook);
8334     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8335
8336     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8337     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8338     CloseHandle(hthread);
8339     CloseHandle(hevent);
8340     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8341     /****** end of event filtering test *************/
8342
8343     /****** start of out of context event test *************/
8344     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8345         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8346         WINEVENT_OUTOFCONTEXT);
8347     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8348
8349     hevent = CreateEventA(NULL, 0, 0, NULL);
8350     assert(hevent);
8351     hwnd2 = hevent;
8352
8353     flush_sequence();
8354
8355     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8356     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8357
8358     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8359
8360     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8361     /* process pending winevent messages */
8362     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8363     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8364
8365     flush_sequence();
8366     /* this one should be received only by old hook proc */
8367     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8368     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8369     /* this one should be received only by old hook proc */
8370     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8371
8372     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8373     /* process pending winevent messages */
8374     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8375     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8376
8377     ret = pUnhookWinEvent(hhook);
8378     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8379
8380     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8381     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8382     CloseHandle(hthread);
8383     CloseHandle(hevent);
8384     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8385     /****** end of out of context event test *************/
8386
8387     /****** start of MOUSE_LL hook test *************/
8388     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8389     /* WH_MOUSE_LL is not supported on Win9x platforms */
8390     if (!hCBT_global_hook)
8391     {
8392         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8393         goto skip_mouse_ll_hook_test;
8394     }
8395
8396     hevent = CreateEventA(NULL, 0, 0, NULL);
8397     assert(hevent);
8398     hwnd2 = hevent;
8399
8400     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8401     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8402
8403     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8404         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8405
8406     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8407     flush_sequence();
8408
8409     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8410     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8411     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8412
8413     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8414
8415     ret = UnhookWindowsHookEx(hCBT_global_hook);
8416     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8417
8418     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8419     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8420     CloseHandle(hthread);
8421     CloseHandle(hevent);
8422     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8423     /****** end of MOUSE_LL hook test *************/
8424 skip_mouse_ll_hook_test:
8425
8426     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8427 }
8428
8429 static void test_set_hook(void)
8430 {
8431     BOOL ret;
8432     HHOOK hhook;
8433     HWINEVENTHOOK hwinevent_hook;
8434
8435     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8436     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8437     UnhookWindowsHookEx(hhook);
8438
8439     if (0)
8440     {
8441     /* this test doesn't pass under Win9x: BUG! */
8442     SetLastError(0xdeadbeef);
8443     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8444     ok(!hhook, "global hook requires hModule != 0\n");
8445     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8446     }
8447
8448     SetLastError(0xdeadbeef);
8449     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8450     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8451     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8452        GetLastError() == 0xdeadbeef, /* Win9x */
8453        "unexpected error %d\n", GetLastError());
8454
8455     SetLastError(0xdeadbeef);
8456     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8457     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8458        GetLastError() == 0xdeadbeef, /* Win9x */
8459        "unexpected error %d\n", GetLastError());
8460
8461     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8462
8463     /* even process local incontext hooks require hmodule */
8464     SetLastError(0xdeadbeef);
8465     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8466         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8467     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8468     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8469        GetLastError() == 0xdeadbeef, /* Win9x */
8470        "unexpected error %d\n", GetLastError());
8471
8472     /* even thread local incontext hooks require hmodule */
8473     SetLastError(0xdeadbeef);
8474     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8475         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8476     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8477     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8478        GetLastError() == 0xdeadbeef, /* Win9x */
8479        "unexpected error %d\n", GetLastError());
8480
8481     if (0)
8482     {
8483     /* these 3 tests don't pass under Win9x */
8484     SetLastError(0xdeadbeef);
8485     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8486         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8487     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8488     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8489
8490     SetLastError(0xdeadbeef);
8491     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8492         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8493     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8494     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8495
8496     SetLastError(0xdeadbeef);
8497     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8498         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8499     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8500     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8501     }
8502
8503     SetLastError(0xdeadbeef);
8504     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8505         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8506     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8507     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8508     ret = pUnhookWinEvent(hwinevent_hook);
8509     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8510
8511 todo_wine {
8512     /* This call succeeds under win2k SP4, but fails under Wine.
8513        Does win2k test/use passed process id? */
8514     SetLastError(0xdeadbeef);
8515     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8516         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8517     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8518     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8519     ret = pUnhookWinEvent(hwinevent_hook);
8520     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8521 }
8522
8523     SetLastError(0xdeadbeef);
8524     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8525     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8526         GetLastError() == 0xdeadbeef, /* Win9x */
8527         "unexpected error %d\n", GetLastError());
8528 }
8529
8530 static const struct message ScrollWindowPaint1[] = {
8531     { WM_PAINT, sent },
8532     { WM_ERASEBKGND, sent|beginpaint },
8533     { WM_GETTEXTLENGTH, sent|optional },
8534     { WM_PAINT, sent|optional },
8535     { WM_NCPAINT, sent|beginpaint|optional },
8536     { WM_GETTEXT, sent|beginpaint|optional },
8537     { WM_GETTEXT, sent|beginpaint|optional },
8538     { WM_GETTEXT, sent|beginpaint|optional },
8539     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8540     { WM_ERASEBKGND, sent|beginpaint|optional },
8541     { 0 }
8542 };
8543
8544 static const struct message ScrollWindowPaint2[] = {
8545     { WM_PAINT, sent },
8546     { 0 }
8547 };
8548
8549 static void test_scrollwindowex(void)
8550 {
8551     HWND hwnd, hchild;
8552     RECT rect={0,0,130,130};
8553
8554     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8555             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8556             100, 100, 200, 200, 0, 0, 0, NULL);
8557     ok (hwnd != 0, "Failed to create overlapped window\n");
8558     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8559             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8560             10, 10, 150, 150, hwnd, 0, 0, NULL);
8561     ok (hchild != 0, "Failed to create child\n");
8562     UpdateWindow(hwnd);
8563     flush_events();
8564     flush_sequence();
8565
8566     /* scroll without the child window */
8567     trace("start scroll\n");
8568     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8569             SW_ERASE|SW_INVALIDATE);
8570     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8571     trace("end scroll\n");
8572     flush_sequence();
8573     flush_events();
8574     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8575     flush_events();
8576     flush_sequence();
8577
8578     /* Now without the SW_ERASE flag */
8579     trace("start scroll\n");
8580     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8581     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8582     trace("end scroll\n");
8583     flush_sequence();
8584     flush_events();
8585     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8586     flush_events();
8587     flush_sequence();
8588
8589     /* now scroll the child window as well */
8590     trace("start scroll\n");
8591     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8592             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8593     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8594     /* windows sometimes a WM_MOVE */
8595     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8596     trace("end scroll\n");
8597     flush_sequence();
8598     flush_events();
8599     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8600     flush_events();
8601     flush_sequence();
8602
8603     /* now scroll with ScrollWindow() */
8604     trace("start scroll with ScrollWindow\n");
8605     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8606     trace("end scroll\n");
8607     flush_sequence();
8608     flush_events();
8609     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8610
8611     ok(DestroyWindow(hchild), "failed to destroy window\n");
8612     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8613     flush_sequence();
8614 }
8615
8616 static const struct message destroy_window_with_children[] = {
8617     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8618     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8619     { 0x0090, sent|optional },
8620     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8621     { 0x0090, sent|optional },
8622     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8623     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8624     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8625     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8626     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8627     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8628     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8629     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8630     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8631     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8632     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8633     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8634     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8635     { 0 }
8636 };
8637
8638 static void test_DestroyWindow(void)
8639 {
8640     BOOL ret;
8641     HWND parent, child1, child2, child3, child4, test;
8642     UINT_PTR child_id = WND_CHILD_ID + 1;
8643
8644     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8645                              100, 100, 200, 200, 0, 0, 0, NULL);
8646     assert(parent != 0);
8647     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8648                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8649     assert(child1 != 0);
8650     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8651                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8652     assert(child2 != 0);
8653     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8654                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8655     assert(child3 != 0);
8656     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8657                              0, 0, 50, 50, parent, 0, 0, NULL);
8658     assert(child4 != 0);
8659
8660     /* test owner/parent of child2 */
8661     test = GetParent(child2);
8662     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8663     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8664     if(pGetAncestor) {
8665         test = pGetAncestor(child2, GA_PARENT);
8666         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8667     }
8668     test = GetWindow(child2, GW_OWNER);
8669     ok(!test, "wrong owner %p\n", test);
8670
8671     test = SetParent(child2, parent);
8672     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8673
8674     /* test owner/parent of the parent */
8675     test = GetParent(parent);
8676     ok(!test, "wrong parent %p\n", test);
8677     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8678     if(pGetAncestor) {
8679         test = pGetAncestor(parent, GA_PARENT);
8680         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8681     }
8682     test = GetWindow(parent, GW_OWNER);
8683     ok(!test, "wrong owner %p\n", test);
8684
8685     /* test owner/parent of child1 */
8686     test = GetParent(child1);
8687     ok(test == parent, "wrong parent %p\n", test);
8688     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8689     if(pGetAncestor) {
8690         test = pGetAncestor(child1, GA_PARENT);
8691         ok(test == parent, "wrong parent %p\n", test);
8692     }
8693     test = GetWindow(child1, GW_OWNER);
8694     ok(!test, "wrong owner %p\n", test);
8695
8696     /* test owner/parent of child2 */
8697     test = GetParent(child2);
8698     ok(test == parent, "wrong parent %p\n", test);
8699     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8700     if(pGetAncestor) {
8701         test = pGetAncestor(child2, GA_PARENT);
8702         ok(test == parent, "wrong parent %p\n", test);
8703     }
8704     test = GetWindow(child2, GW_OWNER);
8705     ok(!test, "wrong owner %p\n", test);
8706
8707     /* test owner/parent of child3 */
8708     test = GetParent(child3);
8709     ok(test == child1, "wrong parent %p\n", test);
8710     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8711     if(pGetAncestor) {
8712         test = pGetAncestor(child3, GA_PARENT);
8713         ok(test == child1, "wrong parent %p\n", test);
8714     }
8715     test = GetWindow(child3, GW_OWNER);
8716     ok(!test, "wrong owner %p\n", test);
8717
8718     /* test owner/parent of child4 */
8719     test = GetParent(child4);
8720     ok(test == parent, "wrong parent %p\n", test);
8721     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8722     if(pGetAncestor) {
8723         test = pGetAncestor(child4, GA_PARENT);
8724         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8725     }
8726     test = GetWindow(child4, GW_OWNER);
8727     ok(test == parent, "wrong owner %p\n", test);
8728
8729     flush_sequence();
8730
8731     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8732            parent, child1, child2, child3, child4);
8733
8734     SetCapture(child4);
8735     test = GetCapture();
8736     ok(test == child4, "wrong capture window %p\n", test);
8737
8738     test_DestroyWindow_flag = TRUE;
8739     ret = DestroyWindow(parent);
8740     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8741     test_DestroyWindow_flag = FALSE;
8742     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8743
8744     ok(!IsWindow(parent), "parent still exists\n");
8745     ok(!IsWindow(child1), "child1 still exists\n");
8746     ok(!IsWindow(child2), "child2 still exists\n");
8747     ok(!IsWindow(child3), "child3 still exists\n");
8748     ok(!IsWindow(child4), "child4 still exists\n");
8749
8750     test = GetCapture();
8751     ok(!test, "wrong capture window %p\n", test);
8752 }
8753
8754
8755 static const struct message WmDispatchPaint[] = {
8756     { WM_NCPAINT, sent },
8757     { WM_GETTEXT, sent|defwinproc|optional },
8758     { WM_GETTEXT, sent|defwinproc|optional },
8759     { WM_ERASEBKGND, sent },
8760     { 0 }
8761 };
8762
8763 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8764 {
8765     if (message == WM_PAINT) return 0;
8766     return MsgCheckProcA( hwnd, message, wParam, lParam );
8767 }
8768
8769 static void test_DispatchMessage(void)
8770 {
8771     RECT rect;
8772     MSG msg;
8773     int count;
8774     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8775                                100, 100, 200, 200, 0, 0, 0, NULL);
8776     ShowWindow( hwnd, SW_SHOW );
8777     UpdateWindow( hwnd );
8778     flush_events();
8779     flush_sequence();
8780     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8781
8782     SetRect( &rect, -5, -5, 5, 5 );
8783     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8784     count = 0;
8785     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8786     {
8787         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8788         else
8789         {
8790             flush_sequence();
8791             DispatchMessage( &msg );
8792             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8793             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8794             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8795             if (++count > 10) break;
8796         }
8797     }
8798     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8799
8800     trace("now without DispatchMessage\n");
8801     flush_sequence();
8802     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8803     count = 0;
8804     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8805     {
8806         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8807         else
8808         {
8809             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8810             flush_sequence();
8811             /* this will send WM_NCCPAINT just like DispatchMessage does */
8812             GetUpdateRgn( hwnd, hrgn, TRUE );
8813             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8814             DeleteObject( hrgn );
8815             GetClientRect( hwnd, &rect );
8816             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8817             ok( !count, "Got multiple WM_PAINTs\n" );
8818             if (++count > 10) break;
8819         }
8820     }
8821     DestroyWindow(hwnd);
8822 }
8823
8824
8825 static const struct message WmUser[] = {
8826     { WM_USER, sent },
8827     { 0 }
8828 };
8829
8830 struct sendmsg_info
8831 {
8832     HWND  hwnd;
8833     DWORD timeout;
8834     DWORD ret;
8835 };
8836
8837 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8838 {
8839     struct sendmsg_info *info = arg;
8840     SetLastError( 0xdeadbeef );
8841     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8842     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8843                         broken(GetLastError() == 0),  /* win9x */
8844                         "unexpected error %d\n", GetLastError());
8845     return 0;
8846 }
8847
8848 static void wait_for_thread( HANDLE thread )
8849 {
8850     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8851     {
8852         MSG msg;
8853         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8854     }
8855 }
8856
8857 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8858 {
8859     if (message == WM_USER) Sleep(200);
8860     return MsgCheckProcA( hwnd, message, wParam, lParam );
8861 }
8862
8863 static void test_SendMessageTimeout(void)
8864 {
8865     HANDLE thread;
8866     struct sendmsg_info info;
8867     DWORD tid;
8868     BOOL is_win9x;
8869
8870     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8871                                100, 100, 200, 200, 0, 0, 0, NULL);
8872     flush_events();
8873     flush_sequence();
8874
8875     info.timeout = 1000;
8876     info.ret = 0xdeadbeef;
8877     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8878     wait_for_thread( thread );
8879     CloseHandle( thread );
8880     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8881     ok_sequence( WmUser, "WmUser", FALSE );
8882
8883     info.timeout = 1;
8884     info.ret = 0xdeadbeef;
8885     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8886     Sleep(100);  /* SendMessageTimeout should time out here */
8887     wait_for_thread( thread );
8888     CloseHandle( thread );
8889     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8890     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8891
8892     /* 0 means infinite timeout (but not on win9x) */
8893     info.timeout = 0;
8894     info.ret = 0xdeadbeef;
8895     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8896     Sleep(100);
8897     wait_for_thread( thread );
8898     CloseHandle( thread );
8899     is_win9x = !info.ret;
8900     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8901     else ok_sequence( WmUser, "WmUser", FALSE );
8902
8903     /* timeout is treated as signed despite the prototype (but not on win9x) */
8904     info.timeout = 0x7fffffff;
8905     info.ret = 0xdeadbeef;
8906     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8907     Sleep(100);
8908     wait_for_thread( thread );
8909     CloseHandle( thread );
8910     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8911     ok_sequence( WmUser, "WmUser", FALSE );
8912
8913     info.timeout = 0x80000000;
8914     info.ret = 0xdeadbeef;
8915     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8916     Sleep(100);
8917     wait_for_thread( thread );
8918     CloseHandle( thread );
8919     if (is_win9x)
8920     {
8921         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8922         ok_sequence( WmUser, "WmUser", FALSE );
8923     }
8924     else
8925     {
8926         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8927         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8928     }
8929
8930     /* now check for timeout during message processing */
8931     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8932     info.timeout = 100;
8933     info.ret = 0xdeadbeef;
8934     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8935     wait_for_thread( thread );
8936     CloseHandle( thread );
8937     /* we should time out but still get the message */
8938     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8939     ok_sequence( WmUser, "WmUser", FALSE );
8940
8941     DestroyWindow( info.hwnd );
8942 }
8943
8944
8945 /****************** edit message test *************************/
8946 #define ID_EDIT 0x1234
8947 static const struct message sl_edit_setfocus[] =
8948 {
8949     { HCBT_SETFOCUS, hook },
8950     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8951     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8952     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8953     { WM_SETFOCUS, sent|wparam, 0 },
8954     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8955     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8956     { WM_CTLCOLOREDIT, sent|parent },
8957     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8958     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8959     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8960     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8961     { 0 }
8962 };
8963 static const struct message ml_edit_setfocus[] =
8964 {
8965     { HCBT_SETFOCUS, hook },
8966     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8967     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8968     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8969     { WM_SETFOCUS, sent|wparam, 0 },
8970     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8971     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8972     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8973     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8974     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8975     { 0 }
8976 };
8977 static const struct message sl_edit_killfocus[] =
8978 {
8979     { HCBT_SETFOCUS, hook },
8980     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8981     { WM_KILLFOCUS, sent|wparam, 0 },
8982     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8983     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8984     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8985     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8986     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8987     { 0 }
8988 };
8989 static const struct message sl_edit_lbutton_dblclk[] =
8990 {
8991     { WM_LBUTTONDBLCLK, sent },
8992     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8993     { 0 }
8994 };
8995 static const struct message sl_edit_lbutton_down[] =
8996 {
8997     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8998     { HCBT_SETFOCUS, hook },
8999     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9000     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9001     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9002     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9003     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9004     { WM_CTLCOLOREDIT, sent|parent },
9005     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9006     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9007     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9008     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9009     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9010     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9011     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9012     { WM_CTLCOLOREDIT, sent|parent|optional },
9013     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9014     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9015     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9016     { 0 }
9017 };
9018 static const struct message ml_edit_lbutton_down[] =
9019 {
9020     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9021     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9022     { HCBT_SETFOCUS, hook },
9023     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9024     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9025     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9026     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9027     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9028     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9029     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9030     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9031     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9032     { 0 }
9033 };
9034 static const struct message sl_edit_lbutton_up[] =
9035 {
9036     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9037     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9038     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9039     { WM_CAPTURECHANGED, sent|defwinproc },
9040     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9041     { 0 }
9042 };
9043 static const struct message ml_edit_lbutton_up[] =
9044 {
9045     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9046     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9047     { WM_CAPTURECHANGED, sent|defwinproc },
9048     { 0 }
9049 };
9050
9051 static WNDPROC old_edit_proc;
9052
9053 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9054 {
9055     static LONG defwndproc_counter = 0;
9056     LRESULT ret;
9057     struct recvd_message msg;
9058
9059     if (ignore_message( message )) return 0;
9060
9061     msg.hwnd = hwnd;
9062     msg.message = message;
9063     msg.flags = sent|wparam|lparam;
9064     if (defwndproc_counter) msg.flags |= defwinproc;
9065     msg.wParam = wParam;
9066     msg.lParam = lParam;
9067     msg.descr = "edit";
9068     add_message(&msg);
9069
9070     defwndproc_counter++;
9071     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9072     defwndproc_counter--;
9073
9074     return ret;
9075 }
9076
9077 static void subclass_edit(void)
9078 {
9079     WNDCLASSA cls;
9080
9081     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9082
9083     old_edit_proc = cls.lpfnWndProc;
9084
9085     cls.hInstance = GetModuleHandle(0);
9086     cls.lpfnWndProc = edit_hook_proc;
9087     cls.lpszClassName = "my_edit_class";
9088     UnregisterClass(cls.lpszClassName, cls.hInstance);
9089     if (!RegisterClassA(&cls)) assert(0);
9090 }
9091
9092 static void test_edit_messages(void)
9093 {
9094     HWND hwnd, parent;
9095     DWORD dlg_code;
9096
9097     subclass_edit();
9098     log_all_parent_messages++;
9099
9100     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9101                              100, 100, 200, 200, 0, 0, 0, NULL);
9102     ok (parent != 0, "Failed to create parent window\n");
9103
9104     /* test single line edit */
9105     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9106                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9107     ok(hwnd != 0, "Failed to create edit window\n");
9108
9109     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9110     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9111
9112     ShowWindow(hwnd, SW_SHOW);
9113     UpdateWindow(hwnd);
9114     SetFocus(0);
9115     flush_sequence();
9116
9117     SetFocus(hwnd);
9118     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9119
9120     SetFocus(0);
9121     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9122
9123     SetFocus(0);
9124     ReleaseCapture();
9125     flush_sequence();
9126
9127     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9128     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9129
9130     SetFocus(0);
9131     ReleaseCapture();
9132     flush_sequence();
9133
9134     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9135     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9136
9137     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9138     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9139
9140     DestroyWindow(hwnd);
9141
9142     /* test multiline edit */
9143     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9144                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9145     ok(hwnd != 0, "Failed to create edit window\n");
9146
9147     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9148     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9149        "wrong dlg_code %08x\n", dlg_code);
9150
9151     ShowWindow(hwnd, SW_SHOW);
9152     UpdateWindow(hwnd);
9153     SetFocus(0);
9154     flush_sequence();
9155
9156     SetFocus(hwnd);
9157     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9158
9159     SetFocus(0);
9160     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9161
9162     SetFocus(0);
9163     ReleaseCapture();
9164     flush_sequence();
9165
9166     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9167     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9168
9169     SetFocus(0);
9170     ReleaseCapture();
9171     flush_sequence();
9172
9173     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9174     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9175
9176     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9177     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9178
9179     DestroyWindow(hwnd);
9180     DestroyWindow(parent);
9181
9182     log_all_parent_messages--;
9183 }
9184
9185 /**************************** End of Edit test ******************************/
9186
9187 static const struct message WmKeyDownSkippedSeq[] =
9188 {
9189     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9190     { 0 }
9191 };
9192 static const struct message WmKeyDownWasDownSkippedSeq[] =
9193 {
9194     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9195     { 0 }
9196 };
9197 static const struct message WmKeyUpSkippedSeq[] =
9198 {
9199     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9200     { 0 }
9201 };
9202 static const struct message WmUserKeyUpSkippedSeq[] =
9203 {
9204     { WM_USER, sent },
9205     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9206     { 0 }
9207 };
9208
9209 #define EV_STOP 0
9210 #define EV_SENDMSG 1
9211 #define EV_ACK 2
9212
9213 struct peekmsg_info
9214 {
9215     HWND  hwnd;
9216     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9217 };
9218
9219 static DWORD CALLBACK send_msg_thread_2(void *param)
9220 {
9221     DWORD ret;
9222     struct peekmsg_info *info = param;
9223
9224     trace("thread: looping\n");
9225     SetEvent(info->hevent[EV_ACK]);
9226
9227     while (1)
9228     {
9229         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9230
9231         switch (ret)
9232         {
9233         case WAIT_OBJECT_0 + EV_STOP:
9234             trace("thread: exiting\n");
9235             return 0;
9236
9237         case WAIT_OBJECT_0 + EV_SENDMSG:
9238             trace("thread: sending message\n");
9239             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9240                 "SendNotifyMessageA failed error %u\n", GetLastError());
9241             SetEvent(info->hevent[EV_ACK]);
9242             break;
9243
9244         default:
9245             trace("unexpected return: %04x\n", ret);
9246             assert(0);
9247             break;
9248         }
9249     }
9250     return 0;
9251 }
9252
9253 static void test_PeekMessage(void)
9254 {
9255     MSG msg;
9256     HANDLE hthread;
9257     DWORD tid, qstatus;
9258     UINT qs_all_input = QS_ALLINPUT;
9259     UINT qs_input = QS_INPUT;
9260     BOOL ret;
9261     struct peekmsg_info info;
9262
9263     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9264                               100, 100, 200, 200, 0, 0, 0, NULL);
9265     assert(info.hwnd);
9266     ShowWindow(info.hwnd, SW_SHOW);
9267     UpdateWindow(info.hwnd);
9268     SetFocus(info.hwnd);
9269
9270     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9271     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9272     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9273
9274     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9275     WaitForSingleObject(info.hevent[EV_ACK], 10000);
9276
9277     flush_events();
9278     flush_sequence();
9279
9280     SetLastError(0xdeadbeef);
9281     qstatus = GetQueueStatus(qs_all_input);
9282     if (GetLastError() == ERROR_INVALID_FLAGS)
9283     {
9284         trace("QS_RAWINPUT not supported on this platform\n");
9285         qs_all_input &= ~QS_RAWINPUT;
9286         qs_input &= ~QS_RAWINPUT;
9287     }
9288     if (qstatus & QS_POSTMESSAGE)
9289     {
9290         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9291         qstatus = GetQueueStatus(qs_all_input);
9292     }
9293     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9294
9295     trace("signalling to send message\n");
9296     SetEvent(info.hevent[EV_SENDMSG]);
9297     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9298
9299     /* pass invalid QS_xxxx flags */
9300     SetLastError(0xdeadbeef);
9301     qstatus = GetQueueStatus(0xffffffff);
9302     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9303     if (!qstatus)
9304     {
9305         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9306         qstatus = GetQueueStatus(qs_all_input);
9307     }
9308     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9309     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9310        "wrong qstatus %08x\n", qstatus);
9311
9312     msg.message = 0;
9313     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9314     ok(!ret,
9315        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9316         msg.message);
9317     ok_sequence(WmUser, "WmUser", FALSE);
9318
9319     qstatus = GetQueueStatus(qs_all_input);
9320     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9321
9322     keybd_event('N', 0, 0, 0);
9323     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9324     qstatus = GetQueueStatus(qs_all_input);
9325     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9326     {
9327         skip( "queuing key events not supported\n" );
9328         goto done;
9329     }
9330     ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9331        /* keybd_event seems to trigger a sent message on NT4 */
9332        qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9333        "wrong qstatus %08x\n", qstatus);
9334
9335     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9336     qstatus = GetQueueStatus(qs_all_input);
9337     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9338        qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9339        "wrong qstatus %08x\n", qstatus);
9340
9341     InvalidateRect(info.hwnd, NULL, FALSE);
9342     qstatus = GetQueueStatus(qs_all_input);
9343     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9344        qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9345        "wrong qstatus %08x\n", qstatus);
9346
9347     trace("signalling to send message\n");
9348     SetEvent(info.hevent[EV_SENDMSG]);
9349     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9350
9351     qstatus = GetQueueStatus(qs_all_input);
9352     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9353        "wrong qstatus %08x\n", qstatus);
9354
9355     msg.message = 0;
9356     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9357     if (ret && msg.message == WM_CHAR)
9358     {
9359         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9360         goto done;
9361     }
9362     ok(!ret,
9363        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9364         msg.message);
9365     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9366     {
9367         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9368         goto done;
9369     }
9370     ok_sequence(WmUser, "WmUser", FALSE);
9371
9372     qstatus = GetQueueStatus(qs_all_input);
9373     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9374        "wrong qstatus %08x\n", qstatus);
9375
9376     trace("signalling to send message\n");
9377     SetEvent(info.hevent[EV_SENDMSG]);
9378     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9379
9380     qstatus = GetQueueStatus(qs_all_input);
9381     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9382        "wrong qstatus %08x\n", qstatus);
9383
9384     msg.message = 0;
9385     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9386     ok(!ret,
9387        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9388         msg.message);
9389     ok_sequence(WmUser, "WmUser", FALSE);
9390
9391     qstatus = GetQueueStatus(qs_all_input);
9392     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9393        "wrong qstatus %08x\n", qstatus);
9394
9395     msg.message = 0;
9396     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9397     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9398        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9399        ret, msg.message, msg.wParam);
9400     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9401
9402     qstatus = GetQueueStatus(qs_all_input);
9403     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9404        "wrong qstatus %08x\n", qstatus);
9405
9406     msg.message = 0;
9407     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9408     ok(!ret,
9409        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9410         msg.message);
9411     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9412
9413     qstatus = GetQueueStatus(qs_all_input);
9414     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9415        "wrong qstatus %08x\n", qstatus);
9416
9417     msg.message = 0;
9418     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9419     ok(ret && msg.message == WM_PAINT,
9420        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9421     DispatchMessageA(&msg);
9422     ok_sequence(WmPaint, "WmPaint", FALSE);
9423
9424     qstatus = GetQueueStatus(qs_all_input);
9425     ok(qstatus == MAKELONG(0, QS_KEY),
9426        "wrong qstatus %08x\n", qstatus);
9427
9428     msg.message = 0;
9429     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9430     ok(!ret,
9431        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9432         msg.message);
9433     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9434
9435     qstatus = GetQueueStatus(qs_all_input);
9436     ok(qstatus == MAKELONG(0, QS_KEY),
9437        "wrong qstatus %08x\n", qstatus);
9438
9439     trace("signalling to send message\n");
9440     SetEvent(info.hevent[EV_SENDMSG]);
9441     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9442
9443     qstatus = GetQueueStatus(qs_all_input);
9444     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9445        "wrong qstatus %08x\n", qstatus);
9446
9447     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9448
9449     qstatus = GetQueueStatus(qs_all_input);
9450     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9451        "wrong qstatus %08x\n", qstatus);
9452
9453     msg.message = 0;
9454     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9455     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9456        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9457        ret, msg.message, msg.wParam);
9458     ok_sequence(WmUser, "WmUser", FALSE);
9459
9460     qstatus = GetQueueStatus(qs_all_input);
9461     ok(qstatus == MAKELONG(0, QS_KEY),
9462        "wrong qstatus %08x\n", qstatus);
9463
9464     msg.message = 0;
9465     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9466     ok(!ret,
9467        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9468         msg.message);
9469     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9470
9471     qstatus = GetQueueStatus(qs_all_input);
9472     ok(qstatus == MAKELONG(0, QS_KEY),
9473        "wrong qstatus %08x\n", qstatus);
9474
9475     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9476
9477     qstatus = GetQueueStatus(qs_all_input);
9478     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9479        "wrong qstatus %08x\n", qstatus);
9480
9481     trace("signalling to send message\n");
9482     SetEvent(info.hevent[EV_SENDMSG]);
9483     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9484
9485     qstatus = GetQueueStatus(qs_all_input);
9486     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9487        "wrong qstatus %08x\n", qstatus);
9488
9489     msg.message = 0;
9490     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9491     ok(!ret,
9492        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9493         msg.message);
9494     ok_sequence(WmUser, "WmUser", FALSE);
9495
9496     qstatus = GetQueueStatus(qs_all_input);
9497     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9498        "wrong qstatus %08x\n", qstatus);
9499
9500     msg.message = 0;
9501     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9502         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9503     else /* workaround for a missing QS_RAWINPUT support */
9504         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9505     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9506        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9507        ret, msg.message, msg.wParam);
9508     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9509
9510     qstatus = GetQueueStatus(qs_all_input);
9511     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9512        "wrong qstatus %08x\n", qstatus);
9513
9514     msg.message = 0;
9515     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9516         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9517     else /* workaround for a missing QS_RAWINPUT support */
9518         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9519     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9520        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9521        ret, msg.message, msg.wParam);
9522     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9523
9524     qstatus = GetQueueStatus(qs_all_input);
9525     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9526        "wrong qstatus %08x\n", qstatus);
9527
9528     msg.message = 0;
9529     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9530     ok(!ret,
9531        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9532         msg.message);
9533     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9534
9535     qstatus = GetQueueStatus(qs_all_input);
9536     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9537        "wrong qstatus %08x\n", qstatus);
9538
9539     msg.message = 0;
9540     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9541     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9542        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9543        ret, msg.message, msg.wParam);
9544     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9545
9546     qstatus = GetQueueStatus(qs_all_input);
9547     ok(qstatus == 0,
9548        "wrong qstatus %08x\n", qstatus);
9549
9550     msg.message = 0;
9551     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9552     ok(!ret,
9553        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9554         msg.message);
9555     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9556
9557     qstatus = GetQueueStatus(qs_all_input);
9558     ok(qstatus == 0,
9559        "wrong qstatus %08x\n", qstatus);
9560
9561     /* test whether presence of the quit flag in the queue affects
9562      * the queue state
9563      */
9564     PostQuitMessage(0x1234abcd);
9565
9566     qstatus = GetQueueStatus(qs_all_input);
9567     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9568        "wrong qstatus %08x\n", qstatus);
9569
9570     PostMessageA(info.hwnd, WM_USER, 0, 0);
9571
9572     qstatus = GetQueueStatus(qs_all_input);
9573     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9574        "wrong qstatus %08x\n", qstatus);
9575
9576     msg.message = 0;
9577     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9578     ok(ret && msg.message == WM_USER,
9579        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9580     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9581
9582     qstatus = GetQueueStatus(qs_all_input);
9583     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9584        "wrong qstatus %08x\n", qstatus);
9585
9586     msg.message = 0;
9587     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9588     ok(ret && msg.message == WM_QUIT,
9589        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9590     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9591     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9592     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9593
9594     qstatus = GetQueueStatus(qs_all_input);
9595 todo_wine {
9596     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9597        "wrong qstatus %08x\n", qstatus);
9598 }
9599
9600     msg.message = 0;
9601     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9602     ok(!ret,
9603        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9604         msg.message);
9605     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9606
9607     qstatus = GetQueueStatus(qs_all_input);
9608     ok(qstatus == 0,
9609        "wrong qstatus %08x\n", qstatus);
9610
9611     /* some GetMessage tests */
9612
9613     keybd_event('N', 0, 0, 0);
9614     qstatus = GetQueueStatus(qs_all_input);
9615     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9616
9617     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9618     qstatus = GetQueueStatus(qs_all_input);
9619     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9620
9621     if (qstatus)
9622     {
9623         ret = GetMessageA( &msg, 0, 0, 0 );
9624         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9625            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9626            ret, msg.message, msg.wParam);
9627         qstatus = GetQueueStatus(qs_all_input);
9628         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9629     }
9630
9631     if (qstatus)
9632     {
9633         ret = GetMessageA( &msg, 0, 0, 0 );
9634         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9635            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9636            ret, msg.message, msg.wParam);
9637         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9638         qstatus = GetQueueStatus(qs_all_input);
9639         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9640     }
9641
9642     keybd_event('N', 0, 0, 0);
9643     qstatus = GetQueueStatus(qs_all_input);
9644     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9645
9646     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9647     qstatus = GetQueueStatus(qs_all_input);
9648     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9649
9650     if (qstatus & (QS_KEY << 16))
9651     {
9652         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9653         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9654            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9655            ret, msg.message, msg.wParam);
9656         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9657         qstatus = GetQueueStatus(qs_all_input);
9658         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9659     }
9660
9661     if (qstatus)
9662     {
9663         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9664         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9665            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9666            ret, msg.message, msg.wParam);
9667         qstatus = GetQueueStatus(qs_all_input);
9668         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9669     }
9670
9671     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9672     qstatus = GetQueueStatus(qs_all_input);
9673     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9674
9675     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9676     qstatus = GetQueueStatus(qs_all_input);
9677     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9678
9679     trace("signalling to send message\n");
9680     SetEvent(info.hevent[EV_SENDMSG]);
9681     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9682     qstatus = GetQueueStatus(qs_all_input);
9683     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9684        "wrong qstatus %08x\n", qstatus);
9685
9686     if (qstatus & (QS_KEY << 16))
9687     {
9688         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9689         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9690            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9691            ret, msg.message, msg.wParam);
9692         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9693         qstatus = GetQueueStatus(qs_all_input);
9694         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9695     }
9696
9697     if (qstatus)
9698     {
9699         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9700         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9701            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9702            ret, msg.message, msg.wParam);
9703         qstatus = GetQueueStatus(qs_all_input);
9704         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9705     }
9706 done:
9707     trace("signalling to exit\n");
9708     SetEvent(info.hevent[EV_STOP]);
9709
9710     WaitForSingleObject(hthread, INFINITE);
9711
9712     CloseHandle(hthread);
9713     CloseHandle(info.hevent[0]);
9714     CloseHandle(info.hevent[1]);
9715     CloseHandle(info.hevent[2]);
9716
9717     DestroyWindow(info.hwnd);
9718 }
9719
9720 static void wait_move_event(HWND hwnd, int x, int y)
9721 {
9722     MSG msg;
9723     DWORD time;
9724     BOOL  ret;
9725     int go = 0;
9726
9727     time = GetTickCount();
9728     while (GetTickCount() - time < 200 && !go) {
9729         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9730         go  = ret && msg.pt.x > x && msg.pt.y > y;
9731         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9732     }
9733 }
9734
9735 #define STEP 5
9736 static void test_PeekMessage2(void)
9737 {
9738     HWND hwnd;
9739     BOOL ret;
9740     MSG msg;
9741     UINT message;
9742     DWORD time1, time2, time3;
9743     int x1, y1, x2, y2, x3, y3;
9744     POINT pos;
9745
9746     time1 = time2 = time3 = 0;
9747     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9748
9749     /* Initialise window and make sure it is ready for events */
9750     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9751                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9752     assert(hwnd);
9753     trace("Window for test_PeekMessage2 %p\n", hwnd);
9754     ShowWindow(hwnd, SW_SHOW);
9755     UpdateWindow(hwnd);
9756     SetFocus(hwnd);
9757     GetCursorPos(&pos);
9758     SetCursorPos(100, 100);
9759     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9760     flush_events();
9761
9762     /* Do initial mousemove, wait until we can see it
9763        and then do our test peek with PM_NOREMOVE. */
9764     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9765     wait_move_event(hwnd, 100-STEP, 100-STEP);
9766
9767     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9768     if (!ret)
9769     {
9770         skip( "queuing mouse events not supported\n" );
9771         goto done;
9772     }
9773     else
9774     {
9775         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9776         message = msg.message;
9777         time1 = msg.time;
9778         x1 = msg.pt.x;
9779         y1 = msg.pt.y;
9780         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9781     }
9782
9783     /* Allow time to advance a bit, and then simulate the user moving their
9784      * mouse around. After that we peek again with PM_NOREMOVE.
9785      * Although the previous mousemove message was never removed, the
9786      * mousemove we now peek should reflect the recent mouse movements
9787      * because the input queue will merge the move events. */
9788     Sleep(100);
9789     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9790     wait_move_event(hwnd, x1, y1);
9791
9792     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9793     ok(ret, "no message available\n");
9794     if (ret) {
9795         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9796         message = msg.message;
9797         time2 = msg.time;
9798         x2 = msg.pt.x;
9799         y2 = msg.pt.y;
9800         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9801         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9802         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9803     }
9804
9805     /* Have another go, to drive the point home */
9806     Sleep(100);
9807     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9808     wait_move_event(hwnd, x2, y2);
9809
9810     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9811     ok(ret, "no message available\n");
9812     if (ret) {
9813         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9814         message = msg.message;
9815         time3 = msg.time;
9816         x3 = msg.pt.x;
9817         y3 = msg.pt.y;
9818         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9819         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9820         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9821     }
9822
9823 done:
9824     DestroyWindow(hwnd);
9825     SetCursorPos(pos.x, pos.y);
9826     flush_events();
9827 }
9828
9829 static void test_quit_message(void)
9830 {
9831     MSG msg;
9832     BOOL ret;
9833
9834     /* test using PostQuitMessage */
9835     flush_events();
9836     PostQuitMessage(0xbeef);
9837
9838     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9839     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9840     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9841     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9842
9843     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9844     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9845
9846     ret = GetMessage(&msg, NULL, 0, 0);
9847     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9848     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9849
9850     /* note: WM_QUIT message received after WM_USER message */
9851     ret = GetMessage(&msg, NULL, 0, 0);
9852     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9853     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9854     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9855
9856     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9857     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9858
9859     /* now test with PostThreadMessage - different behaviour! */
9860     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9861
9862     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9863     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9864     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9865     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9866
9867     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9868     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9869
9870     /* note: we receive the WM_QUIT message first this time */
9871     ret = GetMessage(&msg, NULL, 0, 0);
9872     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9873     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9874     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9875
9876     ret = GetMessage(&msg, NULL, 0, 0);
9877     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9878     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9879 }
9880
9881 static const struct message WmMouseHoverSeq[] = {
9882     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9883     { WM_MOUSEACTIVATE, sent|optional },
9884     { WM_TIMER, sent|optional }, /* XP sends it */
9885     { WM_SYSTIMER, sent },
9886     { WM_MOUSEHOVER, sent|wparam, 0 },
9887     { 0 }
9888 };
9889
9890 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9891 {
9892     MSG msg;
9893     DWORD start_ticks, end_ticks;
9894
9895     start_ticks = GetTickCount();
9896     /* add some deviation (50%) to cover not expected delays */
9897     start_ticks += timeout / 2;
9898
9899     do
9900     {
9901         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9902         {
9903             /* Timer proc messages are not dispatched to the window proc,
9904              * and therefore not logged.
9905              */
9906             if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
9907             {
9908                 struct recvd_message s_msg;
9909
9910                 s_msg.hwnd = msg.hwnd;
9911                 s_msg.message = msg.message;
9912                 s_msg.flags = sent|wparam|lparam;
9913                 s_msg.wParam = msg.wParam;
9914                 s_msg.lParam = msg.lParam;
9915                 s_msg.descr = "msg_loop";
9916                 add_message(&s_msg);
9917             }
9918             DispatchMessage(&msg);
9919         }
9920
9921         end_ticks = GetTickCount();
9922
9923         /* inject WM_MOUSEMOVE to see how it changes tracking */
9924         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9925         {
9926             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9927             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9928
9929             inject_mouse_move = FALSE;
9930         }
9931     } while (start_ticks + timeout >= end_ticks);
9932 }
9933
9934 static void test_TrackMouseEvent(void)
9935 {
9936     TRACKMOUSEEVENT tme;
9937     BOOL ret;
9938     HWND hwnd, hchild;
9939     RECT rc_parent, rc_child;
9940     UINT default_hover_time, hover_width = 0, hover_height = 0;
9941
9942 #define track_hover(track_hwnd, track_hover_time) \
9943     tme.cbSize = sizeof(tme); \
9944     tme.dwFlags = TME_HOVER; \
9945     tme.hwndTrack = track_hwnd; \
9946     tme.dwHoverTime = track_hover_time; \
9947     SetLastError(0xdeadbeef); \
9948     ret = pTrackMouseEvent(&tme); \
9949     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9950
9951 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9952     tme.cbSize = sizeof(tme); \
9953     tme.dwFlags = TME_QUERY; \
9954     tme.hwndTrack = (HWND)0xdeadbeef; \
9955     tme.dwHoverTime = 0xdeadbeef; \
9956     SetLastError(0xdeadbeef); \
9957     ret = pTrackMouseEvent(&tme); \
9958     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9959     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9960     ok(tme.dwFlags == (expected_track_flags), \
9961        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9962     ok(tme.hwndTrack == (expected_track_hwnd), \
9963        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9964     ok(tme.dwHoverTime == (expected_hover_time), \
9965        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9966
9967 #define track_hover_cancel(track_hwnd) \
9968     tme.cbSize = sizeof(tme); \
9969     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9970     tme.hwndTrack = track_hwnd; \
9971     tme.dwHoverTime = 0xdeadbeef; \
9972     SetLastError(0xdeadbeef); \
9973     ret = pTrackMouseEvent(&tme); \
9974     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9975
9976     default_hover_time = 0xdeadbeef;
9977     SetLastError(0xdeadbeef);
9978     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9979     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9980        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9981     if (!ret) default_hover_time = 400;
9982     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9983
9984     SetLastError(0xdeadbeef);
9985     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9986     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9987        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9988     if (!ret) hover_width = 4;
9989     SetLastError(0xdeadbeef);
9990     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9991     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9992        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9993     if (!ret) hover_height = 4;
9994     trace("hover rect is %u x %d\n", hover_width, hover_height);
9995
9996     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9997                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9998                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9999                           NULL, NULL, 0);
10000     assert(hwnd);
10001
10002     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10003                           WS_CHILD | WS_BORDER | WS_VISIBLE,
10004                           50, 50, 200, 200, hwnd,
10005                           NULL, NULL, 0);
10006     assert(hchild);
10007
10008     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10009     flush_events();
10010     flush_sequence();
10011
10012     tme.cbSize = 0;
10013     tme.dwFlags = TME_QUERY;
10014     tme.hwndTrack = (HWND)0xdeadbeef;
10015     tme.dwHoverTime = 0xdeadbeef;
10016     SetLastError(0xdeadbeef);
10017     ret = pTrackMouseEvent(&tme);
10018     ok(!ret, "TrackMouseEvent should fail\n");
10019     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10020        "not expected error %u\n", GetLastError());
10021
10022     tme.cbSize = sizeof(tme);
10023     tme.dwFlags = TME_HOVER;
10024     tme.hwndTrack = (HWND)0xdeadbeef;
10025     tme.dwHoverTime = 0xdeadbeef;
10026     SetLastError(0xdeadbeef);
10027     ret = pTrackMouseEvent(&tme);
10028     ok(!ret, "TrackMouseEvent should fail\n");
10029     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10030        "not expected error %u\n", GetLastError());
10031
10032     tme.cbSize = sizeof(tme);
10033     tme.dwFlags = TME_HOVER | TME_CANCEL;
10034     tme.hwndTrack = (HWND)0xdeadbeef;
10035     tme.dwHoverTime = 0xdeadbeef;
10036     SetLastError(0xdeadbeef);
10037     ret = pTrackMouseEvent(&tme);
10038     ok(!ret, "TrackMouseEvent should fail\n");
10039     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10040        "not expected error %u\n", GetLastError());
10041
10042     GetWindowRect(hwnd, &rc_parent);
10043     GetWindowRect(hchild, &rc_child);
10044     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10045
10046     /* Process messages so that the system updates its internal current
10047      * window and hittest, otherwise TrackMouseEvent calls don't have any
10048      * effect.
10049      */
10050     flush_events();
10051     flush_sequence();
10052
10053     track_query(0, NULL, 0);
10054     track_hover(hchild, 0);
10055     track_query(0, NULL, 0);
10056
10057     flush_events();
10058     flush_sequence();
10059
10060     track_hover(hwnd, 0);
10061     tme.cbSize = sizeof(tme);
10062     tme.dwFlags = TME_QUERY;
10063     tme.hwndTrack = (HWND)0xdeadbeef;
10064     tme.dwHoverTime = 0xdeadbeef;
10065     SetLastError(0xdeadbeef);
10066     ret = pTrackMouseEvent(&tme);
10067     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10068     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10069     if (!tme.dwFlags)
10070     {
10071         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10072         DestroyWindow( hwnd );
10073         return;
10074     }
10075     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10076     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10077     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10078        tme.dwHoverTime, default_hover_time);
10079
10080     pump_msg_loop_timeout(default_hover_time, FALSE);
10081     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10082
10083     track_query(0, NULL, 0);
10084
10085     track_hover(hwnd, HOVER_DEFAULT);
10086     track_query(TME_HOVER, hwnd, default_hover_time);
10087
10088     Sleep(default_hover_time / 2);
10089     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10090     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10091
10092     track_query(TME_HOVER, hwnd, default_hover_time);
10093
10094     pump_msg_loop_timeout(default_hover_time, FALSE);
10095     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10096
10097     track_query(0, NULL, 0);
10098
10099     track_hover(hwnd, HOVER_DEFAULT);
10100     track_query(TME_HOVER, hwnd, default_hover_time);
10101
10102     pump_msg_loop_timeout(default_hover_time, TRUE);
10103     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10104
10105     track_query(0, NULL, 0);
10106
10107     track_hover(hwnd, HOVER_DEFAULT);
10108     track_query(TME_HOVER, hwnd, default_hover_time);
10109     track_hover_cancel(hwnd);
10110
10111     DestroyWindow(hwnd);
10112
10113 #undef track_hover
10114 #undef track_query
10115 #undef track_hover_cancel
10116 }
10117
10118
10119 static const struct message WmSetWindowRgn[] = {
10120     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10121     { WM_NCCALCSIZE, sent|wparam, 1 },
10122     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10123     { WM_GETTEXT, sent|defwinproc|optional },
10124     { WM_ERASEBKGND, sent|optional },
10125     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10126     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10127     { 0 }
10128 };
10129
10130 static const struct message WmSetWindowRgn_no_redraw[] = {
10131     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10132     { WM_NCCALCSIZE, sent|wparam, 1 },
10133     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10134     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10135     { 0 }
10136 };
10137
10138 static const struct message WmSetWindowRgn_clear[] = {
10139     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10140     { WM_NCCALCSIZE, sent|wparam, 1 },
10141     { WM_NCPAINT, sent|optional },
10142     { WM_GETTEXT, sent|defwinproc|optional },
10143     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10144     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10145     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10146     { WM_NCPAINT, sent|optional },
10147     { WM_GETTEXT, sent|defwinproc|optional },
10148     { WM_ERASEBKGND, sent|optional },
10149     { WM_WINDOWPOSCHANGING, sent|optional },
10150     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10151     { WM_NCPAINT, sent|optional },
10152     { WM_GETTEXT, sent|defwinproc|optional },
10153     { WM_ERASEBKGND, sent|optional },
10154     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10155     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10156     { WM_NCPAINT, sent|optional },
10157     { WM_GETTEXT, sent|defwinproc|optional },
10158     { WM_ERASEBKGND, sent|optional },
10159     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10160     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10161     { 0 }
10162 };
10163
10164 static void test_SetWindowRgn(void)
10165 {
10166     HRGN hrgn;
10167     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10168                                 100, 100, 200, 200, 0, 0, 0, NULL);
10169     ok( hwnd != 0, "Failed to create overlapped window\n" );
10170
10171     ShowWindow( hwnd, SW_SHOW );
10172     UpdateWindow( hwnd );
10173     flush_events();
10174     flush_sequence();
10175
10176     trace("testing SetWindowRgn\n");
10177     hrgn = CreateRectRgn( 0, 0, 150, 150 );
10178     SetWindowRgn( hwnd, hrgn, TRUE );
10179     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10180
10181     hrgn = CreateRectRgn( 30, 30, 160, 160 );
10182     SetWindowRgn( hwnd, hrgn, FALSE );
10183     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10184
10185     hrgn = CreateRectRgn( 0, 0, 180, 180 );
10186     SetWindowRgn( hwnd, hrgn, TRUE );
10187     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10188
10189     SetWindowRgn( hwnd, 0, TRUE );
10190     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10191
10192     DestroyWindow( hwnd );
10193 }
10194
10195 /*************************** ShowWindow() test ******************************/
10196 static const struct message WmShowNormal[] = {
10197     { WM_SHOWWINDOW, sent|wparam, 1 },
10198     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10199     { HCBT_ACTIVATE, hook },
10200     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10201     { HCBT_SETFOCUS, hook },
10202     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10203     { 0 }
10204 };
10205 static const struct message WmShow[] = {
10206     { WM_SHOWWINDOW, sent|wparam, 1 },
10207     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10208     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10209     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10210     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10211     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10212     { 0 }
10213 };
10214 static const struct message WmShowNoActivate_1[] = {
10215     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10216     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10217     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10218     { WM_MOVE, sent|defwinproc|optional },
10219     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10220     { 0 }
10221 };
10222 static const struct message WmShowNoActivate_2[] = {
10223     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10224     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10225     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10226     { WM_MOVE, sent|defwinproc },
10227     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10228     { HCBT_SETFOCUS, hook|optional },
10229     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10230     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10231     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10232     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10233     { 0 }
10234 };
10235 static const struct message WmShowNA_1[] = {
10236     { WM_SHOWWINDOW, sent|wparam, 1 },
10237     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10238     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10239     { 0 }
10240 };
10241 static const struct message WmShowNA_2[] = {
10242     { WM_SHOWWINDOW, sent|wparam, 1 },
10243     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10244     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10245     { 0 }
10246 };
10247 static const struct message WmRestore_1[] = {
10248     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10249     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10250     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10251     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10252     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10253     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10254     { WM_MOVE, sent|defwinproc },
10255     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10256     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10257     { 0 }
10258 };
10259 static const struct message WmRestore_2[] = {
10260     { WM_SHOWWINDOW, sent|wparam, 1 },
10261     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10262     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10263     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10264     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10265     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10266     { 0 }
10267 };
10268 static const struct message WmRestore_3[] = {
10269     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10270     { WM_GETMINMAXINFO, sent },
10271     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10272     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10273     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10274     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10275     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10276     { WM_MOVE, sent|defwinproc },
10277     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10278     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10279     { 0 }
10280 };
10281 static const struct message WmRestore_4[] = {
10282     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10283     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10284     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10285     { WM_MOVE, sent|defwinproc|optional },
10286     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10287     { 0 }
10288 };
10289 static const struct message WmRestore_5[] = {
10290     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10291     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10292     { HCBT_ACTIVATE, hook|optional },
10293     { HCBT_SETFOCUS, hook|optional },
10294     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10295     { WM_MOVE, sent|defwinproc|optional },
10296     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10297     { 0 }
10298 };
10299 static const struct message WmHide_1[] = {
10300     { WM_SHOWWINDOW, sent|wparam, 0 },
10301     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10302     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10303     { HCBT_ACTIVATE, hook|optional },
10304     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10305     { 0 }
10306 };
10307 static const struct message WmHide_2[] = {
10308     { WM_SHOWWINDOW, sent|wparam, 0 },
10309     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10310     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10311     { HCBT_ACTIVATE, hook|optional },
10312     { 0 }
10313 };
10314 static const struct message WmHide_3[] = {
10315     { WM_SHOWWINDOW, sent|wparam, 0 },
10316     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10317     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10318     { HCBT_SETFOCUS, hook|optional },
10319     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10320     { 0 }
10321 };
10322 static const struct message WmShowMinimized_1[] = {
10323     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10324     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10325     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10326     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10327     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10328     { WM_MOVE, sent|defwinproc },
10329     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10330     { 0 }
10331 };
10332 static const struct message WmMinimize_1[] = {
10333     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10334     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10335     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10336     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10337     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10338     { WM_MOVE, sent|defwinproc },
10339     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10340     { 0 }
10341 };
10342 static const struct message WmMinimize_2[] = {
10343     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10344     { HCBT_SETFOCUS, hook|optional },
10345     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10346     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10347     { WM_MOVE, sent|defwinproc },
10348     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10349     { 0 }
10350 };
10351 static const struct message WmMinimize_3[] = {
10352     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10353     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10354     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10355     { WM_MOVE, sent|defwinproc },
10356     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10357     { 0 }
10358 };
10359 static const struct message WmShowMinNoActivate[] = {
10360     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10361     { WM_WINDOWPOSCHANGING, sent },
10362     { WM_WINDOWPOSCHANGED, sent },
10363     { WM_MOVE, sent|defwinproc|optional },
10364     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10365     { 0 }
10366 };
10367 static const struct message WmMinMax_1[] = {
10368     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10369     { 0 }
10370 };
10371 static const struct message WmMinMax_2[] = {
10372     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10373     { WM_GETMINMAXINFO, sent|optional },
10374     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10375     { HCBT_ACTIVATE, hook|optional },
10376     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10377     { HCBT_SETFOCUS, hook|optional },
10378     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10379     { WM_MOVE, sent|defwinproc|optional },
10380     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10381     { HCBT_SETFOCUS, hook|optional },
10382     { 0 }
10383 };
10384 static const struct message WmMinMax_3[] = {
10385     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10386     { HCBT_SETFOCUS, hook|optional },
10387     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10388     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10389     { WM_MOVE, sent|defwinproc|optional },
10390     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10391     { 0 }
10392 };
10393 static const struct message WmMinMax_4[] = {
10394     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10395     { 0 }
10396 };
10397 static const struct message WmShowMaximized_1[] = {
10398     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10399     { WM_GETMINMAXINFO, sent },
10400     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10401     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10402     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10403     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10404     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10405     { WM_MOVE, sent|defwinproc },
10406     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10407     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10408     { 0 }
10409 };
10410 static const struct message WmShowMaximized_2[] = {
10411     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10412     { WM_GETMINMAXINFO, sent },
10413     { WM_WINDOWPOSCHANGING, sent|optional },
10414     { HCBT_ACTIVATE, hook|optional },
10415     { WM_WINDOWPOSCHANGED, sent|optional },
10416     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10417     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10418     { WM_WINDOWPOSCHANGING, sent|optional },
10419     { HCBT_SETFOCUS, hook|optional },
10420     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10421     { WM_MOVE, sent|defwinproc },
10422     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10423     { HCBT_SETFOCUS, hook|optional },
10424     { 0 }
10425 };
10426 static const struct message WmShowMaximized_3[] = {
10427     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10428     { WM_GETMINMAXINFO, sent|optional },
10429     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10430     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10431     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10432     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10433     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10434     { WM_MOVE, sent|defwinproc|optional },
10435     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10436     { 0 }
10437 };
10438
10439 static void test_ShowWindow(void)
10440 {
10441     /* ShowWindow commands in random order */
10442     static const struct
10443     {
10444         INT cmd; /* ShowWindow command */
10445         LPARAM ret; /* ShowWindow return value */
10446         DWORD style; /* window style after the command */
10447         const struct message *msg; /* message sequence the command produces */
10448         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10449     } sw[] =
10450     {
10451 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10452 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10453 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10454 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10455 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10456 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10457 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10458 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10459 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10460 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10461 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10462 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10463 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10464 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10465 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10466 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10467 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10468 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10469 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10470 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10471 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10472 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10473 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10474 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10475 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10476 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10477 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10478 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10479 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10480 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10481 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10482 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10483 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10484 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10485 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10486 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10487 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10488 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10489 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10490 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10491 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10492 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10493 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10494 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10495 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10496 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10497 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10498 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10499 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10500 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10501 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10502 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10503 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10504 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10505 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10506 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10507 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10508     };
10509     HWND hwnd;
10510     DWORD style;
10511     LPARAM ret;
10512     INT i;
10513
10514 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10515     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10516                           120, 120, 90, 90,
10517                           0, 0, 0, NULL);
10518     assert(hwnd);
10519
10520     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10521     ok(style == 0, "expected style 0, got %08x\n", style);
10522
10523     flush_events();
10524     flush_sequence();
10525
10526     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10527     {
10528         static const char * const sw_cmd_name[13] =
10529         {
10530             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10531             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10532             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10533             "SW_NORMALNA" /* 0xCC */
10534         };
10535         char comment[64];
10536         INT idx; /* index into the above array of names */
10537
10538         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10539
10540         style = GetWindowLong(hwnd, GWL_STYLE);
10541         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10542         ret = ShowWindow(hwnd, sw[i].cmd);
10543         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10544         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10545         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10546
10547         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10548         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10549
10550         flush_events();
10551         flush_sequence();
10552     }
10553
10554     DestroyWindow(hwnd);
10555 }
10556
10557 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10558 {
10559     struct recvd_message msg;
10560
10561     if (ignore_message( message )) return 0;
10562
10563     msg.hwnd = hwnd;
10564     msg.message = message;
10565     msg.flags = sent|wparam|lparam;
10566     msg.wParam = wParam;
10567     msg.lParam = lParam;
10568     msg.descr = "dialog";
10569     add_message(&msg);
10570
10571     /* calling DefDlgProc leads to a recursion under XP */
10572
10573     switch (message)
10574     {
10575     case WM_INITDIALOG:
10576     case WM_GETDLGCODE:
10577         return 0;
10578     }
10579     return 1;
10580 }
10581
10582 static const struct message WmDefDlgSetFocus_1[] = {
10583     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10584     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10585     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10586     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10587     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10588     { HCBT_SETFOCUS, hook },
10589     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10590     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10591     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10592     { WM_SETFOCUS, sent|wparam, 0 },
10593     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10594     { WM_CTLCOLOREDIT, sent },
10595     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10596     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10597     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10598     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10599     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10600     { 0 }
10601 };
10602 static const struct message WmDefDlgSetFocus_2[] = {
10603     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10604     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10605     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10606     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10607     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10608     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10609     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10610     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10611     { 0 }
10612 };
10613 /* Creation of a dialog */
10614 static const struct message WmCreateDialogParamSeq_1[] = {
10615     { HCBT_CREATEWND, hook },
10616     { WM_NCCREATE, sent },
10617     { WM_NCCALCSIZE, sent|wparam, 0 },
10618     { WM_CREATE, sent },
10619     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10620     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10621     { WM_MOVE, sent },
10622     { WM_SETFONT, sent },
10623     { WM_INITDIALOG, sent },
10624     { WM_CHANGEUISTATE, sent|optional },
10625     { 0 }
10626 };
10627 /* Creation of a dialog */
10628 static const struct message WmCreateDialogParamSeq_2[] = {
10629     { HCBT_CREATEWND, hook },
10630     { WM_NCCREATE, sent },
10631     { WM_NCCALCSIZE, sent|wparam, 0 },
10632     { WM_CREATE, sent },
10633     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10634     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10635     { WM_MOVE, sent },
10636     { WM_CHANGEUISTATE, sent|optional },
10637     { 0 }
10638 };
10639
10640 static void test_dialog_messages(void)
10641 {
10642     WNDCLASS cls;
10643     HWND hdlg, hedit1, hedit2, hfocus;
10644     LRESULT ret;
10645
10646 #define set_selection(hctl, start, end) \
10647     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10648     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10649
10650 #define check_selection(hctl, start, end) \
10651     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10652     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10653
10654     subclass_edit();
10655
10656     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10657                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10658                           0, 0, 100, 100, 0, 0, 0, NULL);
10659     ok(hdlg != 0, "Failed to create custom dialog window\n");
10660
10661     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10662                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10663                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10664     ok(hedit1 != 0, "Failed to create edit control\n");
10665     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10666                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10667                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10668     ok(hedit2 != 0, "Failed to create edit control\n");
10669
10670     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10671     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10672
10673     hfocus = GetFocus();
10674     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10675
10676     SetFocus(hedit2);
10677     hfocus = GetFocus();
10678     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10679
10680     check_selection(hedit1, 0, 0);
10681     check_selection(hedit2, 0, 0);
10682
10683     set_selection(hedit2, 0, -1);
10684     check_selection(hedit2, 0, 3);
10685
10686     SetFocus(0);
10687     hfocus = GetFocus();
10688     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10689
10690     flush_sequence();
10691     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10692     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10693     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10694
10695     hfocus = GetFocus();
10696     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10697
10698     check_selection(hedit1, 0, 5);
10699     check_selection(hedit2, 0, 3);
10700
10701     flush_sequence();
10702     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10703     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10704     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10705
10706     hfocus = GetFocus();
10707     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10708
10709     check_selection(hedit1, 0, 5);
10710     check_selection(hedit2, 0, 3);
10711
10712     EndDialog(hdlg, 0);
10713     DestroyWindow(hedit1);
10714     DestroyWindow(hedit2);
10715     DestroyWindow(hdlg);
10716     flush_sequence();
10717
10718 #undef set_selection
10719 #undef check_selection
10720
10721     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10722     cls.lpszClassName = "MyDialogClass";
10723     cls.hInstance = GetModuleHandle(0);
10724     /* need a cast since a dlgproc is used as a wndproc */
10725     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10726     if (!RegisterClass(&cls)) assert(0);
10727
10728     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10729     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10730     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10731     EndDialog(hdlg, 0);
10732     DestroyWindow(hdlg);
10733     flush_sequence();
10734
10735     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10736     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10737     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10738     EndDialog(hdlg, 0);
10739     DestroyWindow(hdlg);
10740     flush_sequence();
10741
10742     UnregisterClass(cls.lpszClassName, cls.hInstance);
10743 }
10744
10745 static void test_nullCallback(void)
10746 {
10747     HWND hwnd;
10748
10749     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10750                            100, 100, 200, 200, 0, 0, 0, NULL);
10751     ok (hwnd != 0, "Failed to create overlapped window\n");
10752
10753     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10754     flush_events();
10755     DestroyWindow(hwnd);
10756 }
10757
10758 /* SetActiveWindow( 0 ) hwnd visible */
10759 static const struct message SetActiveWindowSeq0[] =
10760 {
10761     { HCBT_ACTIVATE, hook|optional },
10762     { WM_NCACTIVATE, sent|wparam, 0 },
10763     { WM_GETTEXT, sent|defwinproc|optional },
10764     { WM_ACTIVATE, sent|wparam, 0 },
10765     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10766     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10767     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10768     { WM_KILLFOCUS, sent|optional },
10769     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10770     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10771     { WM_NCACTIVATE, sent|wparam|optional, 1 },
10772     { WM_GETTEXT, sent|defwinproc|optional },
10773     { WM_ACTIVATE, sent|wparam|optional, 1 },
10774     { HCBT_SETFOCUS, hook|optional },
10775     { WM_KILLFOCUS, sent|defwinproc|optional },
10776     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10777     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10778     { WM_IME_SETCONTEXT, sent|optional },
10779     { WM_IME_SETCONTEXT, sent|optional },
10780     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10781     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10782     { WM_SETFOCUS, sent|defwinproc|optional },
10783     { WM_GETTEXT, sent|optional },
10784     { 0 }
10785 };
10786 /* SetActiveWindow( hwnd ) hwnd visible */
10787 static const struct message SetActiveWindowSeq1[] =
10788 {
10789     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10790     { 0 }
10791 };
10792 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10793 static const struct message SetActiveWindowSeq2[] =
10794 {
10795     { HCBT_ACTIVATE, hook },
10796     { WM_NCACTIVATE, sent|wparam, 0 },
10797     { WM_GETTEXT, sent|defwinproc|optional },
10798     { WM_ACTIVATE, sent|wparam, 0 },
10799     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10800     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10801     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10802     { WM_NCPAINT, sent|optional },
10803     { WM_GETTEXT, sent|defwinproc|optional },
10804     { WM_ERASEBKGND, sent|optional },
10805     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10806     { WM_NCACTIVATE, sent|wparam, 1 },
10807     { WM_GETTEXT, sent|defwinproc|optional },
10808     { WM_ACTIVATE, sent|wparam, 1 },
10809     { HCBT_SETFOCUS, hook },
10810     { WM_KILLFOCUS, sent|defwinproc },
10811     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10812     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10813     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10814     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10815     { WM_SETFOCUS, sent|defwinproc },
10816     { WM_GETTEXT, sent|optional },
10817     { 0 }
10818 };
10819
10820 /* SetActiveWindow( hwnd ) hwnd not visible */
10821 static const struct message SetActiveWindowSeq3[] =
10822 {
10823     { HCBT_ACTIVATE, hook },
10824     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10825     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10826     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10827     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10828     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10829     { WM_ACTIVATEAPP, sent|wparam, 1 },
10830     { WM_ACTIVATEAPP, sent|wparam, 1 },
10831     { WM_NCACTIVATE, sent|wparam, 1 },
10832     { WM_ACTIVATE, sent|wparam, 1 },
10833     { HCBT_SETFOCUS, hook },
10834     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10835     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10836     { WM_SETFOCUS, sent|defwinproc },
10837     { 0 }
10838 };
10839 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10840 static const struct message SetActiveWindowSeq4[] =
10841 {
10842     { HCBT_ACTIVATE, hook },
10843     { WM_NCACTIVATE, sent|wparam, 0 },
10844     { WM_GETTEXT, sent|defwinproc|optional },
10845     { WM_ACTIVATE, sent|wparam, 0 },
10846     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10847     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10849     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10850     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10851     { WM_NCACTIVATE, sent|wparam, 1 },
10852     { WM_GETTEXT, sent|defwinproc|optional },
10853     { WM_ACTIVATE, sent|wparam, 1 },
10854     { HCBT_SETFOCUS, hook },
10855     { WM_KILLFOCUS, sent|defwinproc },
10856     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10857     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10858     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10859     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10860     { WM_SETFOCUS, sent|defwinproc },
10861     { 0 }
10862 };
10863
10864
10865 static void test_SetActiveWindow(void)
10866 {
10867     HWND hwnd, popup, ret;
10868
10869     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10870                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10871                            100, 100, 200, 200, 0, 0, 0, NULL);
10872
10873     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10874                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10875                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10876
10877     ok(hwnd != 0, "Failed to create overlapped window\n");
10878     ok(popup != 0, "Failed to create popup window\n");
10879     SetForegroundWindow( popup );
10880     flush_sequence();
10881
10882     trace("SetActiveWindow(0)\n");
10883     ret = SetActiveWindow(0);
10884     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10885     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10886     flush_sequence();
10887
10888     trace("SetActiveWindow(hwnd), hwnd visible\n");
10889     ret = SetActiveWindow(hwnd);
10890     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10891     flush_sequence();
10892
10893     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10894     ret = SetActiveWindow(popup);
10895     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10896     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10897     flush_sequence();
10898
10899     ShowWindow(hwnd, SW_HIDE);
10900     ShowWindow(popup, SW_HIDE);
10901     flush_sequence();
10902
10903     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10904     ret = SetActiveWindow(hwnd);
10905     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10906     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10907     flush_sequence();
10908
10909     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10910     ret = SetActiveWindow(popup);
10911     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10912     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10913     flush_sequence();
10914
10915     trace("done\n");
10916
10917     DestroyWindow(hwnd);
10918 }
10919
10920 static const struct message SetForegroundWindowSeq[] =
10921 {
10922     { WM_NCACTIVATE, sent|wparam, 0 },
10923     { WM_GETTEXT, sent|defwinproc|optional },
10924     { WM_ACTIVATE, sent|wparam, 0 },
10925     { WM_ACTIVATEAPP, sent|wparam, 0 },
10926     { WM_KILLFOCUS, sent },
10927     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10928     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10929     { 0 }
10930 };
10931
10932 static void test_SetForegroundWindow(void)
10933 {
10934     HWND hwnd;
10935
10936     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10937                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10938                            100, 100, 200, 200, 0, 0, 0, NULL);
10939     ok (hwnd != 0, "Failed to create overlapped window\n");
10940     SetForegroundWindow( hwnd );
10941     flush_sequence();
10942
10943     trace("SetForegroundWindow( 0 )\n");
10944     SetForegroundWindow( 0 );
10945     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10946     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10947     SetForegroundWindow( GetDesktopWindow() );
10948     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10949                                         "foreground top level window", FALSE);
10950     trace("done\n");
10951
10952     DestroyWindow(hwnd);
10953 }
10954
10955 static void test_dbcs_wm_char(void)
10956 {
10957     BYTE dbch[2];
10958     WCHAR wch, bad_wch;
10959     HWND hwnd, hwnd2;
10960     MSG msg;
10961     DWORD time;
10962     POINT pt;
10963     DWORD_PTR res;
10964     CPINFOEXA cpinfo;
10965     UINT i, j, k;
10966     struct message wmCharSeq[2];
10967
10968     if (!pGetCPInfoExA)
10969     {
10970         win_skip("GetCPInfoExA is not available\n");
10971         return;
10972     }
10973
10974     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10975     if (cpinfo.MaxCharSize != 2)
10976     {
10977         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10978         return;
10979     }
10980
10981     dbch[0] = dbch[1] = 0;
10982     wch = 0;
10983     bad_wch = cpinfo.UnicodeDefaultChar;
10984     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10985         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10986             for (k = 128; k <= 255; k++)
10987             {
10988                 char str[2];
10989                 WCHAR wstr[2];
10990                 str[0] = j;
10991                 str[1] = k;
10992                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10993                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10994                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10995                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10996                 {
10997                     dbch[0] = j;
10998                     dbch[1] = k;
10999                     wch = wstr[0];
11000                     break;
11001                 }
11002             }
11003
11004     if (!wch)
11005     {
11006         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11007         return;
11008     }
11009     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11010            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11011
11012     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11013                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11014     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11015                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11016     ok (hwnd != 0, "Failed to create overlapped window\n");
11017     ok (hwnd2 != 0, "Failed to create overlapped window\n");
11018     flush_sequence();
11019
11020     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11021     wmCharSeq[0].message = WM_CHAR;
11022     wmCharSeq[0].flags = sent|wparam;
11023     wmCharSeq[0].wParam = wch;
11024
11025     /* posted message */
11026     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11027     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11028     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11029     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11030     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11031     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11032     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11033
11034     /* posted thread message */
11035     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11036     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11037     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11038     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11039     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11040     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11041     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11042
11043     /* sent message */
11044     flush_sequence();
11045     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11046     ok_sequence( WmEmptySeq, "no messages", FALSE );
11047     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11048     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11049     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11050
11051     /* sent message with timeout */
11052     flush_sequence();
11053     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11054     ok_sequence( WmEmptySeq, "no messages", FALSE );
11055     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11056     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11057     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11058
11059     /* sent message with timeout and callback */
11060     flush_sequence();
11061     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11062     ok_sequence( WmEmptySeq, "no messages", FALSE );
11063     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11064     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11065     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11066
11067     /* sent message with callback */
11068     flush_sequence();
11069     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11070     ok_sequence( WmEmptySeq, "no messages", FALSE );
11071     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11072     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11073     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11074
11075     /* direct window proc call */
11076     flush_sequence();
11077     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11078     ok_sequence( WmEmptySeq, "no messages", FALSE );
11079     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11080     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11081
11082     /* dispatch message */
11083     msg.hwnd = hwnd;
11084     msg.message = WM_CHAR;
11085     msg.wParam = dbch[0];
11086     msg.lParam = 0;
11087     DispatchMessageA( &msg );
11088     ok_sequence( WmEmptySeq, "no messages", FALSE );
11089     msg.wParam = dbch[1];
11090     DispatchMessageA( &msg );
11091     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11092
11093     /* window handle is irrelevant */
11094     flush_sequence();
11095     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11096     ok_sequence( WmEmptySeq, "no messages", FALSE );
11097     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11098     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11099     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11100
11101     /* interleaved post and send */
11102     flush_sequence();
11103     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11104     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11105     ok_sequence( WmEmptySeq, "no messages", FALSE );
11106     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11107     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11108     ok_sequence( WmEmptySeq, "no messages", FALSE );
11109     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11110     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11111     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11112     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11113     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11114     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11115     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11116
11117     /* interleaved sent message and winproc */
11118     flush_sequence();
11119     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11120     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11121     ok_sequence( WmEmptySeq, "no messages", FALSE );
11122     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11123     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11124     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11125     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11126
11127     /* interleaved winproc and dispatch */
11128     msg.hwnd = hwnd;
11129     msg.message = WM_CHAR;
11130     msg.wParam = dbch[0];
11131     msg.lParam = 0;
11132     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11133     DispatchMessageA( &msg );
11134     ok_sequence( WmEmptySeq, "no messages", FALSE );
11135     msg.wParam = dbch[1];
11136     DispatchMessageA( &msg );
11137     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11138     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11139     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11140
11141     /* interleaved sends */
11142     flush_sequence();
11143     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11144     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11145     ok_sequence( WmEmptySeq, "no messages", FALSE );
11146     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11147     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11148     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11149     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11150
11151     /* dbcs WM_CHAR */
11152     flush_sequence();
11153     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11154     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11155     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11156
11157     /* other char messages are not magic */
11158     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11159     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11160     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11161     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11162     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11163     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11164     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11165     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11166     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11167     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11168
11169     /* test retrieving messages */
11170
11171     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11172     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11173     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11174     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11175     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11176     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11177     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11178     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11179     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11180     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11181
11182     /* message filters */
11183     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11184     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11185     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11186     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11187     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11188     /* message id is filtered, hwnd is not */
11189     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11190     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11191     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11192     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11193     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11194     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11195
11196     /* mixing GetMessage and PostMessage */
11197     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11198     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11199     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11200     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11201     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11202     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11203     time = msg.time;
11204     pt = msg.pt;
11205     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11206     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11207     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11208     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11209     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11210     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11211     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11212     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 );
11213     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11214
11215     /* without PM_REMOVE */
11216     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11217     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11218     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11219     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11220     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11221     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11222     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11223     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11224     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11225     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11226     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11227     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11228     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11229     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11230     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11231     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11232     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11233     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11234
11235     DestroyWindow(hwnd);
11236 }
11237
11238 #define ID_LISTBOX 0x000f
11239
11240 static const struct message wm_lb_setcursel_0[] =
11241 {
11242     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11243     { WM_CTLCOLORLISTBOX, sent|parent },
11244     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11245     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11246     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11247     { 0 }
11248 };
11249 static const struct message wm_lb_setcursel_1[] =
11250 {
11251     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11252     { WM_CTLCOLORLISTBOX, sent|parent },
11253     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11254     { WM_CTLCOLORLISTBOX, sent|parent },
11255     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11256     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11257     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11258     { 0 }
11259 };
11260 static const struct message wm_lb_setcursel_2[] =
11261 {
11262     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11263     { WM_CTLCOLORLISTBOX, sent|parent },
11264     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11265     { WM_CTLCOLORLISTBOX, sent|parent },
11266     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11267     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11268     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11269     { 0 }
11270 };
11271 static const struct message wm_lb_click_0[] =
11272 {
11273     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11274     { HCBT_SETFOCUS, hook },
11275     { WM_KILLFOCUS, sent|parent },
11276     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11277     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11278     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11279     { WM_SETFOCUS, sent|defwinproc },
11280
11281     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11282     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11283     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11284     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11285     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11286
11287     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11288     { WM_CTLCOLORLISTBOX, sent|parent },
11289     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11290     { WM_CTLCOLORLISTBOX, sent|parent },
11291     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11292     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11293
11294     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11295     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11296
11297     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11298     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11299     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11300     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11301     { 0 }
11302 };
11303 static const struct message wm_lb_deletestring[] =
11304 {
11305     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11306     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11307     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11308     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11309     { 0 }
11310 };
11311 static const struct message wm_lb_deletestring_reset[] =
11312 {
11313     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11314     { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11315     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11316     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11317     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11318     { 0 }
11319 };
11320
11321 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11322
11323 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11324
11325 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11326 {
11327     static LONG defwndproc_counter = 0;
11328     LRESULT ret;
11329     struct recvd_message msg;
11330
11331     /* do not log painting messages */
11332     if (message != WM_PAINT &&
11333         message != WM_NCPAINT &&
11334         message != WM_SYNCPAINT &&
11335         message != WM_ERASEBKGND &&
11336         message != WM_NCHITTEST &&
11337         message != WM_GETTEXT &&
11338         !ignore_message( message ))
11339     {
11340         msg.hwnd = hwnd;
11341         msg.message = message;
11342         msg.flags = sent|wparam|lparam;
11343         if (defwndproc_counter) msg.flags |= defwinproc;
11344         msg.wParam = wp;
11345         msg.lParam = lp;
11346         msg.descr = "listbox";
11347         add_message(&msg);
11348     }
11349
11350     defwndproc_counter++;
11351     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11352     defwndproc_counter--;
11353
11354     return ret;
11355 }
11356
11357 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11358                                int caret_index, int top_index, int line)
11359 {
11360     LRESULT ret;
11361
11362     /* calling an orig proc helps to avoid unnecessary message logging */
11363     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11364     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11365     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11366     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11367     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11368     ok_(__FILE__, line)(ret == caret_index ||
11369                         broken(cur_sel == -1 && caret_index == 0 && ret == -1),  /* nt4 */
11370                         "expected caret index %d, got %ld\n", caret_index, ret);
11371     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11372     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11373 }
11374
11375 static void test_listbox_messages(void)
11376 {
11377     HWND parent, listbox;
11378     LRESULT ret;
11379
11380     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11381                              100, 100, 200, 200, 0, 0, 0, NULL);
11382     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11383                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11384                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11385     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11386
11387     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11388
11389     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11390     ok(ret == 0, "expected 0, got %ld\n", ret);
11391     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11392     ok(ret == 1, "expected 1, got %ld\n", ret);
11393     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11394     ok(ret == 2, "expected 2, got %ld\n", ret);
11395
11396     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11397
11398     flush_sequence();
11399
11400     log_all_parent_messages++;
11401
11402     trace("selecting item 0\n");
11403     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11404     ok(ret == 0, "expected 0, got %ld\n", ret);
11405     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11406     check_lb_state(listbox, 3, 0, 0, 0);
11407     flush_sequence();
11408
11409     trace("selecting item 1\n");
11410     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11411     ok(ret == 1, "expected 1, got %ld\n", ret);
11412     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11413     check_lb_state(listbox, 3, 1, 1, 0);
11414
11415     trace("selecting item 2\n");
11416     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11417     ok(ret == 2, "expected 2, got %ld\n", ret);
11418     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11419     check_lb_state(listbox, 3, 2, 2, 0);
11420
11421     trace("clicking on item 0\n");
11422     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11423     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11424     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11425     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11426     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11427     check_lb_state(listbox, 3, 0, 0, 0);
11428     flush_sequence();
11429
11430     trace("deleting item 0\n");
11431     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11432     ok(ret == 2, "expected 2, got %ld\n", ret);
11433     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11434     check_lb_state(listbox, 2, -1, 0, 0);
11435     flush_sequence();
11436
11437     trace("deleting item 0\n");
11438     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11439     ok(ret == 1, "expected 1, got %ld\n", ret);
11440     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11441     check_lb_state(listbox, 1, -1, 0, 0);
11442     flush_sequence();
11443
11444     trace("deleting item 0\n");
11445     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11446     ok(ret == 0, "expected 0, got %ld\n", ret);
11447     ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11448     check_lb_state(listbox, 0, -1, 0, 0);
11449     flush_sequence();
11450
11451     trace("deleting item 0\n");
11452     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11453     ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11454     check_lb_state(listbox, 0, -1, 0, 0);
11455     flush_sequence();
11456
11457     log_all_parent_messages--;
11458
11459     DestroyWindow(listbox);
11460     DestroyWindow(parent);
11461 }
11462
11463 /*************************** Menu test ******************************/
11464 static const struct message wm_popup_menu_1[] =
11465 {
11466     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11467     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11468     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11469     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11470     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11471     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11472     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11473     { WM_INITMENU, sent|lparam, 0, 0 },
11474     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11475     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11476     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11477     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11478     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11479     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11480     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11481     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11482     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11483     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11484     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11485     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11486     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11487     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11488     { 0 }
11489 };
11490 static const struct message wm_popup_menu_2[] =
11491 {
11492     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11493     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11494     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11495     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11496     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11497     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11498     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11499     { WM_INITMENU, sent|lparam, 0, 0 },
11500     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11501     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11502     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11503     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11504     { HCBT_CREATEWND, hook },
11505     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11506                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11507     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11508     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11509     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11510     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11511     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11512     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11513     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11514     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11515     { HCBT_DESTROYWND, hook },
11516     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11517     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11518     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11519     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11520     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11521     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11522     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11523     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11524     { 0 }
11525 };
11526 static const struct message wm_popup_menu_3[] =
11527 {
11528     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11529     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11530     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11531     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11532     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11533     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11534     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11535     { WM_INITMENU, sent|lparam, 0, 0 },
11536     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11537     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11538     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11539     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11540     { HCBT_CREATEWND, hook },
11541     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11542                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11543     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11544     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11545     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11546     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11547     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11548     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11549     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11550     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11551     { HCBT_DESTROYWND, hook },
11552     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11553     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11554     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11555     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11556     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11557     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11558     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11559     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11560     { 0 }
11561 };
11562
11563 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11564 {
11565     if (message == WM_ENTERIDLE ||
11566         message == WM_INITMENU ||
11567         message == WM_INITMENUPOPUP ||
11568         message == WM_MENUSELECT ||
11569         message == WM_PARENTNOTIFY ||
11570         message == WM_ENTERMENULOOP ||
11571         message == WM_EXITMENULOOP ||
11572         message == WM_UNINITMENUPOPUP ||
11573         message == WM_KEYDOWN ||
11574         message == WM_KEYUP ||
11575         message == WM_CHAR ||
11576         message == WM_SYSKEYDOWN ||
11577         message == WM_SYSKEYUP ||
11578         message == WM_SYSCHAR ||
11579         message == WM_COMMAND ||
11580         message == WM_MENUCOMMAND)
11581     {
11582         struct recvd_message msg;
11583
11584         msg.hwnd = hwnd;
11585         msg.message = message;
11586         msg.flags = sent|wparam|lparam;
11587         msg.wParam = wp;
11588         msg.lParam = lp;
11589         msg.descr = "parent_menu_proc";
11590         add_message(&msg);
11591     }
11592
11593     return DefWindowProcA(hwnd, message, wp, lp);
11594 }
11595
11596 static void set_menu_style(HMENU hmenu, DWORD style)
11597 {
11598     MENUINFO mi;
11599     BOOL ret;
11600
11601     mi.cbSize = sizeof(mi);
11602     mi.fMask = MIM_STYLE;
11603     mi.dwStyle = style;
11604     SetLastError(0xdeadbeef);
11605     ret = pSetMenuInfo(hmenu, &mi);
11606     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11607 }
11608
11609 static DWORD get_menu_style(HMENU hmenu)
11610 {
11611     MENUINFO mi;
11612     BOOL ret;
11613
11614     mi.cbSize = sizeof(mi);
11615     mi.fMask = MIM_STYLE;
11616     mi.dwStyle = 0;
11617     SetLastError(0xdeadbeef);
11618     ret = pGetMenuInfo(hmenu, &mi);
11619     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11620
11621     return mi.dwStyle;
11622 }
11623
11624 static void test_menu_messages(void)
11625 {
11626     MSG msg;
11627     WNDCLASSA cls;
11628     HMENU hmenu, hmenu_popup;
11629     HWND hwnd;
11630     DWORD style;
11631
11632     if (!pGetMenuInfo || !pSetMenuInfo)
11633     {
11634         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11635         return;
11636     }
11637     cls.style = 0;
11638     cls.lpfnWndProc = parent_menu_proc;
11639     cls.cbClsExtra = 0;
11640     cls.cbWndExtra = 0;
11641     cls.hInstance = GetModuleHandleA(0);
11642     cls.hIcon = 0;
11643     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11644     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11645     cls.lpszMenuName = NULL;
11646     cls.lpszClassName = "TestMenuClass";
11647     UnregisterClass(cls.lpszClassName, cls.hInstance);
11648     if (!RegisterClassA(&cls)) assert(0);
11649
11650     SetLastError(0xdeadbeef);
11651     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11652                            100, 100, 200, 200, 0, 0, 0, NULL);
11653     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11654
11655     SetLastError(0xdeadbeef);
11656     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11657     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11658
11659     SetMenu(hwnd, hmenu);
11660     SetForegroundWindow( hwnd );
11661
11662     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11663     style = get_menu_style(hmenu);
11664     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11665
11666     hmenu_popup = GetSubMenu(hmenu, 0);
11667     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11668     style = get_menu_style(hmenu_popup);
11669     ok(style == 0, "expected 0, got %u\n", style);
11670
11671     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11672     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11673     style = get_menu_style(hmenu_popup);
11674     ok(style == 0, "expected 0, got %u\n", style);
11675
11676     /* Alt+E, Enter */
11677     trace("testing a popup menu command\n");
11678     flush_sequence();
11679     keybd_event(VK_MENU, 0, 0, 0);
11680     keybd_event('E', 0, 0, 0);
11681     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11682     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11683     keybd_event(VK_RETURN, 0, 0, 0);
11684     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11685     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11686     {
11687         TranslateMessage(&msg);
11688         DispatchMessage(&msg);
11689     }
11690     if (!sequence_cnt)  /* we didn't get any message */
11691     {
11692         skip( "queuing key events not supported\n" );
11693         goto done;
11694     }
11695     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11696     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11697     {
11698         win_skip( "menu tracking through VK_MENU not supported\n" );
11699         goto done;
11700     }
11701     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11702
11703     /* Alt+F, Right, Enter */
11704     trace("testing submenu of a popup menu command\n");
11705     flush_sequence();
11706     keybd_event(VK_MENU, 0, 0, 0);
11707     keybd_event('F', 0, 0, 0);
11708     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11709     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11710     keybd_event(VK_RIGHT, 0, 0, 0);
11711     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11712     keybd_event(VK_RETURN, 0, 0, 0);
11713     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11714     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11715     {
11716         TranslateMessage(&msg);
11717         DispatchMessage(&msg);
11718     }
11719     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11720
11721     set_menu_style(hmenu, 0);
11722     style = get_menu_style(hmenu);
11723     ok(style == 0, "expected 0, got %u\n", style);
11724
11725     hmenu_popup = GetSubMenu(hmenu, 0);
11726     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11727     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11728     style = get_menu_style(hmenu_popup);
11729     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11730
11731     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11732     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11733     style = get_menu_style(hmenu_popup);
11734     ok(style == 0, "expected 0, got %u\n", style);
11735
11736     /* Alt+F, Right, Enter */
11737     trace("testing submenu of a popup menu command\n");
11738     flush_sequence();
11739     keybd_event(VK_MENU, 0, 0, 0);
11740     keybd_event('F', 0, 0, 0);
11741     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11742     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11743     keybd_event(VK_RIGHT, 0, 0, 0);
11744     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11745     keybd_event(VK_RETURN, 0, 0, 0);
11746     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11747     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11748     {
11749         TranslateMessage(&msg);
11750         DispatchMessage(&msg);
11751     }
11752     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11753
11754 done:
11755     DestroyWindow(hwnd);
11756     DestroyMenu(hmenu);
11757 }
11758
11759
11760 static void test_paintingloop(void)
11761 {
11762     HWND hwnd;
11763
11764     paint_loop_done = 0;
11765     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11766                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11767                                 100, 100, 100, 100, 0, 0, 0, NULL );
11768     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11769     ShowWindow(hwnd,SW_NORMAL);
11770     SetFocus(hwnd);
11771
11772     while (!paint_loop_done)
11773     {
11774         MSG msg;
11775         if (PeekMessageA(&msg, 0, 0, 0, 1))
11776         {
11777             TranslateMessage(&msg);
11778             DispatchMessage(&msg);
11779         }
11780     }
11781     DestroyWindow(hwnd);
11782 }
11783
11784 static void test_defwinproc(void)
11785 {
11786     HWND hwnd;
11787     MSG msg;
11788     int gotwmquit = FALSE;
11789     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11790     assert(hwnd);
11791     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11792     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11793         if( msg.message == WM_QUIT) gotwmquit = TRUE;
11794         DispatchMessageA( &msg );
11795     }
11796     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11797     DestroyWindow( hwnd);
11798 }
11799
11800 #define clear_clipboard(hwnd)  clear_clipboard_(__LINE__, (hwnd))
11801 static void clear_clipboard_(int line, HWND hWnd)
11802 {
11803     BOOL succ;
11804     succ = OpenClipboard(hWnd);
11805     ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
11806     succ = EmptyClipboard();
11807     ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
11808     succ = CloseClipboard();
11809     ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
11810 }
11811
11812 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
11813 static void expect_HWND_(int line, HWND expected, HWND got)
11814 {
11815     ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
11816 }
11817
11818 static WNDPROC pOldViewerProc;
11819
11820 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
11821 {
11822     static BOOL recursion_guard;
11823
11824     if (message == WM_DRAWCLIPBOARD && !recursion_guard)
11825     {
11826         recursion_guard = TRUE;
11827         clear_clipboard(hWnd);
11828         recursion_guard = FALSE;
11829     }
11830     return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
11831 }
11832
11833 static void test_clipboard_viewers(void)
11834 {
11835     static struct message wm_change_cb_chain[] =
11836     {
11837         { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
11838         { 0 }
11839     };
11840     static const struct message wm_clipboard_destroyed[] =
11841     {
11842         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11843         { 0 }
11844     };
11845     static struct message wm_clipboard_changed[] =
11846     {
11847         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11848         { 0 }
11849     };
11850     static struct message wm_clipboard_changed_and_owned[] =
11851     {
11852         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11853         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11854         { 0 }
11855     };
11856
11857     HINSTANCE hInst = GetModuleHandleA(NULL);
11858     HWND hWnd1, hWnd2, hWnd3;
11859     HWND hOrigViewer;
11860     HWND hRet;
11861
11862     hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
11863         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11864         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11865         GetDesktopWindow(), NULL, hInst, NULL);
11866     hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
11867         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11868         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11869         GetDesktopWindow(), NULL, hInst, NULL);
11870     hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
11871         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11872         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11873         GetDesktopWindow(), NULL, hInst, NULL);
11874     trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
11875     assert(hWnd1 && hWnd2 && hWnd3);
11876
11877     flush_sequence();
11878
11879     /* Test getting the clipboard viewer and setting the viewer to NULL. */
11880     hOrigViewer = GetClipboardViewer();
11881     hRet = SetClipboardViewer(NULL);
11882     ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
11883     expect_HWND(hOrigViewer, hRet);
11884     expect_HWND(NULL, GetClipboardViewer());
11885
11886     /* Test registering hWnd1 as a viewer. */
11887     hRet = SetClipboardViewer(hWnd1);
11888     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11889     ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
11890     expect_HWND(NULL, hRet);
11891     expect_HWND(hWnd1, GetClipboardViewer());
11892
11893     /* Test that changing the clipboard actually refreshes the registered viewer. */
11894     clear_clipboard(hWnd1);
11895     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11896     ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
11897
11898     /* Again, but with different owner. */
11899     clear_clipboard(hWnd2);
11900     wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
11901     ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
11902
11903     /* Test re-registering same window. */
11904     hRet = SetClipboardViewer(hWnd1);
11905     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11906     ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
11907     expect_HWND(hWnd1, hRet);
11908     expect_HWND(hWnd1, GetClipboardViewer());
11909
11910     /* Test ChangeClipboardChain. */
11911     ChangeClipboardChain(hWnd2, hWnd3);
11912     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11913     wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
11914     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
11915     expect_HWND(hWnd1, GetClipboardViewer());
11916
11917     ChangeClipboardChain(hWnd2, NULL);
11918     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11919     wm_change_cb_chain[0].lParam = 0;
11920     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
11921     expect_HWND(hWnd1, GetClipboardViewer());
11922
11923     ChangeClipboardChain(NULL, hWnd2);
11924     ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
11925     expect_HWND(hWnd1, GetClipboardViewer());
11926
11927     /* Actually change clipboard viewer with ChangeClipboardChain. */
11928     ChangeClipboardChain(hWnd1, hWnd2);
11929     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
11930     expect_HWND(hWnd2, GetClipboardViewer());
11931
11932     /* Test that no refresh messages are sent when viewer has unregistered. */
11933     clear_clipboard(hWnd2);
11934     ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
11935
11936     /* Register hWnd1 again. */
11937     ChangeClipboardChain(hWnd2, hWnd1);
11938     ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
11939     expect_HWND(hWnd1, GetClipboardViewer());
11940
11941     /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
11942      * changes the clipboard. When this happens, the system shouldn't send
11943      * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
11944      */
11945     pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
11946     clear_clipboard(hWnd2);
11947     /* The clipboard owner is changed in recursive_viewer_proc: */
11948     wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
11949     ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
11950
11951     /* Test unregistering. */
11952     ChangeClipboardChain(hWnd1, NULL);
11953     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
11954     expect_HWND(NULL, GetClipboardViewer());
11955
11956     clear_clipboard(hWnd1);
11957     ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
11958
11959     DestroyWindow(hWnd1);
11960     DestroyWindow(hWnd2);
11961     DestroyWindow(hWnd3);
11962     SetClipboardViewer(hOrigViewer);
11963 }
11964
11965 static void test_PostMessage(void)
11966 {
11967     static const struct
11968     {
11969         HWND hwnd;
11970         BOOL ret;
11971     } data[] =
11972     {
11973         { HWND_TOP /* 0 */, TRUE },
11974         { HWND_BROADCAST, TRUE },
11975         { HWND_BOTTOM, TRUE },
11976         { HWND_TOPMOST, TRUE },
11977         { HWND_NOTOPMOST, FALSE },
11978         { HWND_MESSAGE, FALSE },
11979         { (HWND)0xdeadbeef, FALSE }
11980     };
11981     int i;
11982     HWND hwnd;
11983     BOOL ret;
11984     MSG msg;
11985     static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
11986
11987     SetLastError(0xdeadbeef);
11988     hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
11989     if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
11990     {
11991         win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
11992         return;
11993     }
11994     assert(hwnd);
11995
11996     flush_events();
11997
11998     PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
11999     PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12000
12001     for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12002     {
12003         memset(&msg, 0xab, sizeof(msg));
12004         ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12005         ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12006         if (data[i].ret)
12007         {
12008             if (data[i].hwnd)
12009                 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12010                    msg.wParam == 0x5678 && msg.lParam == 0x1234,
12011                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12012                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12013             else
12014                 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12015                    msg.wParam == 0x1234 && msg.lParam == 0x5678,
12016                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12017                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12018         }
12019     }
12020
12021     DestroyWindow(hwnd);
12022     flush_events();
12023 }
12024
12025 static const struct
12026 {
12027     DWORD exp, broken;
12028     BOOL todo;
12029 } wait_idle_expect[] =
12030 {
12031 /* 0 */  { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12032          { WAIT_TIMEOUT, 0,            FALSE },
12033          { WAIT_TIMEOUT, 0,            FALSE },
12034          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12035          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12036 /* 5 */  { WAIT_TIMEOUT, 0,            FALSE },
12037          { WAIT_TIMEOUT, 0,            FALSE },
12038          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12039          { 0,            0,            FALSE },
12040          { 0,            0,            FALSE },
12041 /* 10 */ { 0,            0,            FALSE },
12042          { 0,            0,            FALSE },
12043          { 0,            WAIT_TIMEOUT, FALSE },
12044          { 0,            0,            FALSE },
12045 };
12046
12047 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12048 {
12049     MSG msg;
12050
12051     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12052     Sleep( 200 );
12053     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12054     return 0;
12055 }
12056
12057 static void do_wait_idle_child( int arg )
12058 {
12059     WNDCLASS cls;
12060     MSG msg;
12061     HWND hwnd = 0;
12062     HANDLE thread;
12063     DWORD id;
12064     HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12065     HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12066
12067     memset( &cls, 0, sizeof(cls) );
12068     cls.lpfnWndProc   = DefWindowProc;
12069     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12070     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12071     cls.lpszClassName = "TestClass";
12072     RegisterClass( &cls );
12073
12074     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* create the msg queue */
12075
12076     ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12077     ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12078
12079     switch (arg)
12080     {
12081     case 0:
12082         SetEvent( start_event );
12083         break;
12084     case 1:
12085         SetEvent( start_event );
12086         Sleep( 200 );
12087         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12088         break;
12089     case 2:
12090         SetEvent( start_event );
12091         Sleep( 200 );
12092         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12093         PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12094         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12095         break;
12096     case 3:
12097         SetEvent( start_event );
12098         Sleep( 200 );
12099         SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12100         break;
12101     case 4:
12102         SetEvent( start_event );
12103         Sleep( 200 );
12104         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12105         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12106         break;
12107     case 5:
12108         SetEvent( start_event );
12109         Sleep( 200 );
12110         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12111         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12112         break;
12113     case 6:
12114         SetEvent( start_event );
12115         Sleep( 200 );
12116         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12117         while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12118         {
12119             GetMessage( &msg, 0, 0, 0 );
12120             DispatchMessage( &msg );
12121         }
12122         break;
12123     case 7:
12124         SetEvent( start_event );
12125         Sleep( 200 );
12126         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12127         SetTimer( hwnd, 3, 1, NULL );
12128         Sleep( 200 );
12129         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12130         break;
12131     case 8:
12132         SetEvent( start_event );
12133         Sleep( 200 );
12134         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12135         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12136         break;
12137     case 9:
12138         SetEvent( start_event );
12139         Sleep( 200 );
12140         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12141         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12142         for (;;) GetMessage( &msg, 0, 0, 0 );
12143         break;
12144     case 10:
12145         SetEvent( start_event );
12146         Sleep( 200 );
12147         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12148         SetTimer( hwnd, 3, 1, NULL );
12149         Sleep( 200 );
12150         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12151         break;
12152     case 11:
12153         SetEvent( start_event );
12154         Sleep( 200 );
12155         return;  /* exiting the process makes WaitForInputIdle return success too */
12156     case 12:
12157         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12158         Sleep( 200 );
12159         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12160         SetEvent( start_event );
12161         break;
12162     case 13:
12163         SetEvent( start_event );
12164         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12165         Sleep( 200 );
12166         thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12167         WaitForSingleObject( thread, 10000 );
12168         CloseHandle( thread );
12169         break;
12170     }
12171     WaitForSingleObject( end_event, 2000 );
12172     CloseHandle( start_event );
12173     CloseHandle( end_event );
12174     if (hwnd) DestroyWindow( hwnd );
12175 }
12176
12177 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12178 {
12179     if (msg == WM_WININICHANGE) Sleep( 200 );  /* make sure the child waits */
12180     return DefWindowProcA( hwnd, msg, wp, lp );
12181 }
12182
12183 static DWORD CALLBACK wait_idle_thread( void *arg )
12184 {
12185     WNDCLASS cls;
12186     MSG msg;
12187     HWND hwnd;
12188
12189     memset( &cls, 0, sizeof(cls) );
12190     cls.lpfnWndProc   = wait_idle_proc;
12191     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12192     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12193     cls.lpszClassName = "TestClass";
12194     RegisterClass( &cls );
12195
12196     hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12197     while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12198     return 0;
12199 }
12200
12201 static void test_WaitForInputIdle( char *argv0 )
12202 {
12203     char path[MAX_PATH];
12204     PROCESS_INFORMATION pi;
12205     STARTUPINFOA startup;
12206     BOOL ret;
12207     HANDLE start_event, end_event, thread;
12208     unsigned int i;
12209     DWORD id;
12210     const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12211     const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12212     BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12213
12214     if (console_app)  /* build the test with -mwindows for better coverage */
12215         trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12216
12217     start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12218     end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12219     ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12220     ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12221
12222     memset( &startup, 0, sizeof(startup) );
12223     startup.cb = sizeof(startup);
12224     startup.dwFlags = STARTF_USESHOWWINDOW;
12225     startup.wShowWindow = SW_SHOWNORMAL;
12226
12227     thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12228
12229     for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12230     {
12231         ResetEvent( start_event );
12232         ResetEvent( end_event );
12233         sprintf( path, "%s msg %u", argv0, i );
12234         ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12235         ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12236         if (ret)
12237         {
12238             ret = WaitForSingleObject( start_event, 5000 );
12239             ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12240             if (ret == WAIT_OBJECT_0)
12241             {
12242                 ret = WaitForInputIdle( pi.hProcess, 1000 );
12243                 if (ret == WAIT_FAILED)
12244                     ok( console_app ||
12245                         ret == wait_idle_expect[i].exp ||
12246                         broken(ret == wait_idle_expect[i].broken),
12247                         "%u: WaitForInputIdle error %08x expected %08x\n",
12248                         i, ret, wait_idle_expect[i].exp );
12249                 else if (wait_idle_expect[i].todo)
12250                     todo_wine
12251                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12252                         "%u: WaitForInputIdle error %08x expected %08x\n",
12253                         i, ret, wait_idle_expect[i].exp );
12254                 else
12255                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12256                         "%u: WaitForInputIdle error %08x expected %08x\n",
12257                         i, ret, wait_idle_expect[i].exp );
12258                 SetEvent( end_event );
12259                 WaitForSingleObject( pi.hProcess, 1000 );  /* give it a chance to exit on its own */
12260             }
12261             TerminateProcess( pi.hProcess, 0 );  /* just in case */
12262             winetest_wait_child_process( pi.hProcess );
12263             ret = WaitForInputIdle( pi.hProcess, 100 );
12264             ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12265             CloseHandle( pi.hProcess );
12266             CloseHandle( pi.hThread );
12267         }
12268     }
12269     CloseHandle( start_event );
12270     PostThreadMessage( id, WM_QUIT, 0, 0 );
12271     WaitForSingleObject( thread, 10000 );
12272     CloseHandle( thread );
12273 }
12274
12275 START_TEST(msg)
12276 {
12277     char **test_argv;
12278     BOOL ret;
12279     BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12280
12281     int argc = winetest_get_mainargs( &test_argv );
12282     if (argc >= 3)
12283     {
12284         unsigned int arg;
12285         /* Child process. */
12286         sscanf (test_argv[2], "%d", (unsigned int *) &arg);
12287         do_wait_idle_child( arg );
12288         return;
12289     }
12290
12291     init_procs();
12292
12293     if (!RegisterWindowClasses()) assert(0);
12294
12295     if (pSetWinEventHook)
12296     {
12297         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12298                                        GetModuleHandleA(0), win_event_proc,
12299                                        0, GetCurrentThreadId(),
12300                                        WINEVENT_INCONTEXT);
12301         if (pIsWinEventHookInstalled && hEvent_hook)
12302         {
12303             UINT event;
12304             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12305                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12306         }
12307     }
12308     if (!hEvent_hook) win_skip( "no win event hook support\n" );
12309
12310     cbt_hook_thread_id = GetCurrentThreadId();
12311     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12312     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12313
12314     test_winevents();
12315
12316     /* Fix message sequences before removing 4 lines below */
12317 #if 1
12318     if (pUnhookWinEvent && hEvent_hook)
12319     {
12320         ret = pUnhookWinEvent(hEvent_hook);
12321         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12322         pUnhookWinEvent = 0;
12323     }
12324     hEvent_hook = 0;
12325 #endif
12326
12327     test_PostMessage();
12328     test_ShowWindow();
12329     test_PeekMessage();
12330     test_PeekMessage2();
12331     test_WaitForInputIdle( test_argv[0] );
12332     test_scrollwindowex();
12333     test_messages();
12334     test_setwindowpos();
12335     test_showwindow();
12336     invisible_parent_tests();
12337     test_mdi_messages();
12338     test_button_messages();
12339     test_static_messages();
12340     test_listbox_messages();
12341     test_combobox_messages();
12342     test_wmime_keydown_message();
12343     test_paint_messages();
12344     test_interthread_messages();
12345     test_message_conversion();
12346     test_accelerators();
12347     test_timers();
12348     test_timers_no_wnd();
12349     if (hCBT_hook) test_set_hook();
12350     test_DestroyWindow();
12351     test_DispatchMessage();
12352     test_SendMessageTimeout();
12353     test_edit_messages();
12354     test_quit_message();
12355     test_SetActiveWindow();
12356
12357     if (!pTrackMouseEvent)
12358         win_skip("TrackMouseEvent is not available\n");
12359     else
12360         test_TrackMouseEvent();
12361
12362     test_SetWindowRgn();
12363     test_sys_menu();
12364     test_dialog_messages();
12365     test_nullCallback();
12366     test_dbcs_wm_char();
12367     test_menu_messages();
12368     test_paintingloop();
12369     test_defwinproc();
12370     test_clipboard_viewers();
12371     /* keep it the last test, under Windows it tends to break the tests
12372      * which rely on active/foreground windows being correct.
12373      */
12374     test_SetForegroundWindow();
12375
12376     UnhookWindowsHookEx(hCBT_hook);
12377     if (pUnhookWinEvent && hEvent_hook)
12378     {
12379         ret = pUnhookWinEvent(hEvent_hook);
12380         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12381         SetLastError(0xdeadbeef);
12382         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12383         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12384            GetLastError() == 0xdeadbeef, /* Win9x */
12385            "unexpected error %d\n", GetLastError());
12386     }
12387 }