user32/tests: Add test for Shift+F10.
[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, -1 },
6873     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -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 static const struct message WmShiftF10Seq[] = {
6907     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6908     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6909     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
6910     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6911     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
6912     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
6913     { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, MAKELPARAM(-1, -1) },
6914     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6915     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6916     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6917     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
6918     { HCBT_SYSCOMMAND, hook },
6919     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6920     { WM_INITMENU, sent|defwinproc },
6921     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6922     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
6923     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
6924     { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
6925     { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
6926     { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6927     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
6928     { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
6929     { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
6930     { 0 }
6931 };
6932
6933 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6934 {
6935     MSG msg;
6936
6937     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6938     {
6939         struct recvd_message log_msg;
6940
6941         /* ignore some unwanted messages */
6942         if (msg.message == WM_MOUSEMOVE ||
6943             msg.message == WM_TIMER ||
6944             ignore_message( msg.message ))
6945             continue;
6946
6947         log_msg.hwnd = msg.hwnd;
6948         log_msg.message = msg.message;
6949         log_msg.flags = wparam|lparam;
6950         log_msg.wParam = msg.wParam;
6951         log_msg.lParam = msg.lParam;
6952         log_msg.descr = "accel";
6953         add_message(&log_msg);
6954
6955         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6956         {
6957             TranslateMessage(&msg);
6958             DispatchMessage(&msg);
6959         }
6960     }
6961 }
6962
6963 static void test_accelerators(void)
6964 {
6965     RECT rc;
6966     POINT pt;
6967     SHORT state;
6968     HACCEL hAccel;
6969     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6970                                 100, 100, 200, 200, 0, 0, 0, NULL);
6971     BOOL ret;
6972
6973     assert(hwnd != 0);
6974     UpdateWindow(hwnd);
6975     flush_events();
6976     flush_sequence();
6977
6978     SetFocus(hwnd);
6979     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6980
6981     state = GetKeyState(VK_SHIFT);
6982     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6983     state = GetKeyState(VK_CAPITAL);
6984     ok(state == 0, "wrong CapsLock state %04x\n", state);
6985
6986     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6987     assert(hAccel != 0);
6988
6989     flush_events();
6990     pump_msg_loop(hwnd, 0);
6991     flush_sequence();
6992
6993     trace("testing VK_N press/release\n");
6994     flush_sequence();
6995     keybd_event('N', 0, 0, 0);
6996     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6997     pump_msg_loop(hwnd, hAccel);
6998     if (!sequence_cnt)  /* we didn't get any message */
6999     {
7000         skip( "queuing key events not supported\n" );
7001         goto done;
7002     }
7003     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7004
7005     trace("testing Shift+VK_N press/release\n");
7006     flush_sequence();
7007     keybd_event(VK_SHIFT, 0, 0, 0);
7008     keybd_event('N', 0, 0, 0);
7009     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7010     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7011     pump_msg_loop(hwnd, hAccel);
7012     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7013
7014     trace("testing Ctrl+VK_N press/release\n");
7015     flush_sequence();
7016     keybd_event(VK_CONTROL, 0, 0, 0);
7017     keybd_event('N', 0, 0, 0);
7018     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7019     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7020     pump_msg_loop(hwnd, hAccel);
7021     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7022
7023     trace("testing Alt+VK_N press/release\n");
7024     flush_sequence();
7025     keybd_event(VK_MENU, 0, 0, 0);
7026     keybd_event('N', 0, 0, 0);
7027     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7028     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7029     pump_msg_loop(hwnd, hAccel);
7030     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7031
7032     trace("testing Ctrl+Alt+VK_N press/release 1\n");
7033     flush_sequence();
7034     keybd_event(VK_CONTROL, 0, 0, 0);
7035     keybd_event(VK_MENU, 0, 0, 0);
7036     keybd_event('N', 0, 0, 0);
7037     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7038     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7039     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7040     pump_msg_loop(hwnd, hAccel);
7041     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7042
7043     ret = DestroyAcceleratorTable(hAccel);
7044     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7045
7046     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7047     assert(hAccel != 0);
7048
7049     trace("testing VK_N press/release\n");
7050     flush_sequence();
7051     keybd_event('N', 0, 0, 0);
7052     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7053     pump_msg_loop(hwnd, hAccel);
7054     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7055
7056     trace("testing Shift+VK_N press/release\n");
7057     flush_sequence();
7058     keybd_event(VK_SHIFT, 0, 0, 0);
7059     keybd_event('N', 0, 0, 0);
7060     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7061     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7062     pump_msg_loop(hwnd, hAccel);
7063     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7064
7065     trace("testing Ctrl+VK_N press/release 2\n");
7066     flush_sequence();
7067     keybd_event(VK_CONTROL, 0, 0, 0);
7068     keybd_event('N', 0, 0, 0);
7069     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7070     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7071     pump_msg_loop(hwnd, hAccel);
7072     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7073
7074     trace("testing Alt+VK_N press/release 2\n");
7075     flush_sequence();
7076     keybd_event(VK_MENU, 0, 0, 0);
7077     keybd_event('N', 0, 0, 0);
7078     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7079     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7080     pump_msg_loop(hwnd, hAccel);
7081     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7082
7083     trace("testing Ctrl+Alt+VK_N press/release 2\n");
7084     flush_sequence();
7085     keybd_event(VK_CONTROL, 0, 0, 0);
7086     keybd_event(VK_MENU, 0, 0, 0);
7087     keybd_event('N', 0, 0, 0);
7088     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7089     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7090     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7091     pump_msg_loop(hwnd, hAccel);
7092     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7093
7094     trace("testing Ctrl+Shift+VK_N press/release\n");
7095     flush_sequence();
7096     keybd_event(VK_CONTROL, 0, 0, 0);
7097     keybd_event(VK_SHIFT, 0, 0, 0);
7098     keybd_event('N', 0, 0, 0);
7099     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7100     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7101     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7102     pump_msg_loop(hwnd, hAccel);
7103     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7104
7105     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7106     flush_sequence();
7107     keybd_event(VK_CONTROL, 0, 0, 0);
7108     keybd_event(VK_MENU, 0, 0, 0);
7109     keybd_event(VK_SHIFT, 0, 0, 0);
7110     keybd_event('N', 0, 0, 0);
7111     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7112     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7113     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7114     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7115     pump_msg_loop(hwnd, hAccel);
7116     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7117
7118     ret = DestroyAcceleratorTable(hAccel);
7119     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7120     hAccel = 0;
7121
7122     trace("testing Alt press/release\n");
7123     flush_sequence();
7124     keybd_event(VK_MENU, 0, 0, 0);
7125     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7126     keybd_event(VK_MENU, 0, 0, 0);
7127     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7128     pump_msg_loop(hwnd, 0);
7129     /* this test doesn't pass in Wine for managed windows */
7130     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7131
7132     trace("testing VK_F1 press/release\n");
7133     keybd_event(VK_F1, 0, 0, 0);
7134     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7135     pump_msg_loop(hwnd, 0);
7136     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7137
7138     trace("testing VK_APPS press/release\n");
7139     keybd_event(VK_APPS, 0, 0, 0);
7140     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7141     pump_msg_loop(hwnd, 0);
7142     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7143
7144     trace("testing VK_F10 press/release\n");
7145     keybd_event(VK_F10, 0, 0, 0);
7146     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7147     keybd_event(VK_F10, 0, 0, 0);
7148     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7149     pump_msg_loop(hwnd, 0);
7150     ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7151
7152     trace("testing SHIFT+F10 press/release\n");
7153     keybd_event(VK_SHIFT, 0, 0, 0);
7154     keybd_event(VK_F10, 0, 0, 0);
7155     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7156     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7157     keybd_event(VK_ESCAPE, 0, 0, 0);
7158     keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7159     pump_msg_loop(hwnd, 0);
7160     ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7161
7162     trace("testing Shift+MouseButton press/release\n");
7163     /* first, move mouse pointer inside of the window client area */
7164     GetClientRect(hwnd, &rc);
7165     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7166     rc.left += (rc.right - rc.left)/2;
7167     rc.top += (rc.bottom - rc.top)/2;
7168     SetCursorPos(rc.left, rc.top);
7169     SetActiveWindow(hwnd);
7170
7171     flush_events();
7172     flush_sequence();
7173     GetCursorPos(&pt);
7174     if (pt.x == rc.left && pt.y == rc.top)
7175     {
7176         int i;
7177         keybd_event(VK_SHIFT, 0, 0, 0);
7178         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7179         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7180         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7181         pump_msg_loop(hwnd, 0);
7182         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7183         if (i < sequence_cnt)
7184             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7185         else
7186             skip( "Shift+MouseButton event didn't get to the window\n" );
7187     }
7188
7189 done:
7190     if (hAccel) DestroyAcceleratorTable(hAccel);
7191     DestroyWindow(hwnd);
7192 }
7193
7194 /************* window procedures ********************/
7195
7196 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
7197                              WPARAM wParam, LPARAM lParam)
7198 {
7199     static LONG defwndproc_counter = 0;
7200     static LONG beginpaint_counter = 0;
7201     LRESULT ret;
7202     struct recvd_message msg;
7203
7204     if (ignore_message( message )) return 0;
7205
7206     switch (message)
7207     {
7208         case WM_ENABLE:
7209         {
7210             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7211             ok((BOOL)wParam == !(style & WS_DISABLED),
7212                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7213             break;
7214         }
7215
7216         case WM_CAPTURECHANGED:
7217             if (test_DestroyWindow_flag)
7218             {
7219                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7220                 if (style & WS_CHILD)
7221                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7222                 else if (style & WS_POPUP)
7223                     lParam = WND_POPUP_ID;
7224                 else
7225                     lParam = WND_PARENT_ID;
7226             }
7227             break;
7228
7229         case WM_NCDESTROY:
7230         {
7231             HWND capture;
7232
7233             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7234             capture = GetCapture();
7235             if (capture)
7236             {
7237                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7238                 trace("current capture %p, releasing...\n", capture);
7239                 ReleaseCapture();
7240             }
7241         }
7242         /* fall through */
7243         case WM_DESTROY:
7244             if (pGetAncestor)
7245                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7246             if (test_DestroyWindow_flag)
7247             {
7248                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7249                 if (style & WS_CHILD)
7250                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7251                 else if (style & WS_POPUP)
7252                     lParam = WND_POPUP_ID;
7253                 else
7254                     lParam = WND_PARENT_ID;
7255             }
7256             break;
7257
7258         /* test_accelerators() depends on this */
7259         case WM_NCHITTEST:
7260             return HTCLIENT;
7261
7262         /* ignore */
7263         case WM_MOUSEMOVE:
7264         case WM_MOUSEACTIVATE:
7265         case WM_NCMOUSEMOVE:
7266         case WM_SETCURSOR:
7267         case WM_IME_SELECT:
7268             return 0;
7269     }
7270
7271     msg.hwnd = hwnd;
7272     msg.message = message;
7273     msg.flags = sent|wparam|lparam;
7274     if (defwndproc_counter) msg.flags |= defwinproc;
7275     if (beginpaint_counter) msg.flags |= beginpaint;
7276     msg.wParam = wParam;
7277     msg.lParam = lParam;
7278     msg.descr = "MsgCheckProc";
7279     add_message(&msg);
7280
7281     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7282     {
7283         HWND parent = GetParent(hwnd);
7284         RECT rc;
7285         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7286
7287         GetClientRect(parent, &rc);
7288         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7289         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7290               minmax->ptReserved.x, minmax->ptReserved.y,
7291               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7292               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7293               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7294               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7295
7296         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7297            minmax->ptMaxSize.x, rc.right);
7298         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7299            minmax->ptMaxSize.y, rc.bottom);
7300     }
7301
7302     if (message == WM_PAINT)
7303     {
7304         PAINTSTRUCT ps;
7305         beginpaint_counter++;
7306         BeginPaint( hwnd, &ps );
7307         beginpaint_counter--;
7308         EndPaint( hwnd, &ps );
7309         return 0;
7310     }
7311
7312     defwndproc_counter++;
7313     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
7314                   : DefWindowProcA(hwnd, message, wParam, lParam);
7315     defwndproc_counter--;
7316
7317     return ret;
7318 }
7319
7320 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7321 {
7322     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7323 }
7324
7325 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7326 {
7327     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7328 }
7329
7330 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7331 {
7332     static LONG defwndproc_counter = 0;
7333     LRESULT ret;
7334     struct recvd_message msg;
7335
7336     if (ignore_message( message )) return 0;
7337
7338     switch (message)
7339     {
7340     case WM_QUERYENDSESSION:
7341     case WM_ENDSESSION:
7342         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7343         break;
7344     }
7345
7346     msg.hwnd = hwnd;
7347     msg.message = message;
7348     msg.flags = sent|wparam|lparam;
7349     if (defwndproc_counter) msg.flags |= defwinproc;
7350     msg.wParam = wParam;
7351     msg.lParam = lParam;
7352     msg.descr = "popup";
7353     add_message(&msg);
7354
7355     if (message == WM_CREATE)
7356     {
7357         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7358         SetWindowLongA(hwnd, GWL_STYLE, style);
7359     }
7360
7361     defwndproc_counter++;
7362     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7363     defwndproc_counter--;
7364
7365     return ret;
7366 }
7367
7368 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7369 {
7370     static LONG defwndproc_counter = 0;
7371     static LONG beginpaint_counter = 0;
7372     LRESULT ret;
7373     struct recvd_message msg;
7374
7375     if (ignore_message( message )) return 0;
7376
7377     if (log_all_parent_messages ||
7378         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7379         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7380         message == WM_ENABLE || message == WM_ENTERIDLE ||
7381         message == WM_DRAWITEM || message == WM_COMMAND ||
7382         message == WM_IME_SETCONTEXT)
7383     {
7384         switch (message)
7385         {
7386             /* ignore */
7387             case WM_NCHITTEST:
7388                 return HTCLIENT;
7389             case WM_SETCURSOR:
7390             case WM_MOUSEMOVE:
7391             case WM_NCMOUSEMOVE:
7392                 return 0;
7393
7394             case WM_ERASEBKGND:
7395             {
7396                 RECT rc;
7397                 INT ret = GetClipBox((HDC)wParam, &rc);
7398
7399                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7400                        ret, rc.left, rc.top, rc.right, rc.bottom);
7401                 break;
7402             }
7403         }
7404
7405         msg.hwnd = hwnd;
7406         msg.message = message;
7407         msg.flags = sent|parent|wparam|lparam;
7408         if (defwndproc_counter) msg.flags |= defwinproc;
7409         if (beginpaint_counter) msg.flags |= beginpaint;
7410         msg.wParam = wParam;
7411         msg.lParam = lParam;
7412         msg.descr = "parent";
7413         add_message(&msg);
7414     }
7415
7416     if (message == WM_PAINT)
7417     {
7418         PAINTSTRUCT ps;
7419         beginpaint_counter++;
7420         BeginPaint( hwnd, &ps );
7421         beginpaint_counter--;
7422         EndPaint( hwnd, &ps );
7423         return 0;
7424     }
7425
7426     defwndproc_counter++;
7427     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7428     defwndproc_counter--;
7429
7430     return ret;
7431 }
7432
7433 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7434 {
7435     static LONG defwndproc_counter = 0;
7436     LRESULT ret;
7437     struct recvd_message msg;
7438
7439     if (ignore_message( message )) return 0;
7440
7441     if (test_def_id)
7442     {
7443         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7444         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7445         if (after_end_dialog)
7446             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7447         else
7448             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7449     }
7450
7451     msg.hwnd = hwnd;
7452     msg.message = message;
7453     msg.flags = sent|wparam|lparam;
7454     if (defwndproc_counter) msg.flags |= defwinproc;
7455     msg.wParam = wParam;
7456     msg.lParam = lParam;
7457     msg.descr = "dialog";
7458     add_message(&msg);
7459
7460     defwndproc_counter++;
7461     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7462     defwndproc_counter--;
7463
7464     return ret;
7465 }
7466
7467 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7468 {
7469     static LONG defwndproc_counter = 0;
7470     LRESULT ret;
7471     struct recvd_message msg;
7472
7473     /* log only specific messages we are interested in */
7474     switch (message)
7475     {
7476 #if 0 /* probably log these as well */
7477     case WM_ACTIVATE:
7478     case WM_SETFOCUS:
7479     case WM_KILLFOCUS:
7480 #endif
7481     case WM_SHOWWINDOW:
7482     case WM_SIZE:
7483     case WM_MOVE:
7484     case WM_GETMINMAXINFO:
7485     case WM_WINDOWPOSCHANGING:
7486     case WM_WINDOWPOSCHANGED:
7487         break;
7488
7489     default: /* ignore */
7490         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7491         return DefWindowProcA(hwnd, message, wParam, lParam);
7492     }
7493
7494     msg.hwnd = hwnd;
7495     msg.message = message;
7496     msg.flags = sent|wparam|lparam;
7497     if (defwndproc_counter) msg.flags |= defwinproc;
7498     msg.wParam = wParam;
7499     msg.lParam = lParam;
7500     msg.descr = "show";
7501     add_message(&msg);
7502
7503     defwndproc_counter++;
7504     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7505     defwndproc_counter--;
7506
7507     return ret;
7508 }
7509
7510 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7511 {
7512     switch (msg)
7513     {
7514         case WM_CREATE: return 0;
7515         case WM_PAINT:
7516         {
7517             MSG msg2;
7518             static int i = 0;
7519
7520             if (i < 256)
7521             {
7522                 i++;
7523                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7524                 {
7525                     TranslateMessage(&msg2);
7526                     DispatchMessage(&msg2);
7527                 }
7528                 i--;
7529             }
7530             else ok(broken(1), "infinite loop\n");
7531             if ( i == 0)
7532                 paint_loop_done = 1;
7533             return DefWindowProcA(hWnd,msg,wParam,lParam);
7534         }
7535     }
7536     return DefWindowProcA(hWnd,msg,wParam,lParam);
7537 }
7538
7539 static BOOL RegisterWindowClasses(void)
7540 {
7541     WNDCLASSA cls;
7542     WNDCLASSW clsW;
7543
7544     cls.style = 0;
7545     cls.lpfnWndProc = MsgCheckProcA;
7546     cls.cbClsExtra = 0;
7547     cls.cbWndExtra = 0;
7548     cls.hInstance = GetModuleHandleA(0);
7549     cls.hIcon = 0;
7550     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7551     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7552     cls.lpszMenuName = NULL;
7553     cls.lpszClassName = "TestWindowClass";
7554     if(!RegisterClassA(&cls)) return FALSE;
7555
7556     cls.lpfnWndProc = ShowWindowProcA;
7557     cls.lpszClassName = "ShowWindowClass";
7558     if(!RegisterClassA(&cls)) return FALSE;
7559
7560     cls.lpfnWndProc = PopupMsgCheckProcA;
7561     cls.lpszClassName = "TestPopupClass";
7562     if(!RegisterClassA(&cls)) return FALSE;
7563
7564     cls.lpfnWndProc = ParentMsgCheckProcA;
7565     cls.lpszClassName = "TestParentClass";
7566     if(!RegisterClassA(&cls)) return FALSE;
7567
7568     cls.lpfnWndProc = DefWindowProcA;
7569     cls.lpszClassName = "SimpleWindowClass";
7570     if(!RegisterClassA(&cls)) return FALSE;
7571
7572     cls.lpfnWndProc = PaintLoopProcA;
7573     cls.lpszClassName = "PaintLoopWindowClass";
7574     if(!RegisterClassA(&cls)) return FALSE;
7575
7576     cls.style = CS_NOCLOSE;
7577     cls.lpszClassName = "NoCloseWindowClass";
7578     if(!RegisterClassA(&cls)) return FALSE;
7579
7580     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7581     cls.style = 0;
7582     cls.hInstance = GetModuleHandleA(0);
7583     cls.hbrBackground = 0;
7584     cls.lpfnWndProc = TestDlgProcA;
7585     cls.lpszClassName = "TestDialogClass";
7586     if(!RegisterClassA(&cls)) return FALSE;
7587
7588     clsW.style = 0;
7589     clsW.lpfnWndProc = MsgCheckProcW;
7590     clsW.cbClsExtra = 0;
7591     clsW.cbWndExtra = 0;
7592     clsW.hInstance = GetModuleHandleW(0);
7593     clsW.hIcon = 0;
7594     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7595     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7596     clsW.lpszMenuName = NULL;
7597     clsW.lpszClassName = testWindowClassW;
7598     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7599
7600     return TRUE;
7601 }
7602
7603 static BOOL is_our_logged_class(HWND hwnd)
7604 {
7605     char buf[256];
7606
7607     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7608     {
7609         if (!lstrcmpiA(buf, "TestWindowClass") ||
7610             !lstrcmpiA(buf, "ShowWindowClass") ||
7611             !lstrcmpiA(buf, "TestParentClass") ||
7612             !lstrcmpiA(buf, "TestPopupClass") ||
7613             !lstrcmpiA(buf, "SimpleWindowClass") ||
7614             !lstrcmpiA(buf, "TestDialogClass") ||
7615             !lstrcmpiA(buf, "MDI_frame_class") ||
7616             !lstrcmpiA(buf, "MDI_client_class") ||
7617             !lstrcmpiA(buf, "MDI_child_class") ||
7618             !lstrcmpiA(buf, "my_button_class") ||
7619             !lstrcmpiA(buf, "my_edit_class") ||
7620             !lstrcmpiA(buf, "static") ||
7621             !lstrcmpiA(buf, "ListBox") ||
7622             !lstrcmpiA(buf, "ComboBox") ||
7623             !lstrcmpiA(buf, "MyDialogClass") ||
7624             !lstrcmpiA(buf, "#32770") ||
7625             !lstrcmpiA(buf, "#32768"))
7626         return TRUE;
7627     }
7628     return FALSE;
7629 }
7630
7631 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7632
7633     HWND hwnd;
7634
7635     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7636
7637     if (nCode == HCBT_CLICKSKIPPED)
7638     {
7639         /* ignore this event, XP sends it a lot when switching focus between windows */
7640         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7641     }
7642
7643     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7644     {
7645         struct recvd_message msg;
7646
7647         msg.hwnd = 0;
7648         msg.message = nCode;
7649         msg.flags = hook|wparam|lparam;
7650         msg.wParam = wParam;
7651         msg.lParam = lParam;
7652         msg.descr = "CBT";
7653         add_message(&msg);
7654
7655         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7656     }
7657
7658     if (nCode == HCBT_DESTROYWND)
7659     {
7660         if (test_DestroyWindow_flag)
7661         {
7662             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7663             if (style & WS_CHILD)
7664                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7665             else if (style & WS_POPUP)
7666                 lParam = WND_POPUP_ID;
7667             else
7668                 lParam = WND_PARENT_ID;
7669         }
7670     }
7671
7672     /* Log also SetFocus(0) calls */
7673     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7674
7675     if (is_our_logged_class(hwnd))
7676     {
7677         struct recvd_message msg;
7678
7679         msg.hwnd = hwnd;
7680         msg.message = nCode;
7681         msg.flags = hook|wparam|lparam;
7682         msg.wParam = wParam;
7683         msg.lParam = lParam;
7684         msg.descr = "CBT";
7685         add_message(&msg);
7686     }
7687     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7688 }
7689
7690 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7691                                     DWORD event,
7692                                     HWND hwnd,
7693                                     LONG object_id,
7694                                     LONG child_id,
7695                                     DWORD thread_id,
7696                                     DWORD event_time)
7697 {
7698     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7699
7700     /* ignore mouse cursor events */
7701     if (object_id == OBJID_CURSOR) return;
7702
7703     if (!hwnd || is_our_logged_class(hwnd))
7704     {
7705         struct recvd_message msg;
7706
7707         msg.hwnd = hwnd;
7708         msg.message = event;
7709         msg.flags = winevent_hook|wparam|lparam;
7710         msg.wParam = object_id;
7711         msg.lParam = child_id;
7712         msg.descr = "WEH";
7713         add_message(&msg);
7714     }
7715 }
7716
7717 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7718 static const WCHAR wszAnsi[] = {'U',0};
7719
7720 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7721 {
7722     switch (uMsg)
7723     {
7724     case CB_FINDSTRINGEXACT:
7725         trace("String: %p\n", (LPCWSTR)lParam);
7726         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7727             return 1;
7728         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7729             return 0;
7730         return -1;
7731     }
7732     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7733 }
7734
7735 static const struct message WmGetTextLengthAfromW[] = {
7736     { WM_GETTEXTLENGTH, sent },
7737     { WM_GETTEXT, sent|optional },
7738     { 0 }
7739 };
7740
7741 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7742
7743 /* dummy window proc for WM_GETTEXTLENGTH test */
7744 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7745 {
7746     switch(msg)
7747     {
7748     case WM_GETTEXTLENGTH:
7749         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7750     case WM_GETTEXT:
7751         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7752         return lstrlenW( (LPWSTR)lp );
7753     default:
7754         return DefWindowProcW( hwnd, msg, wp, lp );
7755     }
7756 }
7757
7758 static void test_message_conversion(void)
7759 {
7760     static const WCHAR wszMsgConversionClass[] =
7761         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7762     WNDCLASSW cls;
7763     LRESULT lRes;
7764     HWND hwnd;
7765     WNDPROC wndproc, newproc;
7766     BOOL ret;
7767
7768     cls.style = 0;
7769     cls.lpfnWndProc = MsgConversionProcW;
7770     cls.cbClsExtra = 0;
7771     cls.cbWndExtra = 0;
7772     cls.hInstance = GetModuleHandleW(NULL);
7773     cls.hIcon = NULL;
7774     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7775     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7776     cls.lpszMenuName = NULL;
7777     cls.lpszClassName = wszMsgConversionClass;
7778     /* this call will fail on Win9x, but that doesn't matter as this test is
7779      * meaningless on those platforms */
7780     if(!RegisterClassW(&cls)) return;
7781
7782     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7783                            100, 100, 200, 200, 0, 0, 0, NULL);
7784     ok(hwnd != NULL, "Window creation failed\n");
7785
7786     /* {W, A} -> A */
7787
7788     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7789     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7790     ok(lRes == 0, "String should have been converted\n");
7791     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7792     ok(lRes == 1, "String shouldn't have been converted\n");
7793
7794     /* {W, A} -> W */
7795
7796     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7797     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7798     ok(lRes == 1, "String shouldn't have been converted\n");
7799     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7800     ok(lRes == 1, "String shouldn't have been converted\n");
7801
7802     /* Synchronous messages */
7803
7804     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7805     ok(lRes == 0, "String should have been converted\n");
7806     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7807     ok(lRes == 1, "String shouldn't have been converted\n");
7808
7809     /* Asynchronous messages */
7810
7811     SetLastError(0);
7812     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7813     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7814         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7815     SetLastError(0);
7816     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7817     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7818         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7819     SetLastError(0);
7820     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7821     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7822         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7823     SetLastError(0);
7824     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7825     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7826         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7827     SetLastError(0);
7828     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7829     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7830         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7831     SetLastError(0);
7832     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7833     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7834         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7835     SetLastError(0);
7836     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7837     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7838         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7839     SetLastError(0);
7840     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7841     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7842         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7843
7844     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7845
7846     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7847                           WS_OVERLAPPEDWINDOW,
7848                           100, 100, 200, 200, 0, 0, 0, NULL);
7849     assert(hwnd);
7850     flush_sequence();
7851     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7852     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7853     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7854         "got bad length %ld\n", lRes );
7855
7856     flush_sequence();
7857     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7858                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7859     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7860     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7861         "got bad length %ld\n", lRes );
7862
7863     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7864     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7865     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7866     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7867                                      NULL, 0, NULL, NULL ) ||
7868         broken(lRes == lstrlenW(dummy_window_text) + 37),
7869         "got bad length %ld\n", lRes );
7870
7871     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7872     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7873     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7874                                      NULL, 0, NULL, NULL ) ||
7875         broken(lRes == lstrlenW(dummy_window_text) + 37),
7876         "got bad length %ld\n", lRes );
7877
7878     ret = DestroyWindow(hwnd);
7879     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7880 }
7881
7882 struct timer_info
7883 {
7884     HWND hWnd;
7885     HANDLE handles[2];
7886     DWORD id;
7887 };
7888
7889 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7890 {
7891 }
7892
7893 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7894 {
7895     /* Crash on purpose */
7896     *(volatile int *)0 = 2;
7897 }
7898
7899 #define TIMER_ID  0x19
7900
7901 static DWORD WINAPI timer_thread_proc(LPVOID x)
7902 {
7903     struct timer_info *info = x;
7904     DWORD r;
7905
7906     r = KillTimer(info->hWnd, 0x19);
7907     ok(r,"KillTimer failed in thread\n");
7908     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7909     ok(r,"SetTimer failed in thread\n");
7910     ok(r==TIMER_ID,"SetTimer id different\n");
7911     r = SetEvent(info->handles[0]);
7912     ok(r,"SetEvent failed in thread\n");
7913     return 0;
7914 }
7915
7916 static void test_timers(void)
7917 {
7918     struct timer_info info;
7919     DWORD id;
7920     MSG msg;
7921
7922     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7923        WS_OVERLAPPEDWINDOW ,
7924        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7925        NULL, NULL, 0);
7926
7927     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7928     ok(info.id, "SetTimer failed\n");
7929     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7930     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7931     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7932
7933     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7934
7935     WaitForSingleObject(info.handles[1], INFINITE);
7936
7937     CloseHandle(info.handles[0]);
7938     CloseHandle(info.handles[1]);
7939
7940     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7941
7942     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7943
7944     /* Test timer callback with crash */
7945     SetLastError(0xdeadbeef);
7946     info.hWnd = CreateWindowW(testWindowClassW, NULL,
7947                               WS_OVERLAPPEDWINDOW ,
7948                               CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7949                               NULL, NULL, 0);
7950     if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
7951         (!pGetMenuInfo)) /* Win95/NT4 */
7952     {
7953         win_skip("Test would crash on Win9x/WinMe/NT4\n");
7954         DestroyWindow(info.hWnd);
7955         return;
7956     }
7957     info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
7958     ok(info.id, "SetTimer failed\n");
7959     Sleep(150);
7960     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7961
7962     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7963 }
7964
7965 static int count = 0;
7966 static VOID CALLBACK callback_count(
7967     HWND hwnd,
7968     UINT uMsg,
7969     UINT_PTR idEvent,
7970     DWORD dwTime
7971 )
7972 {
7973     count++;
7974 }
7975
7976 static void test_timers_no_wnd(void)
7977 {
7978     UINT_PTR id, id2;
7979     MSG msg;
7980
7981     count = 0;
7982     id = SetTimer(NULL, 0, 100, callback_count);
7983     ok(id != 0, "did not get id from SetTimer.\n");
7984     id2 = SetTimer(NULL, id, 200, callback_count);
7985     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7986     Sleep(150);
7987     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7988     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7989     Sleep(150);
7990     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7991     ok(count == 1, "did not get one count as expected (%i).\n", count);
7992     KillTimer(NULL, id);
7993     Sleep(250);
7994     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7995     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7996 }
7997
7998 /* Various win events with arbitrary parameters */
7999 static const struct message WmWinEventsSeq[] = {
8000     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8001     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8002     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8003     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8004     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8005     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8006     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8007     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8008     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8009     /* our win event hook ignores OBJID_CURSOR events */
8010     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8011     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8012     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8013     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8014     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8015     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8016     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8017     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8018     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8019     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8020     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8021     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8022     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8023     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8024     { 0 }
8025 };
8026 static const struct message WmWinEventCaretSeq[] = {
8027     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8028     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8029     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8030     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8031     { 0 }
8032 };
8033 static const struct message WmWinEventCaretSeq_2[] = {
8034     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8035     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8036     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8037     { 0 }
8038 };
8039 static const struct message WmWinEventAlertSeq[] = {
8040     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8041     { 0 }
8042 };
8043 static const struct message WmWinEventAlertSeq_2[] = {
8044     /* create window in the thread proc */
8045     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8046     /* our test event */
8047     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8048     { 0 }
8049 };
8050 static const struct message WmGlobalHookSeq_1[] = {
8051     /* create window in the thread proc */
8052     { HCBT_CREATEWND, hook|lparam, 0, 2 },
8053     /* our test events */
8054     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8055     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8056     { 0 }
8057 };
8058 static const struct message WmGlobalHookSeq_2[] = {
8059     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8060     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8061     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8062     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8063     { 0 }
8064 };
8065
8066 static const struct message WmMouseLLHookSeq[] = {
8067     { WM_MOUSEMOVE, hook },
8068     { WM_LBUTTONUP, hook },
8069     { WM_MOUSEMOVE, hook },
8070     { 0 }
8071 };
8072
8073 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8074                                          DWORD event,
8075                                          HWND hwnd,
8076                                          LONG object_id,
8077                                          LONG child_id,
8078                                          DWORD thread_id,
8079                                          DWORD event_time)
8080 {
8081     char buf[256];
8082
8083     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8084     {
8085         if (!lstrcmpiA(buf, "TestWindowClass") ||
8086             !lstrcmpiA(buf, "static"))
8087         {
8088             struct recvd_message msg;
8089
8090             msg.hwnd = hwnd;
8091             msg.message = event;
8092             msg.flags = winevent_hook|wparam|lparam;
8093             msg.wParam = object_id;
8094             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8095             msg.descr = "WEH_2";
8096             add_message(&msg);
8097         }
8098     }
8099 }
8100
8101 static HHOOK hCBT_global_hook;
8102 static DWORD cbt_global_hook_thread_id;
8103
8104 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
8105
8106     HWND hwnd;
8107     char buf[256];
8108
8109     if (nCode == HCBT_SYSCOMMAND)
8110     {
8111         struct recvd_message msg;
8112
8113         msg.hwnd = 0;
8114         msg.message = nCode;
8115         msg.flags = hook|wparam|lparam;
8116         msg.wParam = wParam;
8117         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8118         msg.descr = "CBT_2";
8119         add_message(&msg);
8120
8121         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8122     }
8123     /* WH_MOUSE_LL hook */
8124     if (nCode == HC_ACTION)
8125     {
8126         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8127
8128         /* we can't test for real mouse events */
8129         if (mhll->flags & LLMHF_INJECTED)
8130         {
8131             struct recvd_message msg;
8132
8133             memset (&msg, 0, sizeof (msg));
8134             msg.message = wParam;
8135             msg.flags = hook;
8136             msg.descr = "CBT_2";
8137             add_message(&msg);
8138         }
8139         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8140     }
8141
8142     /* Log also SetFocus(0) calls */
8143     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8144
8145     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8146     {
8147         if (!lstrcmpiA(buf, "TestWindowClass") ||
8148             !lstrcmpiA(buf, "static"))
8149         {
8150             struct recvd_message msg;
8151
8152             msg.hwnd = hwnd;
8153             msg.message = nCode;
8154             msg.flags = hook|wparam|lparam;
8155             msg.wParam = wParam;
8156             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8157             msg.descr = "CBT_2";
8158             add_message(&msg);
8159         }
8160     }
8161     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8162 }
8163
8164 static DWORD WINAPI win_event_global_thread_proc(void *param)
8165 {
8166     HWND hwnd;
8167     MSG msg;
8168     HANDLE hevent = *(HANDLE *)param;
8169
8170     assert(pNotifyWinEvent);
8171
8172     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8173     assert(hwnd);
8174     trace("created thread window %p\n", hwnd);
8175
8176     *(HWND *)param = hwnd;
8177
8178     flush_sequence();
8179     /* this event should be received only by our new hook proc,
8180      * an old one does not expect an event from another thread.
8181      */
8182     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
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 cbt_global_hook_thread_proc(void *param)
8194 {
8195     HWND hwnd;
8196     MSG msg;
8197     HANDLE hevent = *(HANDLE *)param;
8198
8199     flush_sequence();
8200     /* these events should be received only by our new hook proc,
8201      * an old one does not expect an event from another thread.
8202      */
8203
8204     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8205     assert(hwnd);
8206     trace("created thread window %p\n", hwnd);
8207
8208     *(HWND *)param = hwnd;
8209
8210     /* Windows doesn't like when a thread plays games with the focus,
8211        that leads to all kinds of misbehaviours and failures to activate
8212        a window. So, better keep next lines commented out.
8213     SetFocus(0);
8214     SetFocus(hwnd);*/
8215
8216     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8217     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8218
8219     SetEvent(hevent);
8220
8221     while (GetMessage(&msg, 0, 0, 0))
8222     {
8223         TranslateMessage(&msg);
8224         DispatchMessage(&msg);
8225     }
8226     return 0;
8227 }
8228
8229 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8230 {
8231     HWND hwnd;
8232     MSG msg;
8233     HANDLE hevent = *(HANDLE *)param;
8234
8235     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8236     assert(hwnd);
8237     trace("created thread window %p\n", hwnd);
8238
8239     *(HWND *)param = hwnd;
8240
8241     flush_sequence();
8242
8243     /* Windows doesn't like when a thread plays games with the focus,
8244      * that leads to all kinds of misbehaviours and failures to activate
8245      * a window. So, better don't generate a mouse click message below.
8246      */
8247     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8248     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8249     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8250
8251     SetEvent(hevent);
8252     while (GetMessage(&msg, 0, 0, 0))
8253     {
8254         TranslateMessage(&msg);
8255         DispatchMessage(&msg);
8256     }
8257     return 0;
8258 }
8259
8260 static void test_winevents(void)
8261 {
8262     BOOL ret;
8263     MSG msg;
8264     HWND hwnd, hwnd2;
8265     UINT i;
8266     HANDLE hthread, hevent;
8267     DWORD tid;
8268     HWINEVENTHOOK hhook;
8269     const struct message *events = WmWinEventsSeq;
8270
8271     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8272                            WS_OVERLAPPEDWINDOW,
8273                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8274                            NULL, NULL, 0);
8275     assert(hwnd);
8276
8277     /****** start of global hook test *************/
8278     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8279     if (!hCBT_global_hook)
8280     {
8281         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8282         skip( "cannot set global hook\n" );
8283         return;
8284     }
8285
8286     hevent = CreateEventA(NULL, 0, 0, NULL);
8287     assert(hevent);
8288     hwnd2 = hevent;
8289
8290     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8291     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8292
8293     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8294
8295     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8296
8297     flush_sequence();
8298     /* this one should be received only by old hook proc */
8299     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8300     /* this one should be received only by old hook proc */
8301     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8302
8303     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8304
8305     ret = UnhookWindowsHookEx(hCBT_global_hook);
8306     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8307
8308     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8309     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8310     CloseHandle(hthread);
8311     CloseHandle(hevent);
8312     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8313     /****** end of global hook test *************/
8314
8315     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8316     {
8317         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8318         return;
8319     }
8320
8321     flush_sequence();
8322
8323     if (0)
8324     {
8325     /* this test doesn't pass under Win9x */
8326     /* win2k ignores events with hwnd == 0 */
8327     SetLastError(0xdeadbeef);
8328     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8329     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8330        GetLastError() == 0xdeadbeef, /* Win9x */
8331        "unexpected error %d\n", GetLastError());
8332     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8333     }
8334
8335     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8336         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8337
8338     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8339
8340     /****** start of event filtering test *************/
8341     hhook = pSetWinEventHook(
8342         EVENT_OBJECT_SHOW, /* 0x8002 */
8343         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8344         GetModuleHandleA(0), win_event_global_hook_proc,
8345         GetCurrentProcessId(), 0,
8346         WINEVENT_INCONTEXT);
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     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8354     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8355
8356     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8357
8358     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8359
8360     flush_sequence();
8361     /* this one should be received only by old hook proc */
8362     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8363     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8364     /* this one should be received only by old hook proc */
8365     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8366
8367     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8368
8369     ret = pUnhookWinEvent(hhook);
8370     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8371
8372     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8373     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8374     CloseHandle(hthread);
8375     CloseHandle(hevent);
8376     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8377     /****** end of event filtering test *************/
8378
8379     /****** start of out of context event test *************/
8380     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8381         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8382         WINEVENT_OUTOFCONTEXT);
8383     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8384
8385     hevent = CreateEventA(NULL, 0, 0, NULL);
8386     assert(hevent);
8387     hwnd2 = hevent;
8388
8389     flush_sequence();
8390
8391     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8392     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8393
8394     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8395
8396     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8397     /* process pending winevent messages */
8398     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8399     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8400
8401     flush_sequence();
8402     /* this one should be received only by old hook proc */
8403     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8404     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8405     /* this one should be received only by old hook proc */
8406     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8407
8408     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8409     /* process pending winevent messages */
8410     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8411     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8412
8413     ret = pUnhookWinEvent(hhook);
8414     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8415
8416     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8417     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8418     CloseHandle(hthread);
8419     CloseHandle(hevent);
8420     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8421     /****** end of out of context event test *************/
8422
8423     /****** start of MOUSE_LL hook test *************/
8424     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8425     /* WH_MOUSE_LL is not supported on Win9x platforms */
8426     if (!hCBT_global_hook)
8427     {
8428         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8429         goto skip_mouse_ll_hook_test;
8430     }
8431
8432     hevent = CreateEventA(NULL, 0, 0, NULL);
8433     assert(hevent);
8434     hwnd2 = hevent;
8435
8436     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8437     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8438
8439     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8440         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8441
8442     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8443     flush_sequence();
8444
8445     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8446     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8447     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8448
8449     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8450
8451     ret = UnhookWindowsHookEx(hCBT_global_hook);
8452     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8453
8454     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8455     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8456     CloseHandle(hthread);
8457     CloseHandle(hevent);
8458     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8459     /****** end of MOUSE_LL hook test *************/
8460 skip_mouse_ll_hook_test:
8461
8462     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8463 }
8464
8465 static void test_set_hook(void)
8466 {
8467     BOOL ret;
8468     HHOOK hhook;
8469     HWINEVENTHOOK hwinevent_hook;
8470
8471     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8472     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8473     UnhookWindowsHookEx(hhook);
8474
8475     if (0)
8476     {
8477     /* this test doesn't pass under Win9x: BUG! */
8478     SetLastError(0xdeadbeef);
8479     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8480     ok(!hhook, "global hook requires hModule != 0\n");
8481     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8482     }
8483
8484     SetLastError(0xdeadbeef);
8485     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8486     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8487     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8488        GetLastError() == 0xdeadbeef, /* Win9x */
8489        "unexpected error %d\n", GetLastError());
8490
8491     SetLastError(0xdeadbeef);
8492     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8493     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8494        GetLastError() == 0xdeadbeef, /* Win9x */
8495        "unexpected error %d\n", GetLastError());
8496
8497     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8498
8499     /* even process local incontext hooks require hmodule */
8500     SetLastError(0xdeadbeef);
8501     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8502         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8503     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8504     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8505        GetLastError() == 0xdeadbeef, /* Win9x */
8506        "unexpected error %d\n", GetLastError());
8507
8508     /* even thread local incontext hooks require hmodule */
8509     SetLastError(0xdeadbeef);
8510     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8511         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8512     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8513     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8514        GetLastError() == 0xdeadbeef, /* Win9x */
8515        "unexpected error %d\n", GetLastError());
8516
8517     if (0)
8518     {
8519     /* these 3 tests don't pass under Win9x */
8520     SetLastError(0xdeadbeef);
8521     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8522         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8523     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8524     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8525
8526     SetLastError(0xdeadbeef);
8527     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8528         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8529     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8530     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8531
8532     SetLastError(0xdeadbeef);
8533     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8534         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8535     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8536     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8537     }
8538
8539     SetLastError(0xdeadbeef);
8540     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8541         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8542     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8543     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8544     ret = pUnhookWinEvent(hwinevent_hook);
8545     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8546
8547 todo_wine {
8548     /* This call succeeds under win2k SP4, but fails under Wine.
8549        Does win2k test/use passed process id? */
8550     SetLastError(0xdeadbeef);
8551     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8552         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8553     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8554     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8555     ret = pUnhookWinEvent(hwinevent_hook);
8556     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8557 }
8558
8559     SetLastError(0xdeadbeef);
8560     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8561     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8562         GetLastError() == 0xdeadbeef, /* Win9x */
8563         "unexpected error %d\n", GetLastError());
8564 }
8565
8566 static const struct message ScrollWindowPaint1[] = {
8567     { WM_PAINT, sent },
8568     { WM_ERASEBKGND, sent|beginpaint },
8569     { WM_GETTEXTLENGTH, sent|optional },
8570     { WM_PAINT, sent|optional },
8571     { WM_NCPAINT, sent|beginpaint|optional },
8572     { WM_GETTEXT, sent|beginpaint|optional },
8573     { WM_GETTEXT, sent|beginpaint|optional },
8574     { WM_GETTEXT, sent|beginpaint|optional },
8575     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8576     { WM_ERASEBKGND, sent|beginpaint|optional },
8577     { 0 }
8578 };
8579
8580 static const struct message ScrollWindowPaint2[] = {
8581     { WM_PAINT, sent },
8582     { 0 }
8583 };
8584
8585 static void test_scrollwindowex(void)
8586 {
8587     HWND hwnd, hchild;
8588     RECT rect={0,0,130,130};
8589
8590     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8591             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8592             100, 100, 200, 200, 0, 0, 0, NULL);
8593     ok (hwnd != 0, "Failed to create overlapped window\n");
8594     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8595             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8596             10, 10, 150, 150, hwnd, 0, 0, NULL);
8597     ok (hchild != 0, "Failed to create child\n");
8598     UpdateWindow(hwnd);
8599     flush_events();
8600     flush_sequence();
8601
8602     /* scroll without the child window */
8603     trace("start scroll\n");
8604     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8605             SW_ERASE|SW_INVALIDATE);
8606     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8607     trace("end scroll\n");
8608     flush_sequence();
8609     flush_events();
8610     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8611     flush_events();
8612     flush_sequence();
8613
8614     /* Now without the SW_ERASE flag */
8615     trace("start scroll\n");
8616     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8617     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8618     trace("end scroll\n");
8619     flush_sequence();
8620     flush_events();
8621     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8622     flush_events();
8623     flush_sequence();
8624
8625     /* now scroll the child window as well */
8626     trace("start scroll\n");
8627     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8628             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8629     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8630     /* windows sometimes a WM_MOVE */
8631     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8632     trace("end scroll\n");
8633     flush_sequence();
8634     flush_events();
8635     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8636     flush_events();
8637     flush_sequence();
8638
8639     /* now scroll with ScrollWindow() */
8640     trace("start scroll with ScrollWindow\n");
8641     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8642     trace("end scroll\n");
8643     flush_sequence();
8644     flush_events();
8645     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8646
8647     ok(DestroyWindow(hchild), "failed to destroy window\n");
8648     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8649     flush_sequence();
8650 }
8651
8652 static const struct message destroy_window_with_children[] = {
8653     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8654     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8655     { 0x0090, sent|optional },
8656     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8657     { 0x0090, sent|optional },
8658     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8659     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8660     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8661     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8662     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8663     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8664     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8665     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8666     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8667     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8668     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8669     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8670     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8671     { 0 }
8672 };
8673
8674 static void test_DestroyWindow(void)
8675 {
8676     BOOL ret;
8677     HWND parent, child1, child2, child3, child4, test;
8678     UINT_PTR child_id = WND_CHILD_ID + 1;
8679
8680     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8681                              100, 100, 200, 200, 0, 0, 0, NULL);
8682     assert(parent != 0);
8683     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8684                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8685     assert(child1 != 0);
8686     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8687                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8688     assert(child2 != 0);
8689     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8690                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8691     assert(child3 != 0);
8692     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8693                              0, 0, 50, 50, parent, 0, 0, NULL);
8694     assert(child4 != 0);
8695
8696     /* test owner/parent of child2 */
8697     test = GetParent(child2);
8698     ok(test == GetDesktopWindow(), "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 == GetDesktopWindow(), "wrong parent %p\n", test);
8703     }
8704     test = GetWindow(child2, GW_OWNER);
8705     ok(!test, "wrong owner %p\n", test);
8706
8707     test = SetParent(child2, parent);
8708     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8709
8710     /* test owner/parent of the parent */
8711     test = GetParent(parent);
8712     ok(!test, "wrong parent %p\n", test);
8713     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8714     if(pGetAncestor) {
8715         test = pGetAncestor(parent, GA_PARENT);
8716         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8717     }
8718     test = GetWindow(parent, GW_OWNER);
8719     ok(!test, "wrong owner %p\n", test);
8720
8721     /* test owner/parent of child1 */
8722     test = GetParent(child1);
8723     ok(test == parent, "wrong parent %p\n", test);
8724     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8725     if(pGetAncestor) {
8726         test = pGetAncestor(child1, GA_PARENT);
8727         ok(test == parent, "wrong parent %p\n", test);
8728     }
8729     test = GetWindow(child1, GW_OWNER);
8730     ok(!test, "wrong owner %p\n", test);
8731
8732     /* test owner/parent of child2 */
8733     test = GetParent(child2);
8734     ok(test == parent, "wrong parent %p\n", test);
8735     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8736     if(pGetAncestor) {
8737         test = pGetAncestor(child2, GA_PARENT);
8738         ok(test == parent, "wrong parent %p\n", test);
8739     }
8740     test = GetWindow(child2, GW_OWNER);
8741     ok(!test, "wrong owner %p\n", test);
8742
8743     /* test owner/parent of child3 */
8744     test = GetParent(child3);
8745     ok(test == child1, "wrong parent %p\n", test);
8746     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8747     if(pGetAncestor) {
8748         test = pGetAncestor(child3, GA_PARENT);
8749         ok(test == child1, "wrong parent %p\n", test);
8750     }
8751     test = GetWindow(child3, GW_OWNER);
8752     ok(!test, "wrong owner %p\n", test);
8753
8754     /* test owner/parent of child4 */
8755     test = GetParent(child4);
8756     ok(test == parent, "wrong parent %p\n", test);
8757     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8758     if(pGetAncestor) {
8759         test = pGetAncestor(child4, GA_PARENT);
8760         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8761     }
8762     test = GetWindow(child4, GW_OWNER);
8763     ok(test == parent, "wrong owner %p\n", test);
8764
8765     flush_sequence();
8766
8767     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8768            parent, child1, child2, child3, child4);
8769
8770     SetCapture(child4);
8771     test = GetCapture();
8772     ok(test == child4, "wrong capture window %p\n", test);
8773
8774     test_DestroyWindow_flag = TRUE;
8775     ret = DestroyWindow(parent);
8776     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8777     test_DestroyWindow_flag = FALSE;
8778     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8779
8780     ok(!IsWindow(parent), "parent still exists\n");
8781     ok(!IsWindow(child1), "child1 still exists\n");
8782     ok(!IsWindow(child2), "child2 still exists\n");
8783     ok(!IsWindow(child3), "child3 still exists\n");
8784     ok(!IsWindow(child4), "child4 still exists\n");
8785
8786     test = GetCapture();
8787     ok(!test, "wrong capture window %p\n", test);
8788 }
8789
8790
8791 static const struct message WmDispatchPaint[] = {
8792     { WM_NCPAINT, sent },
8793     { WM_GETTEXT, sent|defwinproc|optional },
8794     { WM_GETTEXT, sent|defwinproc|optional },
8795     { WM_ERASEBKGND, sent },
8796     { 0 }
8797 };
8798
8799 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8800 {
8801     if (message == WM_PAINT) return 0;
8802     return MsgCheckProcA( hwnd, message, wParam, lParam );
8803 }
8804
8805 static void test_DispatchMessage(void)
8806 {
8807     RECT rect;
8808     MSG msg;
8809     int count;
8810     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8811                                100, 100, 200, 200, 0, 0, 0, NULL);
8812     ShowWindow( hwnd, SW_SHOW );
8813     UpdateWindow( hwnd );
8814     flush_events();
8815     flush_sequence();
8816     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8817
8818     SetRect( &rect, -5, -5, 5, 5 );
8819     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8820     count = 0;
8821     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8822     {
8823         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8824         else
8825         {
8826             flush_sequence();
8827             DispatchMessage( &msg );
8828             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8829             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8830             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8831             if (++count > 10) break;
8832         }
8833     }
8834     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8835
8836     trace("now without DispatchMessage\n");
8837     flush_sequence();
8838     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8839     count = 0;
8840     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8841     {
8842         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8843         else
8844         {
8845             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8846             flush_sequence();
8847             /* this will send WM_NCCPAINT just like DispatchMessage does */
8848             GetUpdateRgn( hwnd, hrgn, TRUE );
8849             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8850             DeleteObject( hrgn );
8851             GetClientRect( hwnd, &rect );
8852             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8853             ok( !count, "Got multiple WM_PAINTs\n" );
8854             if (++count > 10) break;
8855         }
8856     }
8857     DestroyWindow(hwnd);
8858 }
8859
8860
8861 static const struct message WmUser[] = {
8862     { WM_USER, sent },
8863     { 0 }
8864 };
8865
8866 struct sendmsg_info
8867 {
8868     HWND  hwnd;
8869     DWORD timeout;
8870     DWORD ret;
8871 };
8872
8873 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8874 {
8875     struct sendmsg_info *info = arg;
8876     SetLastError( 0xdeadbeef );
8877     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8878     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8879                         broken(GetLastError() == 0),  /* win9x */
8880                         "unexpected error %d\n", GetLastError());
8881     return 0;
8882 }
8883
8884 static void wait_for_thread( HANDLE thread )
8885 {
8886     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8887     {
8888         MSG msg;
8889         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8890     }
8891 }
8892
8893 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8894 {
8895     if (message == WM_USER) Sleep(200);
8896     return MsgCheckProcA( hwnd, message, wParam, lParam );
8897 }
8898
8899 static void test_SendMessageTimeout(void)
8900 {
8901     HANDLE thread;
8902     struct sendmsg_info info;
8903     DWORD tid;
8904     BOOL is_win9x;
8905
8906     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8907                                100, 100, 200, 200, 0, 0, 0, NULL);
8908     flush_events();
8909     flush_sequence();
8910
8911     info.timeout = 1000;
8912     info.ret = 0xdeadbeef;
8913     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8914     wait_for_thread( thread );
8915     CloseHandle( thread );
8916     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8917     ok_sequence( WmUser, "WmUser", FALSE );
8918
8919     info.timeout = 1;
8920     info.ret = 0xdeadbeef;
8921     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8922     Sleep(100);  /* SendMessageTimeout should time out here */
8923     wait_for_thread( thread );
8924     CloseHandle( thread );
8925     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8926     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8927
8928     /* 0 means infinite timeout (but not on win9x) */
8929     info.timeout = 0;
8930     info.ret = 0xdeadbeef;
8931     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8932     Sleep(100);
8933     wait_for_thread( thread );
8934     CloseHandle( thread );
8935     is_win9x = !info.ret;
8936     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8937     else ok_sequence( WmUser, "WmUser", FALSE );
8938
8939     /* timeout is treated as signed despite the prototype (but not on win9x) */
8940     info.timeout = 0x7fffffff;
8941     info.ret = 0xdeadbeef;
8942     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8943     Sleep(100);
8944     wait_for_thread( thread );
8945     CloseHandle( thread );
8946     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8947     ok_sequence( WmUser, "WmUser", FALSE );
8948
8949     info.timeout = 0x80000000;
8950     info.ret = 0xdeadbeef;
8951     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8952     Sleep(100);
8953     wait_for_thread( thread );
8954     CloseHandle( thread );
8955     if (is_win9x)
8956     {
8957         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8958         ok_sequence( WmUser, "WmUser", FALSE );
8959     }
8960     else
8961     {
8962         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8963         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8964     }
8965
8966     /* now check for timeout during message processing */
8967     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8968     info.timeout = 100;
8969     info.ret = 0xdeadbeef;
8970     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8971     wait_for_thread( thread );
8972     CloseHandle( thread );
8973     /* we should time out but still get the message */
8974     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8975     ok_sequence( WmUser, "WmUser", FALSE );
8976
8977     DestroyWindow( info.hwnd );
8978 }
8979
8980
8981 /****************** edit message test *************************/
8982 #define ID_EDIT 0x1234
8983 static const struct message sl_edit_setfocus[] =
8984 {
8985     { HCBT_SETFOCUS, hook },
8986     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8987     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8988     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8989     { WM_SETFOCUS, sent|wparam, 0 },
8990     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8991     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8992     { WM_CTLCOLOREDIT, sent|parent },
8993     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8994     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8995     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8996     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8997     { 0 }
8998 };
8999 static const struct message ml_edit_setfocus[] =
9000 {
9001     { HCBT_SETFOCUS, hook },
9002     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9003     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9004     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9005     { WM_SETFOCUS, sent|wparam, 0 },
9006     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9007     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9008     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9009     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9010     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9011     { 0 }
9012 };
9013 static const struct message sl_edit_killfocus[] =
9014 {
9015     { HCBT_SETFOCUS, hook },
9016     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9017     { WM_KILLFOCUS, sent|wparam, 0 },
9018     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9019     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9020     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9021     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9022     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9023     { 0 }
9024 };
9025 static const struct message sl_edit_lbutton_dblclk[] =
9026 {
9027     { WM_LBUTTONDBLCLK, sent },
9028     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9029     { 0 }
9030 };
9031 static const struct message sl_edit_lbutton_down[] =
9032 {
9033     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9034     { HCBT_SETFOCUS, hook },
9035     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9036     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9037     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9038     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9039     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9040     { WM_CTLCOLOREDIT, sent|parent },
9041     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9042     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9043     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9044     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9045     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9046     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9047     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9048     { WM_CTLCOLOREDIT, sent|parent|optional },
9049     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9050     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9051     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9052     { 0 }
9053 };
9054 static const struct message ml_edit_lbutton_down[] =
9055 {
9056     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9057     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9058     { HCBT_SETFOCUS, hook },
9059     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9060     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9061     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9062     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9063     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9064     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9065     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9066     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9067     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9068     { 0 }
9069 };
9070 static const struct message sl_edit_lbutton_up[] =
9071 {
9072     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9073     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9074     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9075     { WM_CAPTURECHANGED, sent|defwinproc },
9076     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9077     { 0 }
9078 };
9079 static const struct message ml_edit_lbutton_up[] =
9080 {
9081     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9082     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9083     { WM_CAPTURECHANGED, sent|defwinproc },
9084     { 0 }
9085 };
9086
9087 static WNDPROC old_edit_proc;
9088
9089 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9090 {
9091     static LONG defwndproc_counter = 0;
9092     LRESULT ret;
9093     struct recvd_message msg;
9094
9095     if (ignore_message( message )) return 0;
9096
9097     msg.hwnd = hwnd;
9098     msg.message = message;
9099     msg.flags = sent|wparam|lparam;
9100     if (defwndproc_counter) msg.flags |= defwinproc;
9101     msg.wParam = wParam;
9102     msg.lParam = lParam;
9103     msg.descr = "edit";
9104     add_message(&msg);
9105
9106     defwndproc_counter++;
9107     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9108     defwndproc_counter--;
9109
9110     return ret;
9111 }
9112
9113 static void subclass_edit(void)
9114 {
9115     WNDCLASSA cls;
9116
9117     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9118
9119     old_edit_proc = cls.lpfnWndProc;
9120
9121     cls.hInstance = GetModuleHandle(0);
9122     cls.lpfnWndProc = edit_hook_proc;
9123     cls.lpszClassName = "my_edit_class";
9124     UnregisterClass(cls.lpszClassName, cls.hInstance);
9125     if (!RegisterClassA(&cls)) assert(0);
9126 }
9127
9128 static void test_edit_messages(void)
9129 {
9130     HWND hwnd, parent;
9131     DWORD dlg_code;
9132
9133     subclass_edit();
9134     log_all_parent_messages++;
9135
9136     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9137                              100, 100, 200, 200, 0, 0, 0, NULL);
9138     ok (parent != 0, "Failed to create parent window\n");
9139
9140     /* test single line edit */
9141     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9142                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9143     ok(hwnd != 0, "Failed to create edit window\n");
9144
9145     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9146     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9147
9148     ShowWindow(hwnd, SW_SHOW);
9149     UpdateWindow(hwnd);
9150     SetFocus(0);
9151     flush_sequence();
9152
9153     SetFocus(hwnd);
9154     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9155
9156     SetFocus(0);
9157     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9158
9159     SetFocus(0);
9160     ReleaseCapture();
9161     flush_sequence();
9162
9163     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9164     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9165
9166     SetFocus(0);
9167     ReleaseCapture();
9168     flush_sequence();
9169
9170     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9171     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9172
9173     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9174     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9175
9176     DestroyWindow(hwnd);
9177
9178     /* test multiline edit */
9179     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9180                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9181     ok(hwnd != 0, "Failed to create edit window\n");
9182
9183     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9184     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9185        "wrong dlg_code %08x\n", dlg_code);
9186
9187     ShowWindow(hwnd, SW_SHOW);
9188     UpdateWindow(hwnd);
9189     SetFocus(0);
9190     flush_sequence();
9191
9192     SetFocus(hwnd);
9193     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9194
9195     SetFocus(0);
9196     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9197
9198     SetFocus(0);
9199     ReleaseCapture();
9200     flush_sequence();
9201
9202     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9203     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9204
9205     SetFocus(0);
9206     ReleaseCapture();
9207     flush_sequence();
9208
9209     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9210     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9211
9212     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9213     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9214
9215     DestroyWindow(hwnd);
9216     DestroyWindow(parent);
9217
9218     log_all_parent_messages--;
9219 }
9220
9221 /**************************** End of Edit test ******************************/
9222
9223 static const struct message WmKeyDownSkippedSeq[] =
9224 {
9225     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9226     { 0 }
9227 };
9228 static const struct message WmKeyDownWasDownSkippedSeq[] =
9229 {
9230     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9231     { 0 }
9232 };
9233 static const struct message WmKeyUpSkippedSeq[] =
9234 {
9235     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9236     { 0 }
9237 };
9238 static const struct message WmUserKeyUpSkippedSeq[] =
9239 {
9240     { WM_USER, sent },
9241     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9242     { 0 }
9243 };
9244
9245 #define EV_STOP 0
9246 #define EV_SENDMSG 1
9247 #define EV_ACK 2
9248
9249 struct peekmsg_info
9250 {
9251     HWND  hwnd;
9252     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9253 };
9254
9255 static DWORD CALLBACK send_msg_thread_2(void *param)
9256 {
9257     DWORD ret;
9258     struct peekmsg_info *info = param;
9259
9260     trace("thread: looping\n");
9261     SetEvent(info->hevent[EV_ACK]);
9262
9263     while (1)
9264     {
9265         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9266
9267         switch (ret)
9268         {
9269         case WAIT_OBJECT_0 + EV_STOP:
9270             trace("thread: exiting\n");
9271             return 0;
9272
9273         case WAIT_OBJECT_0 + EV_SENDMSG:
9274             trace("thread: sending message\n");
9275             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9276                 "SendNotifyMessageA failed error %u\n", GetLastError());
9277             SetEvent(info->hevent[EV_ACK]);
9278             break;
9279
9280         default:
9281             trace("unexpected return: %04x\n", ret);
9282             assert(0);
9283             break;
9284         }
9285     }
9286     return 0;
9287 }
9288
9289 static void test_PeekMessage(void)
9290 {
9291     MSG msg;
9292     HANDLE hthread;
9293     DWORD tid, qstatus;
9294     UINT qs_all_input = QS_ALLINPUT;
9295     UINT qs_input = QS_INPUT;
9296     BOOL ret;
9297     struct peekmsg_info info;
9298
9299     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9300                               100, 100, 200, 200, 0, 0, 0, NULL);
9301     assert(info.hwnd);
9302     ShowWindow(info.hwnd, SW_SHOW);
9303     UpdateWindow(info.hwnd);
9304     SetFocus(info.hwnd);
9305
9306     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9307     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9308     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9309
9310     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9311     WaitForSingleObject(info.hevent[EV_ACK], 10000);
9312
9313     flush_events();
9314     flush_sequence();
9315
9316     SetLastError(0xdeadbeef);
9317     qstatus = GetQueueStatus(qs_all_input);
9318     if (GetLastError() == ERROR_INVALID_FLAGS)
9319     {
9320         trace("QS_RAWINPUT not supported on this platform\n");
9321         qs_all_input &= ~QS_RAWINPUT;
9322         qs_input &= ~QS_RAWINPUT;
9323     }
9324     if (qstatus & QS_POSTMESSAGE)
9325     {
9326         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9327         qstatus = GetQueueStatus(qs_all_input);
9328     }
9329     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9330
9331     trace("signalling to send message\n");
9332     SetEvent(info.hevent[EV_SENDMSG]);
9333     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9334
9335     /* pass invalid QS_xxxx flags */
9336     SetLastError(0xdeadbeef);
9337     qstatus = GetQueueStatus(0xffffffff);
9338     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9339     if (!qstatus)
9340     {
9341         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9342         qstatus = GetQueueStatus(qs_all_input);
9343     }
9344     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9345     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9346        "wrong qstatus %08x\n", qstatus);
9347
9348     msg.message = 0;
9349     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9350     ok(!ret,
9351        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9352         msg.message);
9353     ok_sequence(WmUser, "WmUser", FALSE);
9354
9355     qstatus = GetQueueStatus(qs_all_input);
9356     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9357
9358     keybd_event('N', 0, 0, 0);
9359     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9360     qstatus = GetQueueStatus(qs_all_input);
9361     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9362     {
9363         skip( "queuing key events not supported\n" );
9364         goto done;
9365     }
9366     ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9367        /* keybd_event seems to trigger a sent message on NT4 */
9368        qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9369        "wrong qstatus %08x\n", qstatus);
9370
9371     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9372     qstatus = GetQueueStatus(qs_all_input);
9373     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9374        qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9375        "wrong qstatus %08x\n", qstatus);
9376
9377     InvalidateRect(info.hwnd, NULL, FALSE);
9378     qstatus = GetQueueStatus(qs_all_input);
9379     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9380        qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9381        "wrong qstatus %08x\n", qstatus);
9382
9383     trace("signalling to send message\n");
9384     SetEvent(info.hevent[EV_SENDMSG]);
9385     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9386
9387     qstatus = GetQueueStatus(qs_all_input);
9388     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9389        "wrong qstatus %08x\n", qstatus);
9390
9391     msg.message = 0;
9392     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9393     if (ret && msg.message == WM_CHAR)
9394     {
9395         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9396         goto done;
9397     }
9398     ok(!ret,
9399        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9400         msg.message);
9401     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9402     {
9403         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9404         goto done;
9405     }
9406     ok_sequence(WmUser, "WmUser", FALSE);
9407
9408     qstatus = GetQueueStatus(qs_all_input);
9409     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9410        "wrong qstatus %08x\n", qstatus);
9411
9412     trace("signalling to send message\n");
9413     SetEvent(info.hevent[EV_SENDMSG]);
9414     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9415
9416     qstatus = GetQueueStatus(qs_all_input);
9417     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9418        "wrong qstatus %08x\n", qstatus);
9419
9420     msg.message = 0;
9421     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9422     ok(!ret,
9423        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9424         msg.message);
9425     ok_sequence(WmUser, "WmUser", FALSE);
9426
9427     qstatus = GetQueueStatus(qs_all_input);
9428     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9429        "wrong qstatus %08x\n", qstatus);
9430
9431     msg.message = 0;
9432     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9433     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9434        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9435        ret, msg.message, msg.wParam);
9436     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9437
9438     qstatus = GetQueueStatus(qs_all_input);
9439     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9440        "wrong qstatus %08x\n", qstatus);
9441
9442     msg.message = 0;
9443     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9444     ok(!ret,
9445        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9446         msg.message);
9447     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9448
9449     qstatus = GetQueueStatus(qs_all_input);
9450     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9451        "wrong qstatus %08x\n", qstatus);
9452
9453     msg.message = 0;
9454     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9455     ok(ret && msg.message == WM_PAINT,
9456        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9457     DispatchMessageA(&msg);
9458     ok_sequence(WmPaint, "WmPaint", 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, 0, 0, PM_REMOVE | PM_QS_PAINT);
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     trace("signalling to send message\n");
9476     SetEvent(info.hevent[EV_SENDMSG]);
9477     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9478
9479     qstatus = GetQueueStatus(qs_all_input);
9480     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9481        "wrong qstatus %08x\n", qstatus);
9482
9483     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9484
9485     qstatus = GetQueueStatus(qs_all_input);
9486     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9487        "wrong qstatus %08x\n", qstatus);
9488
9489     msg.message = 0;
9490     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9491     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9492        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9493        ret, msg.message, msg.wParam);
9494     ok_sequence(WmUser, "WmUser", FALSE);
9495
9496     qstatus = GetQueueStatus(qs_all_input);
9497     ok(qstatus == MAKELONG(0, QS_KEY),
9498        "wrong qstatus %08x\n", qstatus);
9499
9500     msg.message = 0;
9501     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9502     ok(!ret,
9503        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9504         msg.message);
9505     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9506
9507     qstatus = GetQueueStatus(qs_all_input);
9508     ok(qstatus == MAKELONG(0, QS_KEY),
9509        "wrong qstatus %08x\n", qstatus);
9510
9511     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9512
9513     qstatus = GetQueueStatus(qs_all_input);
9514     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9515        "wrong qstatus %08x\n", qstatus);
9516
9517     trace("signalling to send message\n");
9518     SetEvent(info.hevent[EV_SENDMSG]);
9519     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9520
9521     qstatus = GetQueueStatus(qs_all_input);
9522     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9523        "wrong qstatus %08x\n", qstatus);
9524
9525     msg.message = 0;
9526     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9527     ok(!ret,
9528        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9529         msg.message);
9530     ok_sequence(WmUser, "WmUser", FALSE);
9531
9532     qstatus = GetQueueStatus(qs_all_input);
9533     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9534        "wrong qstatus %08x\n", qstatus);
9535
9536     msg.message = 0;
9537     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9538         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9539     else /* workaround for a missing QS_RAWINPUT support */
9540         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9541     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9542        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9543        ret, msg.message, msg.wParam);
9544     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9545
9546     qstatus = GetQueueStatus(qs_all_input);
9547     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9548        "wrong qstatus %08x\n", qstatus);
9549
9550     msg.message = 0;
9551     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9552         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9553     else /* workaround for a missing QS_RAWINPUT support */
9554         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9555     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9556        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9557        ret, msg.message, msg.wParam);
9558     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9559
9560     qstatus = GetQueueStatus(qs_all_input);
9561     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9562        "wrong qstatus %08x\n", qstatus);
9563
9564     msg.message = 0;
9565     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9566     ok(!ret,
9567        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9568         msg.message);
9569     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9570
9571     qstatus = GetQueueStatus(qs_all_input);
9572     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9573        "wrong qstatus %08x\n", qstatus);
9574
9575     msg.message = 0;
9576     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9577     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9578        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9579        ret, msg.message, msg.wParam);
9580     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9581
9582     qstatus = GetQueueStatus(qs_all_input);
9583     ok(qstatus == 0,
9584        "wrong qstatus %08x\n", qstatus);
9585
9586     msg.message = 0;
9587     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9588     ok(!ret,
9589        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9590         msg.message);
9591     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9592
9593     qstatus = GetQueueStatus(qs_all_input);
9594     ok(qstatus == 0,
9595        "wrong qstatus %08x\n", qstatus);
9596
9597     /* test whether presence of the quit flag in the queue affects
9598      * the queue state
9599      */
9600     PostQuitMessage(0x1234abcd);
9601
9602     qstatus = GetQueueStatus(qs_all_input);
9603     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9604        "wrong qstatus %08x\n", qstatus);
9605
9606     PostMessageA(info.hwnd, WM_USER, 0, 0);
9607
9608     qstatus = GetQueueStatus(qs_all_input);
9609     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9610        "wrong qstatus %08x\n", qstatus);
9611
9612     msg.message = 0;
9613     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9614     ok(ret && msg.message == WM_USER,
9615        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9616     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9617
9618     qstatus = GetQueueStatus(qs_all_input);
9619     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9620        "wrong qstatus %08x\n", qstatus);
9621
9622     msg.message = 0;
9623     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9624     ok(ret && msg.message == WM_QUIT,
9625        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9626     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9627     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9628     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9629
9630     qstatus = GetQueueStatus(qs_all_input);
9631 todo_wine {
9632     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9633        "wrong qstatus %08x\n", qstatus);
9634 }
9635
9636     msg.message = 0;
9637     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9638     ok(!ret,
9639        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9640         msg.message);
9641     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9642
9643     qstatus = GetQueueStatus(qs_all_input);
9644     ok(qstatus == 0,
9645        "wrong qstatus %08x\n", qstatus);
9646
9647     /* some GetMessage tests */
9648
9649     keybd_event('N', 0, 0, 0);
9650     qstatus = GetQueueStatus(qs_all_input);
9651     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9652
9653     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9654     qstatus = GetQueueStatus(qs_all_input);
9655     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9656
9657     if (qstatus)
9658     {
9659         ret = GetMessageA( &msg, 0, 0, 0 );
9660         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9661            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9662            ret, msg.message, msg.wParam);
9663         qstatus = GetQueueStatus(qs_all_input);
9664         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9665     }
9666
9667     if (qstatus)
9668     {
9669         ret = GetMessageA( &msg, 0, 0, 0 );
9670         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9671            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9672            ret, msg.message, msg.wParam);
9673         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9674         qstatus = GetQueueStatus(qs_all_input);
9675         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9676     }
9677
9678     keybd_event('N', 0, 0, 0);
9679     qstatus = GetQueueStatus(qs_all_input);
9680     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9681
9682     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9683     qstatus = GetQueueStatus(qs_all_input);
9684     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "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_KEYDOWN && 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(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", 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
9707     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9708     qstatus = GetQueueStatus(qs_all_input);
9709     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9710
9711     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9712     qstatus = GetQueueStatus(qs_all_input);
9713     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9714
9715     trace("signalling to send message\n");
9716     SetEvent(info.hevent[EV_SENDMSG]);
9717     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9718     qstatus = GetQueueStatus(qs_all_input);
9719     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9720        "wrong qstatus %08x\n", qstatus);
9721
9722     if (qstatus & (QS_KEY << 16))
9723     {
9724         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9725         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9726            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9727            ret, msg.message, msg.wParam);
9728         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9729         qstatus = GetQueueStatus(qs_all_input);
9730         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9731     }
9732
9733     if (qstatus)
9734     {
9735         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9736         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9737            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9738            ret, msg.message, msg.wParam);
9739         qstatus = GetQueueStatus(qs_all_input);
9740         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9741     }
9742 done:
9743     trace("signalling to exit\n");
9744     SetEvent(info.hevent[EV_STOP]);
9745
9746     WaitForSingleObject(hthread, INFINITE);
9747
9748     CloseHandle(hthread);
9749     CloseHandle(info.hevent[0]);
9750     CloseHandle(info.hevent[1]);
9751     CloseHandle(info.hevent[2]);
9752
9753     DestroyWindow(info.hwnd);
9754 }
9755
9756 static void wait_move_event(HWND hwnd, int x, int y)
9757 {
9758     MSG msg;
9759     DWORD time;
9760     BOOL  ret;
9761     int go = 0;
9762
9763     time = GetTickCount();
9764     while (GetTickCount() - time < 200 && !go) {
9765         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9766         go  = ret && msg.pt.x > x && msg.pt.y > y;
9767         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9768     }
9769 }
9770
9771 #define STEP 5
9772 static void test_PeekMessage2(void)
9773 {
9774     HWND hwnd;
9775     BOOL ret;
9776     MSG msg;
9777     UINT message;
9778     DWORD time1, time2, time3;
9779     int x1, y1, x2, y2, x3, y3;
9780     POINT pos;
9781
9782     time1 = time2 = time3 = 0;
9783     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9784
9785     /* Initialise window and make sure it is ready for events */
9786     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9787                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9788     assert(hwnd);
9789     trace("Window for test_PeekMessage2 %p\n", hwnd);
9790     ShowWindow(hwnd, SW_SHOW);
9791     UpdateWindow(hwnd);
9792     SetFocus(hwnd);
9793     GetCursorPos(&pos);
9794     SetCursorPos(100, 100);
9795     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9796     flush_events();
9797
9798     /* Do initial mousemove, wait until we can see it
9799        and then do our test peek with PM_NOREMOVE. */
9800     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9801     wait_move_event(hwnd, 100-STEP, 100-STEP);
9802
9803     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9804     if (!ret)
9805     {
9806         skip( "queuing mouse events not supported\n" );
9807         goto done;
9808     }
9809     else
9810     {
9811         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9812         message = msg.message;
9813         time1 = msg.time;
9814         x1 = msg.pt.x;
9815         y1 = msg.pt.y;
9816         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9817     }
9818
9819     /* Allow time to advance a bit, and then simulate the user moving their
9820      * mouse around. After that we peek again with PM_NOREMOVE.
9821      * Although the previous mousemove message was never removed, the
9822      * mousemove we now peek should reflect the recent mouse movements
9823      * because the input queue will merge the move events. */
9824     Sleep(100);
9825     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9826     wait_move_event(hwnd, x1, y1);
9827
9828     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9829     ok(ret, "no message available\n");
9830     if (ret) {
9831         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9832         message = msg.message;
9833         time2 = msg.time;
9834         x2 = msg.pt.x;
9835         y2 = msg.pt.y;
9836         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9837         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9838         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9839     }
9840
9841     /* Have another go, to drive the point home */
9842     Sleep(100);
9843     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9844     wait_move_event(hwnd, x2, y2);
9845
9846     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9847     ok(ret, "no message available\n");
9848     if (ret) {
9849         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9850         message = msg.message;
9851         time3 = msg.time;
9852         x3 = msg.pt.x;
9853         y3 = msg.pt.y;
9854         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9855         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9856         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9857     }
9858
9859 done:
9860     DestroyWindow(hwnd);
9861     SetCursorPos(pos.x, pos.y);
9862     flush_events();
9863 }
9864
9865 static void test_quit_message(void)
9866 {
9867     MSG msg;
9868     BOOL ret;
9869
9870     /* test using PostQuitMessage */
9871     flush_events();
9872     PostQuitMessage(0xbeef);
9873
9874     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9875     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9876     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9877     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9878
9879     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9880     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9881
9882     ret = GetMessage(&msg, NULL, 0, 0);
9883     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9884     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9885
9886     /* note: WM_QUIT message received after WM_USER message */
9887     ret = GetMessage(&msg, NULL, 0, 0);
9888     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9889     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9890     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9891
9892     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9893     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9894
9895     /* now test with PostThreadMessage - different behaviour! */
9896     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9897
9898     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9899     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9900     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9901     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9902
9903     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9904     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9905
9906     /* note: we receive the WM_QUIT message first this time */
9907     ret = GetMessage(&msg, NULL, 0, 0);
9908     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9909     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9910     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9911
9912     ret = GetMessage(&msg, NULL, 0, 0);
9913     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9914     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9915 }
9916
9917 static const struct message WmMouseHoverSeq[] = {
9918     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9919     { WM_MOUSEACTIVATE, sent|optional },
9920     { WM_TIMER, sent|optional }, /* XP sends it */
9921     { WM_SYSTIMER, sent },
9922     { WM_MOUSEHOVER, sent|wparam, 0 },
9923     { 0 }
9924 };
9925
9926 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9927 {
9928     MSG msg;
9929     DWORD start_ticks, end_ticks;
9930
9931     start_ticks = GetTickCount();
9932     /* add some deviation (50%) to cover not expected delays */
9933     start_ticks += timeout / 2;
9934
9935     do
9936     {
9937         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9938         {
9939             /* Timer proc messages are not dispatched to the window proc,
9940              * and therefore not logged.
9941              */
9942             if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
9943             {
9944                 struct recvd_message s_msg;
9945
9946                 s_msg.hwnd = msg.hwnd;
9947                 s_msg.message = msg.message;
9948                 s_msg.flags = sent|wparam|lparam;
9949                 s_msg.wParam = msg.wParam;
9950                 s_msg.lParam = msg.lParam;
9951                 s_msg.descr = "msg_loop";
9952                 add_message(&s_msg);
9953             }
9954             DispatchMessage(&msg);
9955         }
9956
9957         end_ticks = GetTickCount();
9958
9959         /* inject WM_MOUSEMOVE to see how it changes tracking */
9960         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9961         {
9962             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9963             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9964
9965             inject_mouse_move = FALSE;
9966         }
9967     } while (start_ticks + timeout >= end_ticks);
9968 }
9969
9970 static void test_TrackMouseEvent(void)
9971 {
9972     TRACKMOUSEEVENT tme;
9973     BOOL ret;
9974     HWND hwnd, hchild;
9975     RECT rc_parent, rc_child;
9976     UINT default_hover_time, hover_width = 0, hover_height = 0;
9977
9978 #define track_hover(track_hwnd, track_hover_time) \
9979     tme.cbSize = sizeof(tme); \
9980     tme.dwFlags = TME_HOVER; \
9981     tme.hwndTrack = track_hwnd; \
9982     tme.dwHoverTime = track_hover_time; \
9983     SetLastError(0xdeadbeef); \
9984     ret = pTrackMouseEvent(&tme); \
9985     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9986
9987 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9988     tme.cbSize = sizeof(tme); \
9989     tme.dwFlags = TME_QUERY; \
9990     tme.hwndTrack = (HWND)0xdeadbeef; \
9991     tme.dwHoverTime = 0xdeadbeef; \
9992     SetLastError(0xdeadbeef); \
9993     ret = pTrackMouseEvent(&tme); \
9994     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9995     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9996     ok(tme.dwFlags == (expected_track_flags), \
9997        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9998     ok(tme.hwndTrack == (expected_track_hwnd), \
9999        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10000     ok(tme.dwHoverTime == (expected_hover_time), \
10001        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10002
10003 #define track_hover_cancel(track_hwnd) \
10004     tme.cbSize = sizeof(tme); \
10005     tme.dwFlags = TME_HOVER | TME_CANCEL; \
10006     tme.hwndTrack = track_hwnd; \
10007     tme.dwHoverTime = 0xdeadbeef; \
10008     SetLastError(0xdeadbeef); \
10009     ret = pTrackMouseEvent(&tme); \
10010     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10011
10012     default_hover_time = 0xdeadbeef;
10013     SetLastError(0xdeadbeef);
10014     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10015     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10016        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10017     if (!ret) default_hover_time = 400;
10018     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10019
10020     SetLastError(0xdeadbeef);
10021     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10022     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10023        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10024     if (!ret) hover_width = 4;
10025     SetLastError(0xdeadbeef);
10026     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10027     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10028        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10029     if (!ret) hover_height = 4;
10030     trace("hover rect is %u x %d\n", hover_width, hover_height);
10031
10032     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10033                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10034                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10035                           NULL, NULL, 0);
10036     assert(hwnd);
10037
10038     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10039                           WS_CHILD | WS_BORDER | WS_VISIBLE,
10040                           50, 50, 200, 200, hwnd,
10041                           NULL, NULL, 0);
10042     assert(hchild);
10043
10044     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10045     flush_events();
10046     flush_sequence();
10047
10048     tme.cbSize = 0;
10049     tme.dwFlags = TME_QUERY;
10050     tme.hwndTrack = (HWND)0xdeadbeef;
10051     tme.dwHoverTime = 0xdeadbeef;
10052     SetLastError(0xdeadbeef);
10053     ret = pTrackMouseEvent(&tme);
10054     ok(!ret, "TrackMouseEvent should fail\n");
10055     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10056        "not expected error %u\n", GetLastError());
10057
10058     tme.cbSize = sizeof(tme);
10059     tme.dwFlags = TME_HOVER;
10060     tme.hwndTrack = (HWND)0xdeadbeef;
10061     tme.dwHoverTime = 0xdeadbeef;
10062     SetLastError(0xdeadbeef);
10063     ret = pTrackMouseEvent(&tme);
10064     ok(!ret, "TrackMouseEvent should fail\n");
10065     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10066        "not expected error %u\n", GetLastError());
10067
10068     tme.cbSize = sizeof(tme);
10069     tme.dwFlags = TME_HOVER | TME_CANCEL;
10070     tme.hwndTrack = (HWND)0xdeadbeef;
10071     tme.dwHoverTime = 0xdeadbeef;
10072     SetLastError(0xdeadbeef);
10073     ret = pTrackMouseEvent(&tme);
10074     ok(!ret, "TrackMouseEvent should fail\n");
10075     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10076        "not expected error %u\n", GetLastError());
10077
10078     GetWindowRect(hwnd, &rc_parent);
10079     GetWindowRect(hchild, &rc_child);
10080     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10081
10082     /* Process messages so that the system updates its internal current
10083      * window and hittest, otherwise TrackMouseEvent calls don't have any
10084      * effect.
10085      */
10086     flush_events();
10087     flush_sequence();
10088
10089     track_query(0, NULL, 0);
10090     track_hover(hchild, 0);
10091     track_query(0, NULL, 0);
10092
10093     flush_events();
10094     flush_sequence();
10095
10096     track_hover(hwnd, 0);
10097     tme.cbSize = sizeof(tme);
10098     tme.dwFlags = TME_QUERY;
10099     tme.hwndTrack = (HWND)0xdeadbeef;
10100     tme.dwHoverTime = 0xdeadbeef;
10101     SetLastError(0xdeadbeef);
10102     ret = pTrackMouseEvent(&tme);
10103     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10104     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10105     if (!tme.dwFlags)
10106     {
10107         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10108         DestroyWindow( hwnd );
10109         return;
10110     }
10111     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10112     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10113     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10114        tme.dwHoverTime, default_hover_time);
10115
10116     pump_msg_loop_timeout(default_hover_time, FALSE);
10117     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10118
10119     track_query(0, NULL, 0);
10120
10121     track_hover(hwnd, HOVER_DEFAULT);
10122     track_query(TME_HOVER, hwnd, default_hover_time);
10123
10124     Sleep(default_hover_time / 2);
10125     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10126     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10127
10128     track_query(TME_HOVER, hwnd, default_hover_time);
10129
10130     pump_msg_loop_timeout(default_hover_time, FALSE);
10131     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10132
10133     track_query(0, NULL, 0);
10134
10135     track_hover(hwnd, HOVER_DEFAULT);
10136     track_query(TME_HOVER, hwnd, default_hover_time);
10137
10138     pump_msg_loop_timeout(default_hover_time, TRUE);
10139     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10140
10141     track_query(0, NULL, 0);
10142
10143     track_hover(hwnd, HOVER_DEFAULT);
10144     track_query(TME_HOVER, hwnd, default_hover_time);
10145     track_hover_cancel(hwnd);
10146
10147     DestroyWindow(hwnd);
10148
10149 #undef track_hover
10150 #undef track_query
10151 #undef track_hover_cancel
10152 }
10153
10154
10155 static const struct message WmSetWindowRgn[] = {
10156     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10157     { WM_NCCALCSIZE, sent|wparam, 1 },
10158     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10159     { WM_GETTEXT, sent|defwinproc|optional },
10160     { WM_ERASEBKGND, sent|optional },
10161     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10162     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10163     { 0 }
10164 };
10165
10166 static const struct message WmSetWindowRgn_no_redraw[] = {
10167     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10168     { WM_NCCALCSIZE, sent|wparam, 1 },
10169     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10170     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10171     { 0 }
10172 };
10173
10174 static const struct message WmSetWindowRgn_clear[] = {
10175     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10176     { WM_NCCALCSIZE, sent|wparam, 1 },
10177     { WM_NCPAINT, sent|optional },
10178     { WM_GETTEXT, sent|defwinproc|optional },
10179     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10181     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10182     { WM_NCPAINT, sent|optional },
10183     { WM_GETTEXT, sent|defwinproc|optional },
10184     { WM_ERASEBKGND, sent|optional },
10185     { WM_WINDOWPOSCHANGING, sent|optional },
10186     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10187     { WM_NCPAINT, sent|optional },
10188     { WM_GETTEXT, sent|defwinproc|optional },
10189     { WM_ERASEBKGND, sent|optional },
10190     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10191     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10192     { WM_NCPAINT, sent|optional },
10193     { WM_GETTEXT, sent|defwinproc|optional },
10194     { WM_ERASEBKGND, sent|optional },
10195     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10196     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10197     { 0 }
10198 };
10199
10200 static void test_SetWindowRgn(void)
10201 {
10202     HRGN hrgn;
10203     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10204                                 100, 100, 200, 200, 0, 0, 0, NULL);
10205     ok( hwnd != 0, "Failed to create overlapped window\n" );
10206
10207     ShowWindow( hwnd, SW_SHOW );
10208     UpdateWindow( hwnd );
10209     flush_events();
10210     flush_sequence();
10211
10212     trace("testing SetWindowRgn\n");
10213     hrgn = CreateRectRgn( 0, 0, 150, 150 );
10214     SetWindowRgn( hwnd, hrgn, TRUE );
10215     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10216
10217     hrgn = CreateRectRgn( 30, 30, 160, 160 );
10218     SetWindowRgn( hwnd, hrgn, FALSE );
10219     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10220
10221     hrgn = CreateRectRgn( 0, 0, 180, 180 );
10222     SetWindowRgn( hwnd, hrgn, TRUE );
10223     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10224
10225     SetWindowRgn( hwnd, 0, TRUE );
10226     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10227
10228     DestroyWindow( hwnd );
10229 }
10230
10231 /*************************** ShowWindow() test ******************************/
10232 static const struct message WmShowNormal[] = {
10233     { WM_SHOWWINDOW, sent|wparam, 1 },
10234     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10235     { HCBT_ACTIVATE, hook },
10236     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10237     { HCBT_SETFOCUS, hook },
10238     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10239     { 0 }
10240 };
10241 static const struct message WmShow[] = {
10242     { WM_SHOWWINDOW, sent|wparam, 1 },
10243     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10244     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10245     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10246     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10247     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10248     { 0 }
10249 };
10250 static const struct message WmShowNoActivate_1[] = {
10251     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10252     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10253     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10254     { WM_MOVE, sent|defwinproc|optional },
10255     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10256     { 0 }
10257 };
10258 static const struct message WmShowNoActivate_2[] = {
10259     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10260     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10261     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10262     { WM_MOVE, sent|defwinproc },
10263     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10264     { HCBT_SETFOCUS, hook|optional },
10265     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10266     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10267     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10268     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10269     { 0 }
10270 };
10271 static const struct message WmShowNA_1[] = {
10272     { WM_SHOWWINDOW, sent|wparam, 1 },
10273     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10274     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10275     { 0 }
10276 };
10277 static const struct message WmShowNA_2[] = {
10278     { WM_SHOWWINDOW, sent|wparam, 1 },
10279     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10280     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10281     { 0 }
10282 };
10283 static const struct message WmRestore_1[] = {
10284     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10285     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10286     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10287     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10288     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10289     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10290     { WM_MOVE, sent|defwinproc },
10291     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10292     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10293     { 0 }
10294 };
10295 static const struct message WmRestore_2[] = {
10296     { WM_SHOWWINDOW, sent|wparam, 1 },
10297     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10298     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10299     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10300     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10301     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10302     { 0 }
10303 };
10304 static const struct message WmRestore_3[] = {
10305     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10306     { WM_GETMINMAXINFO, sent },
10307     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10308     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10309     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10310     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10311     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10312     { WM_MOVE, sent|defwinproc },
10313     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10314     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10315     { 0 }
10316 };
10317 static const struct message WmRestore_4[] = {
10318     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10319     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10320     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10321     { WM_MOVE, sent|defwinproc|optional },
10322     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10323     { 0 }
10324 };
10325 static const struct message WmRestore_5[] = {
10326     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10327     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10328     { HCBT_ACTIVATE, hook|optional },
10329     { HCBT_SETFOCUS, hook|optional },
10330     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10331     { WM_MOVE, sent|defwinproc|optional },
10332     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10333     { 0 }
10334 };
10335 static const struct message WmHide_1[] = {
10336     { WM_SHOWWINDOW, sent|wparam, 0 },
10337     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10338     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10339     { HCBT_ACTIVATE, hook|optional },
10340     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10341     { 0 }
10342 };
10343 static const struct message WmHide_2[] = {
10344     { WM_SHOWWINDOW, sent|wparam, 0 },
10345     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10346     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10347     { HCBT_ACTIVATE, hook|optional },
10348     { 0 }
10349 };
10350 static const struct message WmHide_3[] = {
10351     { WM_SHOWWINDOW, sent|wparam, 0 },
10352     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10354     { HCBT_SETFOCUS, hook|optional },
10355     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10356     { 0 }
10357 };
10358 static const struct message WmShowMinimized_1[] = {
10359     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10360     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10361     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10362     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10363     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10364     { WM_MOVE, sent|defwinproc },
10365     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10366     { 0 }
10367 };
10368 static const struct message WmMinimize_1[] = {
10369     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10370     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10371     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10372     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10373     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10374     { WM_MOVE, sent|defwinproc },
10375     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10376     { 0 }
10377 };
10378 static const struct message WmMinimize_2[] = {
10379     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10380     { HCBT_SETFOCUS, hook|optional },
10381     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10382     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10383     { WM_MOVE, sent|defwinproc },
10384     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10385     { 0 }
10386 };
10387 static const struct message WmMinimize_3[] = {
10388     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10389     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10390     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10391     { WM_MOVE, sent|defwinproc },
10392     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10393     { 0 }
10394 };
10395 static const struct message WmShowMinNoActivate[] = {
10396     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10397     { WM_WINDOWPOSCHANGING, sent },
10398     { WM_WINDOWPOSCHANGED, sent },
10399     { WM_MOVE, sent|defwinproc|optional },
10400     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10401     { 0 }
10402 };
10403 static const struct message WmMinMax_1[] = {
10404     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10405     { 0 }
10406 };
10407 static const struct message WmMinMax_2[] = {
10408     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10409     { WM_GETMINMAXINFO, sent|optional },
10410     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10411     { HCBT_ACTIVATE, hook|optional },
10412     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10413     { HCBT_SETFOCUS, hook|optional },
10414     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10415     { WM_MOVE, sent|defwinproc|optional },
10416     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10417     { HCBT_SETFOCUS, hook|optional },
10418     { 0 }
10419 };
10420 static const struct message WmMinMax_3[] = {
10421     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10422     { HCBT_SETFOCUS, hook|optional },
10423     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10424     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10425     { WM_MOVE, sent|defwinproc|optional },
10426     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10427     { 0 }
10428 };
10429 static const struct message WmMinMax_4[] = {
10430     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10431     { 0 }
10432 };
10433 static const struct message WmShowMaximized_1[] = {
10434     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10435     { WM_GETMINMAXINFO, sent },
10436     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10437     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10438     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10439     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10440     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10441     { WM_MOVE, sent|defwinproc },
10442     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10443     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10444     { 0 }
10445 };
10446 static const struct message WmShowMaximized_2[] = {
10447     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10448     { WM_GETMINMAXINFO, sent },
10449     { WM_WINDOWPOSCHANGING, sent|optional },
10450     { HCBT_ACTIVATE, hook|optional },
10451     { WM_WINDOWPOSCHANGED, sent|optional },
10452     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10453     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10454     { WM_WINDOWPOSCHANGING, sent|optional },
10455     { HCBT_SETFOCUS, hook|optional },
10456     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10457     { WM_MOVE, sent|defwinproc },
10458     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10459     { HCBT_SETFOCUS, hook|optional },
10460     { 0 }
10461 };
10462 static const struct message WmShowMaximized_3[] = {
10463     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10464     { WM_GETMINMAXINFO, sent|optional },
10465     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10466     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10467     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10468     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10469     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10470     { WM_MOVE, sent|defwinproc|optional },
10471     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10472     { 0 }
10473 };
10474
10475 static void test_ShowWindow(void)
10476 {
10477     /* ShowWindow commands in random order */
10478     static const struct
10479     {
10480         INT cmd; /* ShowWindow command */
10481         LPARAM ret; /* ShowWindow return value */
10482         DWORD style; /* window style after the command */
10483         const struct message *msg; /* message sequence the command produces */
10484         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10485     } sw[] =
10486     {
10487 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10488 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10489 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10490 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10491 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10492 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10493 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10494 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10495 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10496 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10497 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10498 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10499 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10500 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10501 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10502 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10503 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10504 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10505 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10506 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10507 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10508 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10509 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10510 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10511 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10512 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10513 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10514 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10515 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10516 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10517 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10518 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10519 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10520 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10521 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10522 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10523 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10524 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10525 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10526 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10527 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10528 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10529 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10530 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10531 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10532 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10533 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10534 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10535 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10536 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10537 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10538 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10539 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10540 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10541 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10542 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10543 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10544     };
10545     HWND hwnd;
10546     DWORD style;
10547     LPARAM ret;
10548     INT i;
10549
10550 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10551     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10552                           120, 120, 90, 90,
10553                           0, 0, 0, NULL);
10554     assert(hwnd);
10555
10556     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10557     ok(style == 0, "expected style 0, got %08x\n", style);
10558
10559     flush_events();
10560     flush_sequence();
10561
10562     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10563     {
10564         static const char * const sw_cmd_name[13] =
10565         {
10566             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10567             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10568             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10569             "SW_NORMALNA" /* 0xCC */
10570         };
10571         char comment[64];
10572         INT idx; /* index into the above array of names */
10573
10574         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10575
10576         style = GetWindowLong(hwnd, GWL_STYLE);
10577         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10578         ret = ShowWindow(hwnd, sw[i].cmd);
10579         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10580         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10581         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10582
10583         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10584         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10585
10586         flush_events();
10587         flush_sequence();
10588     }
10589
10590     DestroyWindow(hwnd);
10591 }
10592
10593 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10594 {
10595     struct recvd_message msg;
10596
10597     if (ignore_message( message )) return 0;
10598
10599     msg.hwnd = hwnd;
10600     msg.message = message;
10601     msg.flags = sent|wparam|lparam;
10602     msg.wParam = wParam;
10603     msg.lParam = lParam;
10604     msg.descr = "dialog";
10605     add_message(&msg);
10606
10607     /* calling DefDlgProc leads to a recursion under XP */
10608
10609     switch (message)
10610     {
10611     case WM_INITDIALOG:
10612     case WM_GETDLGCODE:
10613         return 0;
10614     }
10615     return 1;
10616 }
10617
10618 static const struct message WmDefDlgSetFocus_1[] = {
10619     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10620     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10621     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10622     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10623     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10624     { HCBT_SETFOCUS, hook },
10625     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10626     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10627     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10628     { WM_SETFOCUS, sent|wparam, 0 },
10629     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10630     { WM_CTLCOLOREDIT, sent },
10631     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10632     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10633     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10634     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10635     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10636     { 0 }
10637 };
10638 static const struct message WmDefDlgSetFocus_2[] = {
10639     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10640     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10641     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10642     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10643     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10644     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10645     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10646     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10647     { 0 }
10648 };
10649 /* Creation of a dialog */
10650 static const struct message WmCreateDialogParamSeq_1[] = {
10651     { HCBT_CREATEWND, hook },
10652     { WM_NCCREATE, sent },
10653     { WM_NCCALCSIZE, sent|wparam, 0 },
10654     { WM_CREATE, sent },
10655     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10656     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10657     { WM_MOVE, sent },
10658     { WM_SETFONT, sent },
10659     { WM_INITDIALOG, sent },
10660     { WM_CHANGEUISTATE, sent|optional },
10661     { 0 }
10662 };
10663 /* Creation of a dialog */
10664 static const struct message WmCreateDialogParamSeq_2[] = {
10665     { HCBT_CREATEWND, hook },
10666     { WM_NCCREATE, sent },
10667     { WM_NCCALCSIZE, sent|wparam, 0 },
10668     { WM_CREATE, sent },
10669     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10670     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10671     { WM_MOVE, sent },
10672     { WM_CHANGEUISTATE, sent|optional },
10673     { 0 }
10674 };
10675
10676 static void test_dialog_messages(void)
10677 {
10678     WNDCLASS cls;
10679     HWND hdlg, hedit1, hedit2, hfocus;
10680     LRESULT ret;
10681
10682 #define set_selection(hctl, start, end) \
10683     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10684     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10685
10686 #define check_selection(hctl, start, end) \
10687     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10688     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10689
10690     subclass_edit();
10691
10692     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10693                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10694                           0, 0, 100, 100, 0, 0, 0, NULL);
10695     ok(hdlg != 0, "Failed to create custom dialog window\n");
10696
10697     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10698                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10699                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10700     ok(hedit1 != 0, "Failed to create edit control\n");
10701     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10702                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10703                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10704     ok(hedit2 != 0, "Failed to create edit control\n");
10705
10706     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10707     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10708
10709     hfocus = GetFocus();
10710     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10711
10712     SetFocus(hedit2);
10713     hfocus = GetFocus();
10714     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10715
10716     check_selection(hedit1, 0, 0);
10717     check_selection(hedit2, 0, 0);
10718
10719     set_selection(hedit2, 0, -1);
10720     check_selection(hedit2, 0, 3);
10721
10722     SetFocus(0);
10723     hfocus = GetFocus();
10724     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10725
10726     flush_sequence();
10727     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10728     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10729     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10730
10731     hfocus = GetFocus();
10732     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10733
10734     check_selection(hedit1, 0, 5);
10735     check_selection(hedit2, 0, 3);
10736
10737     flush_sequence();
10738     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10739     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10740     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10741
10742     hfocus = GetFocus();
10743     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10744
10745     check_selection(hedit1, 0, 5);
10746     check_selection(hedit2, 0, 3);
10747
10748     EndDialog(hdlg, 0);
10749     DestroyWindow(hedit1);
10750     DestroyWindow(hedit2);
10751     DestroyWindow(hdlg);
10752     flush_sequence();
10753
10754 #undef set_selection
10755 #undef check_selection
10756
10757     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10758     cls.lpszClassName = "MyDialogClass";
10759     cls.hInstance = GetModuleHandle(0);
10760     /* need a cast since a dlgproc is used as a wndproc */
10761     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10762     if (!RegisterClass(&cls)) assert(0);
10763
10764     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10765     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10766     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10767     EndDialog(hdlg, 0);
10768     DestroyWindow(hdlg);
10769     flush_sequence();
10770
10771     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10772     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10773     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10774     EndDialog(hdlg, 0);
10775     DestroyWindow(hdlg);
10776     flush_sequence();
10777
10778     UnregisterClass(cls.lpszClassName, cls.hInstance);
10779 }
10780
10781 static void test_nullCallback(void)
10782 {
10783     HWND hwnd;
10784
10785     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10786                            100, 100, 200, 200, 0, 0, 0, NULL);
10787     ok (hwnd != 0, "Failed to create overlapped window\n");
10788
10789     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10790     flush_events();
10791     DestroyWindow(hwnd);
10792 }
10793
10794 /* SetActiveWindow( 0 ) hwnd visible */
10795 static const struct message SetActiveWindowSeq0[] =
10796 {
10797     { HCBT_ACTIVATE, hook|optional },
10798     { WM_NCACTIVATE, sent|wparam, 0 },
10799     { WM_GETTEXT, sent|defwinproc|optional },
10800     { WM_ACTIVATE, sent|wparam, 0 },
10801     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10802     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10803     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10804     { WM_KILLFOCUS, sent|optional },
10805     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10806     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10807     { WM_NCACTIVATE, sent|wparam|optional, 1 },
10808     { WM_GETTEXT, sent|defwinproc|optional },
10809     { WM_ACTIVATE, sent|wparam|optional, 1 },
10810     { HCBT_SETFOCUS, hook|optional },
10811     { WM_KILLFOCUS, sent|defwinproc|optional },
10812     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10813     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10814     { WM_IME_SETCONTEXT, sent|optional },
10815     { WM_IME_SETCONTEXT, sent|optional },
10816     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10817     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10818     { WM_SETFOCUS, sent|defwinproc|optional },
10819     { WM_GETTEXT, sent|optional },
10820     { 0 }
10821 };
10822 /* SetActiveWindow( hwnd ) hwnd visible */
10823 static const struct message SetActiveWindowSeq1[] =
10824 {
10825     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10826     { 0 }
10827 };
10828 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10829 static const struct message SetActiveWindowSeq2[] =
10830 {
10831     { HCBT_ACTIVATE, hook },
10832     { WM_NCACTIVATE, sent|wparam, 0 },
10833     { WM_GETTEXT, sent|defwinproc|optional },
10834     { WM_ACTIVATE, sent|wparam, 0 },
10835     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10836     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10837     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10838     { WM_NCPAINT, sent|optional },
10839     { WM_GETTEXT, sent|defwinproc|optional },
10840     { WM_ERASEBKGND, sent|optional },
10841     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10842     { WM_NCACTIVATE, sent|wparam, 1 },
10843     { WM_GETTEXT, sent|defwinproc|optional },
10844     { WM_ACTIVATE, sent|wparam, 1 },
10845     { HCBT_SETFOCUS, hook },
10846     { WM_KILLFOCUS, sent|defwinproc },
10847     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10848     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10849     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10850     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10851     { WM_SETFOCUS, sent|defwinproc },
10852     { WM_GETTEXT, sent|optional },
10853     { 0 }
10854 };
10855
10856 /* SetActiveWindow( hwnd ) hwnd not visible */
10857 static const struct message SetActiveWindowSeq3[] =
10858 {
10859     { HCBT_ACTIVATE, hook },
10860     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10861     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10862     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10863     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10864     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10865     { WM_ACTIVATEAPP, sent|wparam, 1 },
10866     { WM_ACTIVATEAPP, sent|wparam, 1 },
10867     { WM_NCACTIVATE, sent|wparam, 1 },
10868     { WM_ACTIVATE, sent|wparam, 1 },
10869     { HCBT_SETFOCUS, hook },
10870     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10871     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10872     { WM_SETFOCUS, sent|defwinproc },
10873     { 0 }
10874 };
10875 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10876 static const struct message SetActiveWindowSeq4[] =
10877 {
10878     { HCBT_ACTIVATE, hook },
10879     { WM_NCACTIVATE, sent|wparam, 0 },
10880     { WM_GETTEXT, sent|defwinproc|optional },
10881     { WM_ACTIVATE, sent|wparam, 0 },
10882     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10883     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10884     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10885     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10886     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10887     { WM_NCACTIVATE, sent|wparam, 1 },
10888     { WM_GETTEXT, sent|defwinproc|optional },
10889     { WM_ACTIVATE, sent|wparam, 1 },
10890     { HCBT_SETFOCUS, hook },
10891     { WM_KILLFOCUS, sent|defwinproc },
10892     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10893     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10894     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10895     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10896     { WM_SETFOCUS, sent|defwinproc },
10897     { 0 }
10898 };
10899
10900
10901 static void test_SetActiveWindow(void)
10902 {
10903     HWND hwnd, popup, ret;
10904
10905     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10906                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10907                            100, 100, 200, 200, 0, 0, 0, NULL);
10908
10909     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10910                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10911                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10912
10913     ok(hwnd != 0, "Failed to create overlapped window\n");
10914     ok(popup != 0, "Failed to create popup window\n");
10915     SetForegroundWindow( popup );
10916     flush_sequence();
10917
10918     trace("SetActiveWindow(0)\n");
10919     ret = SetActiveWindow(0);
10920     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10921     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10922     flush_sequence();
10923
10924     trace("SetActiveWindow(hwnd), hwnd visible\n");
10925     ret = SetActiveWindow(hwnd);
10926     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10927     flush_sequence();
10928
10929     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10930     ret = SetActiveWindow(popup);
10931     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10932     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10933     flush_sequence();
10934
10935     ShowWindow(hwnd, SW_HIDE);
10936     ShowWindow(popup, SW_HIDE);
10937     flush_sequence();
10938
10939     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10940     ret = SetActiveWindow(hwnd);
10941     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10942     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10943     flush_sequence();
10944
10945     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10946     ret = SetActiveWindow(popup);
10947     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10948     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10949     flush_sequence();
10950
10951     trace("done\n");
10952
10953     DestroyWindow(hwnd);
10954 }
10955
10956 static const struct message SetForegroundWindowSeq[] =
10957 {
10958     { WM_NCACTIVATE, sent|wparam, 0 },
10959     { WM_GETTEXT, sent|defwinproc|optional },
10960     { WM_ACTIVATE, sent|wparam, 0 },
10961     { WM_ACTIVATEAPP, sent|wparam, 0 },
10962     { WM_KILLFOCUS, sent },
10963     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10964     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10965     { 0 }
10966 };
10967
10968 static void test_SetForegroundWindow(void)
10969 {
10970     HWND hwnd;
10971
10972     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10973                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10974                            100, 100, 200, 200, 0, 0, 0, NULL);
10975     ok (hwnd != 0, "Failed to create overlapped window\n");
10976     SetForegroundWindow( hwnd );
10977     flush_sequence();
10978
10979     trace("SetForegroundWindow( 0 )\n");
10980     SetForegroundWindow( 0 );
10981     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10982     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10983     SetForegroundWindow( GetDesktopWindow() );
10984     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10985                                         "foreground top level window", FALSE);
10986     trace("done\n");
10987
10988     DestroyWindow(hwnd);
10989 }
10990
10991 static void test_dbcs_wm_char(void)
10992 {
10993     BYTE dbch[2];
10994     WCHAR wch, bad_wch;
10995     HWND hwnd, hwnd2;
10996     MSG msg;
10997     DWORD time;
10998     POINT pt;
10999     DWORD_PTR res;
11000     CPINFOEXA cpinfo;
11001     UINT i, j, k;
11002     struct message wmCharSeq[2];
11003
11004     if (!pGetCPInfoExA)
11005     {
11006         win_skip("GetCPInfoExA is not available\n");
11007         return;
11008     }
11009
11010     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11011     if (cpinfo.MaxCharSize != 2)
11012     {
11013         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11014         return;
11015     }
11016
11017     dbch[0] = dbch[1] = 0;
11018     wch = 0;
11019     bad_wch = cpinfo.UnicodeDefaultChar;
11020     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11021         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11022             for (k = 128; k <= 255; k++)
11023             {
11024                 char str[2];
11025                 WCHAR wstr[2];
11026                 str[0] = j;
11027                 str[1] = k;
11028                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11029                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11030                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
11031                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11032                 {
11033                     dbch[0] = j;
11034                     dbch[1] = k;
11035                     wch = wstr[0];
11036                     break;
11037                 }
11038             }
11039
11040     if (!wch)
11041     {
11042         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11043         return;
11044     }
11045     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11046            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11047
11048     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11049                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11050     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11051                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11052     ok (hwnd != 0, "Failed to create overlapped window\n");
11053     ok (hwnd2 != 0, "Failed to create overlapped window\n");
11054     flush_sequence();
11055
11056     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11057     wmCharSeq[0].message = WM_CHAR;
11058     wmCharSeq[0].flags = sent|wparam;
11059     wmCharSeq[0].wParam = wch;
11060
11061     /* posted message */
11062     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11063     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11064     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11065     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11066     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11067     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11068     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11069
11070     /* posted thread message */
11071     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11072     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11073     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11074     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11075     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11076     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11077     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11078
11079     /* sent message */
11080     flush_sequence();
11081     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11082     ok_sequence( WmEmptySeq, "no messages", FALSE );
11083     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11084     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11085     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11086
11087     /* sent message with timeout */
11088     flush_sequence();
11089     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11090     ok_sequence( WmEmptySeq, "no messages", FALSE );
11091     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11092     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11093     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11094
11095     /* sent message with timeout and callback */
11096     flush_sequence();
11097     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11098     ok_sequence( WmEmptySeq, "no messages", FALSE );
11099     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11100     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11101     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11102
11103     /* sent message with callback */
11104     flush_sequence();
11105     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11106     ok_sequence( WmEmptySeq, "no messages", FALSE );
11107     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11108     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11109     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11110
11111     /* direct window proc call */
11112     flush_sequence();
11113     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11114     ok_sequence( WmEmptySeq, "no messages", FALSE );
11115     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11116     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11117
11118     /* dispatch message */
11119     msg.hwnd = hwnd;
11120     msg.message = WM_CHAR;
11121     msg.wParam = dbch[0];
11122     msg.lParam = 0;
11123     DispatchMessageA( &msg );
11124     ok_sequence( WmEmptySeq, "no messages", FALSE );
11125     msg.wParam = dbch[1];
11126     DispatchMessageA( &msg );
11127     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11128
11129     /* window handle is irrelevant */
11130     flush_sequence();
11131     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11132     ok_sequence( WmEmptySeq, "no messages", FALSE );
11133     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11134     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11135     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11136
11137     /* interleaved post and send */
11138     flush_sequence();
11139     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11140     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11141     ok_sequence( WmEmptySeq, "no messages", FALSE );
11142     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11143     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11144     ok_sequence( WmEmptySeq, "no messages", FALSE );
11145     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11146     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11147     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11148     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11149     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11150     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11151     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11152
11153     /* interleaved sent message and winproc */
11154     flush_sequence();
11155     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11156     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11157     ok_sequence( WmEmptySeq, "no messages", FALSE );
11158     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11159     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11160     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11161     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11162
11163     /* interleaved winproc and dispatch */
11164     msg.hwnd = hwnd;
11165     msg.message = WM_CHAR;
11166     msg.wParam = dbch[0];
11167     msg.lParam = 0;
11168     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11169     DispatchMessageA( &msg );
11170     ok_sequence( WmEmptySeq, "no messages", FALSE );
11171     msg.wParam = dbch[1];
11172     DispatchMessageA( &msg );
11173     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11174     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11175     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11176
11177     /* interleaved sends */
11178     flush_sequence();
11179     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11180     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11181     ok_sequence( WmEmptySeq, "no messages", FALSE );
11182     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11183     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11184     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11185     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11186
11187     /* dbcs WM_CHAR */
11188     flush_sequence();
11189     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11190     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11191     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11192
11193     /* other char messages are not magic */
11194     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11195     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11196     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11197     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11198     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11199     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11200     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11201     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11202     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11203     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11204
11205     /* test retrieving messages */
11206
11207     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11208     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11209     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11210     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11211     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11212     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11213     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11214     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11215     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11216     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11217
11218     /* message filters */
11219     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11220     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11221     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11222     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11223     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11224     /* message id is filtered, hwnd is not */
11225     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11226     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11227     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11228     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11229     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11230     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11231
11232     /* mixing GetMessage and PostMessage */
11233     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11234     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11235     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11236     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11237     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11238     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11239     time = msg.time;
11240     pt = msg.pt;
11241     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11242     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11243     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11244     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11245     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11246     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11247     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11248     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 );
11249     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11250
11251     /* without PM_REMOVE */
11252     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11253     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11254     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11255     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11256     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11257     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11258     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11259     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11260     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11261     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11262     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11263     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11264     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11265     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11266     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11267     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11268     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11269     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11270
11271     DestroyWindow(hwnd);
11272 }
11273
11274 #define ID_LISTBOX 0x000f
11275
11276 static const struct message wm_lb_setcursel_0[] =
11277 {
11278     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11279     { WM_CTLCOLORLISTBOX, sent|parent },
11280     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11281     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11282     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11283     { 0 }
11284 };
11285 static const struct message wm_lb_setcursel_1[] =
11286 {
11287     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11288     { WM_CTLCOLORLISTBOX, sent|parent },
11289     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11290     { WM_CTLCOLORLISTBOX, sent|parent },
11291     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11292     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11293     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11294     { 0 }
11295 };
11296 static const struct message wm_lb_setcursel_2[] =
11297 {
11298     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11299     { WM_CTLCOLORLISTBOX, sent|parent },
11300     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11301     { WM_CTLCOLORLISTBOX, sent|parent },
11302     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11303     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11304     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11305     { 0 }
11306 };
11307 static const struct message wm_lb_click_0[] =
11308 {
11309     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11310     { HCBT_SETFOCUS, hook },
11311     { WM_KILLFOCUS, sent|parent },
11312     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11313     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11314     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11315     { WM_SETFOCUS, sent|defwinproc },
11316
11317     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11318     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11319     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11320     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11321     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11322
11323     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11324     { WM_CTLCOLORLISTBOX, sent|parent },
11325     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11326     { WM_CTLCOLORLISTBOX, sent|parent },
11327     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11328     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11329
11330     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11331     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11332
11333     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11334     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11335     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11336     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11337     { 0 }
11338 };
11339 static const struct message wm_lb_deletestring[] =
11340 {
11341     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11342     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11343     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11344     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11345     { 0 }
11346 };
11347 static const struct message wm_lb_deletestring_reset[] =
11348 {
11349     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11350     { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11351     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11352     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11353     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11354     { 0 }
11355 };
11356
11357 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11358
11359 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11360
11361 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11362 {
11363     static LONG defwndproc_counter = 0;
11364     LRESULT ret;
11365     struct recvd_message msg;
11366
11367     /* do not log painting messages */
11368     if (message != WM_PAINT &&
11369         message != WM_NCPAINT &&
11370         message != WM_SYNCPAINT &&
11371         message != WM_ERASEBKGND &&
11372         message != WM_NCHITTEST &&
11373         message != WM_GETTEXT &&
11374         !ignore_message( message ))
11375     {
11376         msg.hwnd = hwnd;
11377         msg.message = message;
11378         msg.flags = sent|wparam|lparam;
11379         if (defwndproc_counter) msg.flags |= defwinproc;
11380         msg.wParam = wp;
11381         msg.lParam = lp;
11382         msg.descr = "listbox";
11383         add_message(&msg);
11384     }
11385
11386     defwndproc_counter++;
11387     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11388     defwndproc_counter--;
11389
11390     return ret;
11391 }
11392
11393 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11394                                int caret_index, int top_index, int line)
11395 {
11396     LRESULT ret;
11397
11398     /* calling an orig proc helps to avoid unnecessary message logging */
11399     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11400     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11401     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11402     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11403     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11404     ok_(__FILE__, line)(ret == caret_index ||
11405                         broken(cur_sel == -1 && caret_index == 0 && ret == -1),  /* nt4 */
11406                         "expected caret index %d, got %ld\n", caret_index, ret);
11407     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11408     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11409 }
11410
11411 static void test_listbox_messages(void)
11412 {
11413     HWND parent, listbox;
11414     LRESULT ret;
11415
11416     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11417                              100, 100, 200, 200, 0, 0, 0, NULL);
11418     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11419                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11420                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11421     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11422
11423     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11424
11425     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11426     ok(ret == 0, "expected 0, got %ld\n", ret);
11427     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11428     ok(ret == 1, "expected 1, got %ld\n", ret);
11429     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11430     ok(ret == 2, "expected 2, got %ld\n", ret);
11431
11432     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11433
11434     flush_sequence();
11435
11436     log_all_parent_messages++;
11437
11438     trace("selecting item 0\n");
11439     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11440     ok(ret == 0, "expected 0, got %ld\n", ret);
11441     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11442     check_lb_state(listbox, 3, 0, 0, 0);
11443     flush_sequence();
11444
11445     trace("selecting item 1\n");
11446     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11447     ok(ret == 1, "expected 1, got %ld\n", ret);
11448     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11449     check_lb_state(listbox, 3, 1, 1, 0);
11450
11451     trace("selecting item 2\n");
11452     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11453     ok(ret == 2, "expected 2, got %ld\n", ret);
11454     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11455     check_lb_state(listbox, 3, 2, 2, 0);
11456
11457     trace("clicking on item 0\n");
11458     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11459     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11460     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11461     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11462     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11463     check_lb_state(listbox, 3, 0, 0, 0);
11464     flush_sequence();
11465
11466     trace("deleting item 0\n");
11467     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11468     ok(ret == 2, "expected 2, got %ld\n", ret);
11469     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11470     check_lb_state(listbox, 2, -1, 0, 0);
11471     flush_sequence();
11472
11473     trace("deleting item 0\n");
11474     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11475     ok(ret == 1, "expected 1, got %ld\n", ret);
11476     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11477     check_lb_state(listbox, 1, -1, 0, 0);
11478     flush_sequence();
11479
11480     trace("deleting item 0\n");
11481     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11482     ok(ret == 0, "expected 0, got %ld\n", ret);
11483     ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11484     check_lb_state(listbox, 0, -1, 0, 0);
11485     flush_sequence();
11486
11487     trace("deleting item 0\n");
11488     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11489     ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11490     check_lb_state(listbox, 0, -1, 0, 0);
11491     flush_sequence();
11492
11493     log_all_parent_messages--;
11494
11495     DestroyWindow(listbox);
11496     DestroyWindow(parent);
11497 }
11498
11499 /*************************** Menu test ******************************/
11500 static const struct message wm_popup_menu_1[] =
11501 {
11502     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11503     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11504     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11505     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11506     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11507     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11508     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11509     { WM_INITMENU, sent|lparam, 0, 0 },
11510     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11511     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11512     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11513     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11514     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11515     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11516     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11517     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
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, 200 - 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_2[] =
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_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11558     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11559     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11560     { 0 }
11561 };
11562 static const struct message wm_popup_menu_3[] =
11563 {
11564     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11565     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11566     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11567     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11568     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11569     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11570     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11571     { WM_INITMENU, sent|lparam, 0, 0 },
11572     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11573     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11574     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11575     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11576     { HCBT_CREATEWND, hook },
11577     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11578                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11579     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11580     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11581     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11582     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11583     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11584     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11585     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11586     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11587     { HCBT_DESTROYWND, hook },
11588     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11589     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11590     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11591     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11592     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11593     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11594     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11595     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11596     { 0 }
11597 };
11598
11599 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11600 {
11601     if (message == WM_ENTERIDLE ||
11602         message == WM_INITMENU ||
11603         message == WM_INITMENUPOPUP ||
11604         message == WM_MENUSELECT ||
11605         message == WM_PARENTNOTIFY ||
11606         message == WM_ENTERMENULOOP ||
11607         message == WM_EXITMENULOOP ||
11608         message == WM_UNINITMENUPOPUP ||
11609         message == WM_KEYDOWN ||
11610         message == WM_KEYUP ||
11611         message == WM_CHAR ||
11612         message == WM_SYSKEYDOWN ||
11613         message == WM_SYSKEYUP ||
11614         message == WM_SYSCHAR ||
11615         message == WM_COMMAND ||
11616         message == WM_MENUCOMMAND)
11617     {
11618         struct recvd_message msg;
11619
11620         msg.hwnd = hwnd;
11621         msg.message = message;
11622         msg.flags = sent|wparam|lparam;
11623         msg.wParam = wp;
11624         msg.lParam = lp;
11625         msg.descr = "parent_menu_proc";
11626         add_message(&msg);
11627     }
11628
11629     return DefWindowProcA(hwnd, message, wp, lp);
11630 }
11631
11632 static void set_menu_style(HMENU hmenu, DWORD style)
11633 {
11634     MENUINFO mi;
11635     BOOL ret;
11636
11637     mi.cbSize = sizeof(mi);
11638     mi.fMask = MIM_STYLE;
11639     mi.dwStyle = style;
11640     SetLastError(0xdeadbeef);
11641     ret = pSetMenuInfo(hmenu, &mi);
11642     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11643 }
11644
11645 static DWORD get_menu_style(HMENU hmenu)
11646 {
11647     MENUINFO mi;
11648     BOOL ret;
11649
11650     mi.cbSize = sizeof(mi);
11651     mi.fMask = MIM_STYLE;
11652     mi.dwStyle = 0;
11653     SetLastError(0xdeadbeef);
11654     ret = pGetMenuInfo(hmenu, &mi);
11655     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11656
11657     return mi.dwStyle;
11658 }
11659
11660 static void test_menu_messages(void)
11661 {
11662     MSG msg;
11663     WNDCLASSA cls;
11664     HMENU hmenu, hmenu_popup;
11665     HWND hwnd;
11666     DWORD style;
11667
11668     if (!pGetMenuInfo || !pSetMenuInfo)
11669     {
11670         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11671         return;
11672     }
11673     cls.style = 0;
11674     cls.lpfnWndProc = parent_menu_proc;
11675     cls.cbClsExtra = 0;
11676     cls.cbWndExtra = 0;
11677     cls.hInstance = GetModuleHandleA(0);
11678     cls.hIcon = 0;
11679     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11680     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11681     cls.lpszMenuName = NULL;
11682     cls.lpszClassName = "TestMenuClass";
11683     UnregisterClass(cls.lpszClassName, cls.hInstance);
11684     if (!RegisterClassA(&cls)) assert(0);
11685
11686     SetLastError(0xdeadbeef);
11687     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11688                            100, 100, 200, 200, 0, 0, 0, NULL);
11689     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11690
11691     SetLastError(0xdeadbeef);
11692     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11693     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11694
11695     SetMenu(hwnd, hmenu);
11696     SetForegroundWindow( hwnd );
11697
11698     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11699     style = get_menu_style(hmenu);
11700     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11701
11702     hmenu_popup = GetSubMenu(hmenu, 0);
11703     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11704     style = get_menu_style(hmenu_popup);
11705     ok(style == 0, "expected 0, got %u\n", style);
11706
11707     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11708     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11709     style = get_menu_style(hmenu_popup);
11710     ok(style == 0, "expected 0, got %u\n", style);
11711
11712     /* Alt+E, Enter */
11713     trace("testing a popup menu command\n");
11714     flush_sequence();
11715     keybd_event(VK_MENU, 0, 0, 0);
11716     keybd_event('E', 0, 0, 0);
11717     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11718     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11719     keybd_event(VK_RETURN, 0, 0, 0);
11720     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11721     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11722     {
11723         TranslateMessage(&msg);
11724         DispatchMessage(&msg);
11725     }
11726     if (!sequence_cnt)  /* we didn't get any message */
11727     {
11728         skip( "queuing key events not supported\n" );
11729         goto done;
11730     }
11731     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11732     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11733     {
11734         win_skip( "menu tracking through VK_MENU not supported\n" );
11735         goto done;
11736     }
11737     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11738
11739     /* Alt+F, Right, Enter */
11740     trace("testing submenu of a popup menu command\n");
11741     flush_sequence();
11742     keybd_event(VK_MENU, 0, 0, 0);
11743     keybd_event('F', 0, 0, 0);
11744     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11745     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11746     keybd_event(VK_RIGHT, 0, 0, 0);
11747     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11748     keybd_event(VK_RETURN, 0, 0, 0);
11749     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11750     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11751     {
11752         TranslateMessage(&msg);
11753         DispatchMessage(&msg);
11754     }
11755     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11756
11757     set_menu_style(hmenu, 0);
11758     style = get_menu_style(hmenu);
11759     ok(style == 0, "expected 0, got %u\n", style);
11760
11761     hmenu_popup = GetSubMenu(hmenu, 0);
11762     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11763     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11764     style = get_menu_style(hmenu_popup);
11765     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11766
11767     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11768     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11769     style = get_menu_style(hmenu_popup);
11770     ok(style == 0, "expected 0, got %u\n", style);
11771
11772     /* Alt+F, Right, Enter */
11773     trace("testing submenu of a popup menu command\n");
11774     flush_sequence();
11775     keybd_event(VK_MENU, 0, 0, 0);
11776     keybd_event('F', 0, 0, 0);
11777     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11778     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11779     keybd_event(VK_RIGHT, 0, 0, 0);
11780     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11781     keybd_event(VK_RETURN, 0, 0, 0);
11782     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11783     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11784     {
11785         TranslateMessage(&msg);
11786         DispatchMessage(&msg);
11787     }
11788     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11789
11790 done:
11791     DestroyWindow(hwnd);
11792     DestroyMenu(hmenu);
11793 }
11794
11795
11796 static void test_paintingloop(void)
11797 {
11798     HWND hwnd;
11799
11800     paint_loop_done = 0;
11801     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11802                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11803                                 100, 100, 100, 100, 0, 0, 0, NULL );
11804     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11805     ShowWindow(hwnd,SW_NORMAL);
11806     SetFocus(hwnd);
11807
11808     while (!paint_loop_done)
11809     {
11810         MSG msg;
11811         if (PeekMessageA(&msg, 0, 0, 0, 1))
11812         {
11813             TranslateMessage(&msg);
11814             DispatchMessage(&msg);
11815         }
11816     }
11817     DestroyWindow(hwnd);
11818 }
11819
11820 static void test_defwinproc(void)
11821 {
11822     HWND hwnd;
11823     MSG msg;
11824     int gotwmquit = FALSE;
11825     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11826     assert(hwnd);
11827     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11828     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11829         if( msg.message == WM_QUIT) gotwmquit = TRUE;
11830         DispatchMessageA( &msg );
11831     }
11832     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11833     DestroyWindow( hwnd);
11834 }
11835
11836 #define clear_clipboard(hwnd)  clear_clipboard_(__LINE__, (hwnd))
11837 static void clear_clipboard_(int line, HWND hWnd)
11838 {
11839     BOOL succ;
11840     succ = OpenClipboard(hWnd);
11841     ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
11842     succ = EmptyClipboard();
11843     ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
11844     succ = CloseClipboard();
11845     ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
11846 }
11847
11848 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
11849 static void expect_HWND_(int line, HWND expected, HWND got)
11850 {
11851     ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
11852 }
11853
11854 static WNDPROC pOldViewerProc;
11855
11856 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
11857 {
11858     static BOOL recursion_guard;
11859
11860     if (message == WM_DRAWCLIPBOARD && !recursion_guard)
11861     {
11862         recursion_guard = TRUE;
11863         clear_clipboard(hWnd);
11864         recursion_guard = FALSE;
11865     }
11866     return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
11867 }
11868
11869 static void test_clipboard_viewers(void)
11870 {
11871     static struct message wm_change_cb_chain[] =
11872     {
11873         { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
11874         { 0 }
11875     };
11876     static const struct message wm_clipboard_destroyed[] =
11877     {
11878         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11879         { 0 }
11880     };
11881     static struct message wm_clipboard_changed[] =
11882     {
11883         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11884         { 0 }
11885     };
11886     static struct message wm_clipboard_changed_and_owned[] =
11887     {
11888         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11889         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11890         { 0 }
11891     };
11892
11893     HINSTANCE hInst = GetModuleHandleA(NULL);
11894     HWND hWnd1, hWnd2, hWnd3;
11895     HWND hOrigViewer;
11896     HWND hRet;
11897
11898     hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
11899         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11900         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11901         GetDesktopWindow(), NULL, hInst, NULL);
11902     hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
11903         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11904         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11905         GetDesktopWindow(), NULL, hInst, NULL);
11906     hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
11907         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11908         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11909         GetDesktopWindow(), NULL, hInst, NULL);
11910     trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
11911     assert(hWnd1 && hWnd2 && hWnd3);
11912
11913     flush_sequence();
11914
11915     /* Test getting the clipboard viewer and setting the viewer to NULL. */
11916     hOrigViewer = GetClipboardViewer();
11917     hRet = SetClipboardViewer(NULL);
11918     ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
11919     expect_HWND(hOrigViewer, hRet);
11920     expect_HWND(NULL, GetClipboardViewer());
11921
11922     /* Test registering hWnd1 as a viewer. */
11923     hRet = SetClipboardViewer(hWnd1);
11924     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11925     ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
11926     expect_HWND(NULL, hRet);
11927     expect_HWND(hWnd1, GetClipboardViewer());
11928
11929     /* Test that changing the clipboard actually refreshes the registered viewer. */
11930     clear_clipboard(hWnd1);
11931     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11932     ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
11933
11934     /* Again, but with different owner. */
11935     clear_clipboard(hWnd2);
11936     wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
11937     ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
11938
11939     /* Test re-registering same window. */
11940     hRet = SetClipboardViewer(hWnd1);
11941     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11942     ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
11943     expect_HWND(hWnd1, hRet);
11944     expect_HWND(hWnd1, GetClipboardViewer());
11945
11946     /* Test ChangeClipboardChain. */
11947     ChangeClipboardChain(hWnd2, hWnd3);
11948     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11949     wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
11950     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
11951     expect_HWND(hWnd1, GetClipboardViewer());
11952
11953     ChangeClipboardChain(hWnd2, NULL);
11954     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11955     wm_change_cb_chain[0].lParam = 0;
11956     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
11957     expect_HWND(hWnd1, GetClipboardViewer());
11958
11959     ChangeClipboardChain(NULL, hWnd2);
11960     ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
11961     expect_HWND(hWnd1, GetClipboardViewer());
11962
11963     /* Actually change clipboard viewer with ChangeClipboardChain. */
11964     ChangeClipboardChain(hWnd1, hWnd2);
11965     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
11966     expect_HWND(hWnd2, GetClipboardViewer());
11967
11968     /* Test that no refresh messages are sent when viewer has unregistered. */
11969     clear_clipboard(hWnd2);
11970     ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
11971
11972     /* Register hWnd1 again. */
11973     ChangeClipboardChain(hWnd2, hWnd1);
11974     ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
11975     expect_HWND(hWnd1, GetClipboardViewer());
11976
11977     /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
11978      * changes the clipboard. When this happens, the system shouldn't send
11979      * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
11980      */
11981     pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
11982     clear_clipboard(hWnd2);
11983     /* The clipboard owner is changed in recursive_viewer_proc: */
11984     wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
11985     ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
11986
11987     /* Test unregistering. */
11988     ChangeClipboardChain(hWnd1, NULL);
11989     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
11990     expect_HWND(NULL, GetClipboardViewer());
11991
11992     clear_clipboard(hWnd1);
11993     ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
11994
11995     DestroyWindow(hWnd1);
11996     DestroyWindow(hWnd2);
11997     DestroyWindow(hWnd3);
11998     SetClipboardViewer(hOrigViewer);
11999 }
12000
12001 static void test_PostMessage(void)
12002 {
12003     static const struct
12004     {
12005         HWND hwnd;
12006         BOOL ret;
12007     } data[] =
12008     {
12009         { HWND_TOP /* 0 */, TRUE },
12010         { HWND_BROADCAST, TRUE },
12011         { HWND_BOTTOM, TRUE },
12012         { HWND_TOPMOST, TRUE },
12013         { HWND_NOTOPMOST, FALSE },
12014         { HWND_MESSAGE, FALSE },
12015         { (HWND)0xdeadbeef, FALSE }
12016     };
12017     int i;
12018     HWND hwnd;
12019     BOOL ret;
12020     MSG msg;
12021     static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12022
12023     SetLastError(0xdeadbeef);
12024     hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12025     if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12026     {
12027         win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12028         return;
12029     }
12030     assert(hwnd);
12031
12032     flush_events();
12033
12034     PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12035     PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12036
12037     for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12038     {
12039         memset(&msg, 0xab, sizeof(msg));
12040         ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12041         ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12042         if (data[i].ret)
12043         {
12044             if (data[i].hwnd)
12045                 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12046                    msg.wParam == 0x5678 && msg.lParam == 0x1234,
12047                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12048                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12049             else
12050                 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12051                    msg.wParam == 0x1234 && msg.lParam == 0x5678,
12052                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12053                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12054         }
12055     }
12056
12057     DestroyWindow(hwnd);
12058     flush_events();
12059 }
12060
12061 static const struct
12062 {
12063     DWORD exp, broken;
12064     BOOL todo;
12065 } wait_idle_expect[] =
12066 {
12067 /* 0 */  { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12068          { WAIT_TIMEOUT, 0,            FALSE },
12069          { WAIT_TIMEOUT, 0,            FALSE },
12070          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12071          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12072 /* 5 */  { WAIT_TIMEOUT, 0,            FALSE },
12073          { WAIT_TIMEOUT, 0,            FALSE },
12074          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12075          { 0,            0,            FALSE },
12076          { 0,            0,            FALSE },
12077 /* 10 */ { 0,            0,            FALSE },
12078          { 0,            0,            FALSE },
12079          { 0,            WAIT_TIMEOUT, FALSE },
12080          { 0,            0,            FALSE },
12081 };
12082
12083 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12084 {
12085     MSG msg;
12086
12087     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12088     Sleep( 200 );
12089     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12090     return 0;
12091 }
12092
12093 static void do_wait_idle_child( int arg )
12094 {
12095     WNDCLASS cls;
12096     MSG msg;
12097     HWND hwnd = 0;
12098     HANDLE thread;
12099     DWORD id;
12100     HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12101     HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12102
12103     memset( &cls, 0, sizeof(cls) );
12104     cls.lpfnWndProc   = DefWindowProc;
12105     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12106     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12107     cls.lpszClassName = "TestClass";
12108     RegisterClass( &cls );
12109
12110     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* create the msg queue */
12111
12112     ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12113     ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12114
12115     switch (arg)
12116     {
12117     case 0:
12118         SetEvent( start_event );
12119         break;
12120     case 1:
12121         SetEvent( start_event );
12122         Sleep( 200 );
12123         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12124         break;
12125     case 2:
12126         SetEvent( start_event );
12127         Sleep( 200 );
12128         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12129         PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12130         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12131         break;
12132     case 3:
12133         SetEvent( start_event );
12134         Sleep( 200 );
12135         SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12136         break;
12137     case 4:
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|PM_NOYIELD )) DispatchMessage( &msg );
12142         break;
12143     case 5:
12144         SetEvent( start_event );
12145         Sleep( 200 );
12146         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12147         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12148         break;
12149     case 6:
12150         SetEvent( start_event );
12151         Sleep( 200 );
12152         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12153         while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12154         {
12155             GetMessage( &msg, 0, 0, 0 );
12156             DispatchMessage( &msg );
12157         }
12158         break;
12159     case 7:
12160         SetEvent( start_event );
12161         Sleep( 200 );
12162         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12163         SetTimer( hwnd, 3, 1, NULL );
12164         Sleep( 200 );
12165         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12166         break;
12167     case 8:
12168         SetEvent( start_event );
12169         Sleep( 200 );
12170         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12171         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12172         break;
12173     case 9:
12174         SetEvent( start_event );
12175         Sleep( 200 );
12176         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12177         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12178         for (;;) GetMessage( &msg, 0, 0, 0 );
12179         break;
12180     case 10:
12181         SetEvent( start_event );
12182         Sleep( 200 );
12183         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12184         SetTimer( hwnd, 3, 1, NULL );
12185         Sleep( 200 );
12186         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12187         break;
12188     case 11:
12189         SetEvent( start_event );
12190         Sleep( 200 );
12191         return;  /* exiting the process makes WaitForInputIdle return success too */
12192     case 12:
12193         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12194         Sleep( 200 );
12195         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12196         SetEvent( start_event );
12197         break;
12198     case 13:
12199         SetEvent( start_event );
12200         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12201         Sleep( 200 );
12202         thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12203         WaitForSingleObject( thread, 10000 );
12204         CloseHandle( thread );
12205         break;
12206     }
12207     WaitForSingleObject( end_event, 2000 );
12208     CloseHandle( start_event );
12209     CloseHandle( end_event );
12210     if (hwnd) DestroyWindow( hwnd );
12211 }
12212
12213 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12214 {
12215     if (msg == WM_WININICHANGE) Sleep( 200 );  /* make sure the child waits */
12216     return DefWindowProcA( hwnd, msg, wp, lp );
12217 }
12218
12219 static DWORD CALLBACK wait_idle_thread( void *arg )
12220 {
12221     WNDCLASS cls;
12222     MSG msg;
12223     HWND hwnd;
12224
12225     memset( &cls, 0, sizeof(cls) );
12226     cls.lpfnWndProc   = wait_idle_proc;
12227     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12228     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12229     cls.lpszClassName = "TestClass";
12230     RegisterClass( &cls );
12231
12232     hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12233     while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12234     return 0;
12235 }
12236
12237 static void test_WaitForInputIdle( char *argv0 )
12238 {
12239     char path[MAX_PATH];
12240     PROCESS_INFORMATION pi;
12241     STARTUPINFOA startup;
12242     BOOL ret;
12243     HANDLE start_event, end_event, thread;
12244     unsigned int i;
12245     DWORD id;
12246     const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12247     const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12248     BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12249
12250     if (console_app)  /* build the test with -mwindows for better coverage */
12251         trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12252
12253     start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12254     end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12255     ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12256     ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12257
12258     memset( &startup, 0, sizeof(startup) );
12259     startup.cb = sizeof(startup);
12260     startup.dwFlags = STARTF_USESHOWWINDOW;
12261     startup.wShowWindow = SW_SHOWNORMAL;
12262
12263     thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12264
12265     for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12266     {
12267         ResetEvent( start_event );
12268         ResetEvent( end_event );
12269         sprintf( path, "%s msg %u", argv0, i );
12270         ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12271         ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12272         if (ret)
12273         {
12274             ret = WaitForSingleObject( start_event, 5000 );
12275             ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12276             if (ret == WAIT_OBJECT_0)
12277             {
12278                 ret = WaitForInputIdle( pi.hProcess, 1000 );
12279                 if (ret == WAIT_FAILED)
12280                     ok( console_app ||
12281                         ret == wait_idle_expect[i].exp ||
12282                         broken(ret == wait_idle_expect[i].broken),
12283                         "%u: WaitForInputIdle error %08x expected %08x\n",
12284                         i, ret, wait_idle_expect[i].exp );
12285                 else if (wait_idle_expect[i].todo)
12286                     todo_wine
12287                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12288                         "%u: WaitForInputIdle error %08x expected %08x\n",
12289                         i, ret, wait_idle_expect[i].exp );
12290                 else
12291                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12292                         "%u: WaitForInputIdle error %08x expected %08x\n",
12293                         i, ret, wait_idle_expect[i].exp );
12294                 SetEvent( end_event );
12295                 WaitForSingleObject( pi.hProcess, 1000 );  /* give it a chance to exit on its own */
12296             }
12297             TerminateProcess( pi.hProcess, 0 );  /* just in case */
12298             winetest_wait_child_process( pi.hProcess );
12299             ret = WaitForInputIdle( pi.hProcess, 100 );
12300             ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12301             CloseHandle( pi.hProcess );
12302             CloseHandle( pi.hThread );
12303         }
12304     }
12305     CloseHandle( start_event );
12306     PostThreadMessage( id, WM_QUIT, 0, 0 );
12307     WaitForSingleObject( thread, 10000 );
12308     CloseHandle( thread );
12309 }
12310
12311 START_TEST(msg)
12312 {
12313     char **test_argv;
12314     BOOL ret;
12315     BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12316
12317     int argc = winetest_get_mainargs( &test_argv );
12318     if (argc >= 3)
12319     {
12320         unsigned int arg;
12321         /* Child process. */
12322         sscanf (test_argv[2], "%d", (unsigned int *) &arg);
12323         do_wait_idle_child( arg );
12324         return;
12325     }
12326
12327     init_procs();
12328
12329     if (!RegisterWindowClasses()) assert(0);
12330
12331     if (pSetWinEventHook)
12332     {
12333         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12334                                        GetModuleHandleA(0), win_event_proc,
12335                                        0, GetCurrentThreadId(),
12336                                        WINEVENT_INCONTEXT);
12337         if (pIsWinEventHookInstalled && hEvent_hook)
12338         {
12339             UINT event;
12340             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12341                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12342         }
12343     }
12344     if (!hEvent_hook) win_skip( "no win event hook support\n" );
12345
12346     cbt_hook_thread_id = GetCurrentThreadId();
12347     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12348     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12349
12350     test_winevents();
12351
12352     /* Fix message sequences before removing 4 lines below */
12353 #if 1
12354     if (pUnhookWinEvent && hEvent_hook)
12355     {
12356         ret = pUnhookWinEvent(hEvent_hook);
12357         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12358         pUnhookWinEvent = 0;
12359     }
12360     hEvent_hook = 0;
12361 #endif
12362
12363     test_PostMessage();
12364     test_ShowWindow();
12365     test_PeekMessage();
12366     test_PeekMessage2();
12367     test_WaitForInputIdle( test_argv[0] );
12368     test_scrollwindowex();
12369     test_messages();
12370     test_setwindowpos();
12371     test_showwindow();
12372     invisible_parent_tests();
12373     test_mdi_messages();
12374     test_button_messages();
12375     test_static_messages();
12376     test_listbox_messages();
12377     test_combobox_messages();
12378     test_wmime_keydown_message();
12379     test_paint_messages();
12380     test_interthread_messages();
12381     test_message_conversion();
12382     test_accelerators();
12383     test_timers();
12384     test_timers_no_wnd();
12385     if (hCBT_hook) test_set_hook();
12386     test_DestroyWindow();
12387     test_DispatchMessage();
12388     test_SendMessageTimeout();
12389     test_edit_messages();
12390     test_quit_message();
12391     test_SetActiveWindow();
12392
12393     if (!pTrackMouseEvent)
12394         win_skip("TrackMouseEvent is not available\n");
12395     else
12396         test_TrackMouseEvent();
12397
12398     test_SetWindowRgn();
12399     test_sys_menu();
12400     test_dialog_messages();
12401     test_nullCallback();
12402     test_dbcs_wm_char();
12403     test_menu_messages();
12404     test_paintingloop();
12405     test_defwinproc();
12406     test_clipboard_viewers();
12407     /* keep it the last test, under Windows it tends to break the tests
12408      * which rely on active/foreground windows being correct.
12409      */
12410     test_SetForegroundWindow();
12411
12412     UnhookWindowsHookEx(hCBT_hook);
12413     if (pUnhookWinEvent && hEvent_hook)
12414     {
12415         ret = pUnhookWinEvent(hEvent_hook);
12416         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12417         SetLastError(0xdeadbeef);
12418         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12419         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12420            GetLastError() == 0xdeadbeef, /* Win9x */
12421            "unexpected error %d\n", GetLastError());
12422     }
12423 }